Passed
Push — master ( 56b1f7...a15c21 )
by Brian
04:38 queued 10s
created
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +451 added lines, -451 removed lines patch added patch discarded remove patch
@@ -12,492 +12,492 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-
163
-			}
164
-
165
-		}
166
-
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
-	}
169
-
170
-	/**
171
-	 * Helper function to send an email.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice
174
-	 * @param GetPaid_Notification_Email $email
175
-	 * @param string $type
176
-	 * @param string|array $recipients
177
-	 * @param array $extra_args Extra template args.
178
-	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
-
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
-
183
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
185
-			return;
186
-		}
187
-
188
-		$mailer     = new GetPaid_Notification_Email_Sender();
189
-		$merge_tags = $email->get_merge_tags();
190
-
191
-		$result = $mailer->send(
192
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
-			$email->get_content( $merge_tags, $extra_args ),
195
-			$email->get_attachments()
196
-		);
197
-
198
-		// Maybe send a copy to the admin.
199
-		if ( $email->include_admin_bcc() ) {
200
-			$mailer->send(
201
-				wpinv_get_admin_email(),
202
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
-				$email->get_content( $merge_tags ),
204
-				$email->get_attachments()
205
-			);
206
-		}
207
-
208
-		if ( $result ) {
209
-			$invoice->add_system_note(
210
-				sprintf(
211
-					__( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
-					sanitize_key( $type ),
213
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
-				)
215
-			);
216
-		} else {
217
-			$invoice->add_system_note(
218
-				sprintf(
219
-					__( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
222
-				)
223
-			);	
224
-		}
225
-
226
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
-
228
-		return $result;
229
-	}
230
-
231
-	/**
232
-	 * Also send emails to any cc users.
233
-	 *
234
-	 * @param array $recipients
235
-	 * @param GetPaid_Notification_Email $email
236
-	 */
237
-	public function filter_email_recipients( $recipients, $email ) {
238
-
239
-		if ( ! $email->is_admin_email() ) {
240
-			$cc   = $email->object->get_email_cc();
241
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
-
243
-			if ( ! empty( $cc ) ) {
244
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
-			}
247
-
248
-			if ( ! empty( $cc_2 ) ) {
249
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
-			}
252
-
253
-		}
254
-
255
-		return $recipients;
256
-
257
-	}
258
-
259
-	/**
260
-	 * Sends a new invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function new_invoice( $invoice ) {
265
-
266
-		// Only send this email for invoices created via the admin page.
267
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
-			return;
269
-		}
270
-
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
-		$recipient = wpinv_get_admin_email();
273
-
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
-
276
-	}
277
-
278
-	/**
279
-	 * Sends a cancelled invoice notification.
280
-	 *
281
-	 * @param WPInv_Invoice $invoice
282
-	 */
283
-	public function cancelled_invoice( $invoice ) {
284
-
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
-		$recipient = wpinv_get_admin_email();
287
-
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
-
290
-	}
291
-
292
-	/**
293
-	 * Sends a failed invoice notification.
294
-	 *
295
-	 * @param WPInv_Invoice $invoice
296
-	 */
297
-	public function failed_invoice( $invoice ) {
298
-
299
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
300
-		$recipient = wpinv_get_admin_email();
301
-
302
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
303
-
304
-	}
305
-
306
-	/**
307
-	 * Sends a notification whenever an invoice is put on hold.
308
-	 *
309
-	 * @param WPInv_Invoice $invoice
310
-	 */
311
-	public function onhold_invoice( $invoice ) {
312
-
313
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
314
-		$recipient = $invoice->get_email();
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar ( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+
163
+            }
164
+
165
+        }
166
+
167
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
+    }
169
+
170
+    /**
171
+     * Helper function to send an email.
172
+     *
173
+     * @param WPInv_Invoice $invoice
174
+     * @param GetPaid_Notification_Email $email
175
+     * @param string $type
176
+     * @param string|array $recipients
177
+     * @param array $extra_args Extra template args.
178
+     */
179
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
+
181
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
+
183
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
185
+            return;
186
+        }
187
+
188
+        $mailer     = new GetPaid_Notification_Email_Sender();
189
+        $merge_tags = $email->get_merge_tags();
190
+
191
+        $result = $mailer->send(
192
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
+            $email->get_content( $merge_tags, $extra_args ),
195
+            $email->get_attachments()
196
+        );
197
+
198
+        // Maybe send a copy to the admin.
199
+        if ( $email->include_admin_bcc() ) {
200
+            $mailer->send(
201
+                wpinv_get_admin_email(),
202
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
+                $email->get_content( $merge_tags ),
204
+                $email->get_attachments()
205
+            );
206
+        }
207
+
208
+        if ( $result ) {
209
+            $invoice->add_system_note(
210
+                sprintf(
211
+                    __( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
+                    sanitize_key( $type ),
213
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
+                )
215
+            );
216
+        } else {
217
+            $invoice->add_system_note(
218
+                sprintf(
219
+                    __( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
+                    sanitize_key( $type ),
221
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
222
+                )
223
+            );	
224
+        }
225
+
226
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
+
228
+        return $result;
229
+    }
230
+
231
+    /**
232
+     * Also send emails to any cc users.
233
+     *
234
+     * @param array $recipients
235
+     * @param GetPaid_Notification_Email $email
236
+     */
237
+    public function filter_email_recipients( $recipients, $email ) {
238
+
239
+        if ( ! $email->is_admin_email() ) {
240
+            $cc   = $email->object->get_email_cc();
241
+            $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
+
243
+            if ( ! empty( $cc ) ) {
244
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
+            }
247
+
248
+            if ( ! empty( $cc_2 ) ) {
249
+                $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
+            }
252
+
253
+        }
254
+
255
+        return $recipients;
256
+
257
+    }
258
+
259
+    /**
260
+     * Sends a new invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function new_invoice( $invoice ) {
265
+
266
+        // Only send this email for invoices created via the admin page.
267
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
+            return;
269
+        }
270
+
271
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
+        $recipient = wpinv_get_admin_email();
273
+
274
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
+
276
+    }
277
+
278
+    /**
279
+     * Sends a cancelled invoice notification.
280
+     *
281
+     * @param WPInv_Invoice $invoice
282
+     */
283
+    public function cancelled_invoice( $invoice ) {
284
+
285
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
+        $recipient = wpinv_get_admin_email();
287
+
288
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
+
290
+    }
291
+
292
+    /**
293
+     * Sends a failed invoice notification.
294
+     *
295
+     * @param WPInv_Invoice $invoice
296
+     */
297
+    public function failed_invoice( $invoice ) {
298
+
299
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
300
+        $recipient = wpinv_get_admin_email();
301
+
302
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
303
+
304
+    }
305
+
306
+    /**
307
+     * Sends a notification whenever an invoice is put on hold.
308
+     *
309
+     * @param WPInv_Invoice $invoice
310
+     */
311
+    public function onhold_invoice( $invoice ) {
312
+
313
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
314
+        $recipient = $invoice->get_email();
315 315
 
316
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
316
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
317 317
 
318
-	}
318
+    }
319 319
 
320
-	/**
321
-	 * Sends a notification whenever an invoice is marked as processing payment.
322
-	 *
323
-	 * @param WPInv_Invoice $invoice
324
-	 */
325
-	public function processing_invoice( $invoice ) {
320
+    /**
321
+     * Sends a notification whenever an invoice is marked as processing payment.
322
+     *
323
+     * @param WPInv_Invoice $invoice
324
+     */
325
+    public function processing_invoice( $invoice ) {
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
-		$recipient = $invoice->get_email();
327
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
+        $recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331
-
332
-	}
333
-
334
-	/**
335
-	 * Sends a notification whenever an invoice is paid.
336
-	 *
337
-	 * @param WPInv_Invoice $invoice
338
-	 */
339
-	public function completed_invoice( $invoice ) {
330
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331
+
332
+    }
333
+
334
+    /**
335
+     * Sends a notification whenever an invoice is paid.
336
+     *
337
+     * @param WPInv_Invoice $invoice
338
+     */
339
+    public function completed_invoice( $invoice ) {
340 340
 
341
-		// (Maybe) abort if it is a renewal invoice.
342
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
343
-			return;
344
-		}
341
+        // (Maybe) abort if it is a renewal invoice.
342
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
343
+            return;
344
+        }
345 345
 
346
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
347
-		$recipient = $invoice->get_email();
346
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
347
+        $recipient = $invoice->get_email();
348 348
 
349
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
349
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
350 350
 
351
-	}
351
+    }
352 352
 
353
-	/**
354
-	 * Sends a notification whenever an invoice is refunded.
355
-	 *
356
-	 * @param WPInv_Invoice $invoice
357
-	 */
358
-	public function refunded_invoice( $invoice ) {
353
+    /**
354
+     * Sends a notification whenever an invoice is refunded.
355
+     *
356
+     * @param WPInv_Invoice $invoice
357
+     */
358
+    public function refunded_invoice( $invoice ) {
359 359
 
360
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
361
-		$recipient = $invoice->get_email();
360
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
361
+        $recipient = $invoice->get_email();
362 362
 
363
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
363
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
364 364
 
365
-	}
365
+    }
366 366
 
367
-	/**
368
-	 * Notifies a user about new invoices
369
-	 *
370
-	 * @param WPInv_Invoice $invoice
371
-	 * @param bool $force
372
-	 */
373
-	public function user_invoice( $invoice, $force = false ) {
367
+    /**
368
+     * Notifies a user about new invoices
369
+     *
370
+     * @param WPInv_Invoice $invoice
371
+     * @param bool $force
372
+     */
373
+    public function user_invoice( $invoice, $force = false ) {
374 374
 
375
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
376
-			return;
377
-		}
378
-
379
-		// Only send this email for invoices created via the admin page.
380
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
381
-			return;
382
-		}
375
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
376
+            return;
377
+        }
378
+
379
+        // Only send this email for invoices created via the admin page.
380
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
381
+            return;
382
+        }
383 383
 
384
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
385
-		$recipient = $invoice->get_email();
384
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
385
+        $recipient = $invoice->get_email();
386 386
 
387
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
387
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
388 388
 
389
-	}
390
-
391
-	/**
392
-	 * Checks if an invoice is a payment form invoice.
393
-	 *
394
-	 * @param int $invoice
395
-	 * @return bool
396
-	 */
397
-	public function is_payment_form_invoice( $invoice ) {
398
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
399
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
-	}
389
+    }
390
+
391
+    /**
392
+     * Checks if an invoice is a payment form invoice.
393
+     *
394
+     * @param int $invoice
395
+     * @return bool
396
+     */
397
+    public function is_payment_form_invoice( $invoice ) {
398
+        $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
399
+        return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
+    }
401 401
 
402
-	/**
403
-	 * Notifies admin about new invoice notes
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 * @param string $note
407
-	 */
408
-	public function user_note( $invoice, $note ) {
409
-
410
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
-		$recipient = $invoice->get_email();
402
+    /**
403
+     * Notifies admin about new invoice notes
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     * @param string $note
407
+     */
408
+    public function user_note( $invoice, $note ) {
409
+
410
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
+        $recipient = $invoice->get_email();
412 412
 
413
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
-
415
-	}
416
-
417
-	/**
418
-	 * (Force) Sends overdue notices.
419
-	 *
420
-	 * @param WPInv_Invoice $invoice
421
-	 */
422
-	public function force_send_overdue_notice( $invoice ) {
423
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
-	}
426
-
427
-	/**
428
-	 * Sends overdue notices.
429
-	 *
430
-	 * @TODO: Create an invoices query class.
431
-	 */
432
-	public function overdue() {
433
-		global $wpdb;
434
-
435
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
436
-
437
-		// Fetch reminder days.
438
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
-
440
-		// Abort if non is set.
441
-		if ( empty( $reminder_days ) ) {
442
-			return;
443
-		}
444
-
445
-		// Retrieve date query.
446
-		$date_query = $this->get_date_query( $reminder_days );
447
-
448
-		// Invoices table.
449
-		$table = $wpdb->prefix . 'getpaid_invoices';
450
-
451
-		// Fetch invoices.
452
-		$invoices  = $wpdb->get_col(
453
-			"SELECT posts.ID FROM $wpdb->posts as posts
413
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
+
415
+    }
416
+
417
+    /**
418
+     * (Force) Sends overdue notices.
419
+     *
420
+     * @param WPInv_Invoice $invoice
421
+     */
422
+    public function force_send_overdue_notice( $invoice ) {
423
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
+    }
426
+
427
+    /**
428
+     * Sends overdue notices.
429
+     *
430
+     * @TODO: Create an invoices query class.
431
+     */
432
+    public function overdue() {
433
+        global $wpdb;
434
+
435
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
436
+
437
+        // Fetch reminder days.
438
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
+
440
+        // Abort if non is set.
441
+        if ( empty( $reminder_days ) ) {
442
+            return;
443
+        }
444
+
445
+        // Retrieve date query.
446
+        $date_query = $this->get_date_query( $reminder_days );
447
+
448
+        // Invoices table.
449
+        $table = $wpdb->prefix . 'getpaid_invoices';
450
+
451
+        // Fetch invoices.
452
+        $invoices  = $wpdb->get_col(
453
+            "SELECT posts.ID FROM $wpdb->posts as posts
454 454
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
455 455
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
456 456
 
457
-		foreach ( $invoices as $invoice ) {
457
+        foreach ( $invoices as $invoice ) {
458 458
 
459
-			// Only send this email for invoices created via the admin page.
460
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
461
-				$invoice       = new WPInv_Invoice( $invoice );
462
-				$email->object = $invoice;
459
+            // Only send this email for invoices created via the admin page.
460
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
461
+                $invoice       = new WPInv_Invoice( $invoice );
462
+                $email->object = $invoice;
463 463
 
464
-				if ( $invoice->needs_payment() ) {
465
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
466
-				}
464
+                if ( $invoice->needs_payment() ) {
465
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
466
+                }
467 467
 
468
-			}
468
+            }
469 469
 
470
-		}
470
+        }
471 471
 
472
-	}
472
+    }
473 473
 
474
-	/**
475
-	 * Calculates the date query for an invoices query
476
-	 *
477
-	 * @param array $reminder_days
478
-	 * @return string
479
-	 */
480
-	public function get_date_query( $reminder_days ) {
474
+    /**
475
+     * Calculates the date query for an invoices query
476
+     *
477
+     * @param array $reminder_days
478
+     * @return string
479
+     */
480
+    public function get_date_query( $reminder_days ) {
481 481
 
482
-		$date_query = array(
483
-			'relation'  => 'OR'
484
-		);
482
+        $date_query = array(
483
+            'relation'  => 'OR'
484
+        );
485 485
 
486
-		foreach ( $reminder_days as $days ) {
487
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
486
+        foreach ( $reminder_days as $days ) {
487
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
488 488
 
489
-			$date_query[] = array(
490
-				'year'  => $date['year'],
491
-				'month' => $date['month'],
492
-				'day'   => $date['day'],
493
-			);
489
+            $date_query[] = array(
490
+                'year'  => $date['year'],
491
+                'month' => $date['month'],
492
+                'day'   => $date['day'],
493
+            );
494 494
 
495
-		}
495
+        }
496 496
 
497
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
498 498
 
499
-		return $date_query->get_sql();
499
+        return $date_query->get_sql();
500 500
 
501
-	}
501
+    }
502 502
 
503 503
 }
Please login to merge, or discard this patch.
templates/payment-forms/cart-item.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -24,64 +24,64 @@  discard block
 block discarded – undo
24 24
 
25 25
 				<?php
26 26
 
27
-					// Fires before printing a line item column.
28
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
27
+                    // Fires before printing a line item column.
28
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
29 29
 
30
-					// Item name.
31
-					if ( 'name' == $key ) {
30
+                    // Item name.
31
+                    if ( 'name' == $key ) {
32 32
 
33
-						// Display the name.
34
-						echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>';
33
+                        // Display the name.
34
+                        echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>';
35 35
 
36
-						// And an optional description.
36
+                        // And an optional description.
37 37
                         $description = $item->get_description();
38 38
 
39 39
                         if ( ! empty( $description ) ) {
40 40
                             $description = wp_kses_post( $description );
41 41
                             echo "<small class='form-text text-muted pr-2 m-0'>$description</small>";
42
-						}
42
+                        }
43 43
 
44
-						// Price help text.
44
+                        // Price help text.
45 45
                         $description = getpaid_item_recurring_price_help_text( $item, $currency );
46 46
                         if ( $description ) {
47 47
                             echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>";
48
-						}
48
+                        }
49 49
 
50
-					}
50
+                    }
51 51
 
52
-					// Item price.
53
-					if ( 'price' == $key ) {
52
+                    // Item price.
53
+                    if ( 'price' == $key ) {
54 54
 
55
-						// Set the currency position.
56
-						$position = wpinv_currency_position();
55
+                        // Set the currency position.
56
+                        $position = wpinv_currency_position();
57 57
 
58
-						if ( $position == 'left_space' ) {
59
-							$position = 'left';
60
-						}
58
+                        if ( $position == 'left_space' ) {
59
+                            $position = 'left';
60
+                        }
61 61
 
62
-						if ( $position == 'right_space' ) {
63
-							$position = 'right';
64
-						}
62
+                        if ( $position == 'right_space' ) {
63
+                            $position = 'right';
64
+                        }
65 65
 
66
-						if ( $item->user_can_set_their_price() ) {
67
-							$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
68
-							$minimum          = (float) $item->get_minimum_price();
69
-							$validate_minimum = '';
70
-							$class            = '';
71
-							$data_minimum     = '';
66
+                        if ( $item->user_can_set_their_price() ) {
67
+                            $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
68
+                            $minimum          = (float) $item->get_minimum_price();
69
+                            $validate_minimum = '';
70
+                            $class            = '';
71
+                            $data_minimum     = '';
72 72
 
73
-							if ( $minimum > 0 ) {
74
-								$validate_minimum = sprintf(
75
-									esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
76
-									sanitize_text_field( wpinv_price( $minimum, $currency ) )
77
-								);
73
+                            if ( $minimum > 0 ) {
74
+                                $validate_minimum = sprintf(
75
+                                    esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
76
+                                    sanitize_text_field( wpinv_price( $minimum, $currency ) )
77
+                                );
78 78
 
79
-								$class = 'getpaid-validate-minimum-amount';
79
+                                $class = 'getpaid-validate-minimum-amount';
80 80
 
81
-								$data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
82
-							}
81
+                                $data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
82
+                            }
83 83
 
84
-							?>
84
+                            ?>
85 85
 								<div class="input-group input-group-sm">
86 86
 									<?php if( 'left' == $position ) : ?>
87 87
 										<div class="input-group-prepend">
@@ -105,37 +105,37 @@  discard block
 block discarded – undo
105 105
 								</div>
106 106
 
107 107
 							<?php
108
-						} else {
109
-							echo wpinv_price( $item->get_price(), $currency );
110
-							?>
108
+                        } else {
109
+                            echo wpinv_price( $item->get_price(), $currency );
110
+                            ?>
111 111
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'>
112 112
 							<?php
113
-						}
114
-					}
113
+                        }
114
+                    }
115 115
 
116
-					// Item quantity.
117
-					if ( 'quantity' == $key ) {
116
+                    // Item quantity.
117
+                    if ( 'quantity' == $key ) {
118 118
 
119
-						if ( $item->allows_quantities() ) {
120
-							?>
119
+                        if ( $item->allows_quantities() ) {
120
+                            ?>
121 121
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required>
122 122
 							<?php
123
-						} else {
124
-							echo (float) $item->get_quantity();
125
-							echo '&nbsp;&nbsp;&nbsp;';
126
-							?>
123
+                        } else {
124
+                            echo (float) $item->get_quantity();
125
+                            echo '&nbsp;&nbsp;&nbsp;';
126
+                            ?>
127 127
 								<input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'>
128 128
 							<?php
129
-						}
130
-					}
129
+                        }
130
+                    }
131 131
 
132
-					// Item sub total.
133
-					if ( 'subtotal' == $key ) {
134
-						echo wpinv_price( $item->get_sub_total(), $currency );
135
-					}
132
+                    // Item sub total.
133
+                    if ( 'subtotal' == $key ) {
134
+                        echo wpinv_price( $item->get_sub_total(), $currency );
135
+                    }
136 136
 
137
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
138
-				?>
137
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
138
+                ?>
139 139
 
140 140
 			</div>
141 141
 
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +529 added lines, -529 removed lines patch added patch discarded remove patch
@@ -14,592 +14,592 @@
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * @var array An array of payment gateways.
40
-	 */
41
-	public $gateways;
42
-
43
-	/**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
47
-		$this->define_constants();
48
-		$this->includes();
49
-		$this->init_hooks();
50
-		$this->set_properties();
51
-	}
52
-
53
-	/**
54
-	 * Sets a custom data property.
55
-	 * 
56
-	 * @param string $prop The prop to set.
57
-	 * @param mixed $value The value to retrieve.
58
-	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
61
-	}
62
-
63
-	/**
64
-	 * Gets a custom data property.
65
-	 *
66
-	 * @param string $prop The prop to set.
67
-	 * @return mixed The value.
68
-	 */
69
-	public function get( $prop ) {
70
-
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
73
-		}
74
-
75
-		return null;
76
-	}
77
-
78
-	/**
79
-	 * Define class properties.
80
-	 */
81
-	public function set_properties() {
82
-
83
-		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
-
88
-		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
-
102
-	}
103
-
104
-	 /**
105
-	 * Define plugin constants.
106
-	 */
107
-	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
-		$this->version = WPINV_VERSION;
111
-	}
112
-
113
-	/**
114
-	 * Hook into actions and filters.
115
-	 *
116
-	 * @since 1.0.19
117
-	 */
118
-	protected function init_hooks() {
119
-		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
-
122
-		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @var array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     * 
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'session', new WPInv_Session_Handler() );
90
+        $this->set( 'notes', new WPInv_Notes() );
91
+        $this->set( 'api', new WPInv_API() );
92
+        $this->set( 'post_types', new GetPaid_Post_Types() );
93
+        $this->set( 'template', new GetPaid_Template() );
94
+        $this->set( 'admin', new GetPaid_Admin() );
95
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
96
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
+
102
+    }
103
+
104
+        /**
105
+         * Define plugin constants.
106
+         */
107
+    public function define_constants() {
108
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
+        $this->version = WPINV_VERSION;
111
+    }
112
+
113
+    /**
114
+     * Hook into actions and filters.
115
+     *
116
+     * @since 1.0.19
117
+     */
118
+    protected function init_hooks() {
119
+        /* Internationalize the text strings used. */
120
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
+
122
+        // Init the plugin after WordPress inits.
123
+        add_action( 'init', array( $this, 'init' ), 1 );
124
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
126
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
130
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135 135
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load the translation of the plugin.
158
-	 *
159
-	 * @since 1.0
160
-	 */
161
-	public function load_textdomain( $locale = NULL ) {
162
-		if ( empty( $locale ) ) {
163
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
164
-		}
165
-
166
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
167
-
168
-		unload_textdomain( 'invoicing' );
169
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
171
-
172
-		/**
173
-		 * Define language constants.
174
-		 */
175
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
176
-	}
177
-
178
-	/**
179
-	 * Include required core files used in admin and on the frontend.
180
-	 */
181
-	public function includes() {
182
-
183
-		// Start with the settings.
184
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
185
-
186
-		// Packages/libraries.
187
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
189
-
190
-		// Load functions.
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
206
-
207
-		// Register autoloader.
208
-		try {
209
-			spl_autoload_register( array( $this, 'autoload' ), true );
210
-		} catch ( Exception $e ) {
211
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
-		}
213
-
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
235
-
236
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
-			GetPaid_Post_Types_Admin::init();
238
-
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
241
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
242
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
245
-			// load the user class only on the users.php page
246
-			global $pagenow;
247
-			if($pagenow=='users.php'){
248
-				new WPInv_Admin_Users();
249
-			}
250
-		}
251
-
252
-		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
-		}
257
-
258
-	}
259
-
260
-	/**
261
-	 * Class autoloader
262
-	 *
263
-	 * @param       string $class_name The name of the class to load.
264
-	 * @access      public
265
-	 * @since       1.0.19
266
-	 * @return      void
267
-	 */
268
-	public function autoload( $class_name ) {
269
-
270
-		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
272
-
273
-		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
-			return;
276
-		}
277
-
278
-		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
-
281
-		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
-
284
-		// And an array of possible locations in order of importance.
285
-		$locations = array(
286
-			"$plugin_path/includes",
287
-			"$plugin_path/includes/data-stores",
288
-			"$plugin_path/includes/gateways",
289
-			"$plugin_path/includes/payments",
290
-			"$plugin_path/includes/geolocation",
291
-			"$plugin_path/includes/reports",
292
-			"$plugin_path/includes/api",
293
-			"$plugin_path/includes/admin",
294
-			"$plugin_path/includes/admin/meta-boxes",
295
-		);
296
-
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
-
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
301
-				break;
302
-			}
303
-
304
-		}
305
-
306
-	}
307
-
308
-	/**
309
-	 * Inits hooks etc.
310
-	 */
311
-	public function init() {
312
-
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
-	/**
346
-	 * Checks if this is an IPN request and processes it.
347
-	 */
348
-	public function maybe_process_ipn() {
349
-
350
-		// Ensure that this is an IPN request.
351
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
352
-			return;
353
-		}
354
-
355
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
356
-
357
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
358
-		do_action( "wpinv_verify_{$gateway}_ipn" );
359
-		exit;
360
-
361
-	}
362
-
363
-	public function enqueue_scripts() {
364
-
365
-		// Fires before adding scripts.
366
-		do_action( 'getpaid_enqueue_scripts' );
367
-
368
-		$localize                         = array();
369
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
-		$localize['thousands']            = wpinv_thousands_separator();
371
-		$localize['decimals']             = wpinv_decimal_separator();
372
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
373
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
374
-		$localize['UseTaxes']             = wpinv_use_taxes();
375
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
376
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
377
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
378
-
379
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
-
381
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
382
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
383
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
384
-	}
385
-
386
-	public function wpinv_actions() {
387
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
388
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
389
-		}
390
-	}
391
-
392
-	/**
136
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load the translation of the plugin.
158
+     *
159
+     * @since 1.0
160
+     */
161
+    public function load_textdomain( $locale = NULL ) {
162
+        if ( empty( $locale ) ) {
163
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
164
+        }
165
+
166
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
167
+
168
+        unload_textdomain( 'invoicing' );
169
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
171
+
172
+        /**
173
+         * Define language constants.
174
+         */
175
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
176
+    }
177
+
178
+    /**
179
+     * Include required core files used in admin and on the frontend.
180
+     */
181
+    public function includes() {
182
+
183
+        // Start with the settings.
184
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
185
+
186
+        // Packages/libraries.
187
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
189
+
190
+        // Load functions.
191
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
206
+
207
+        // Register autoloader.
208
+        try {
209
+            spl_autoload_register( array( $this, 'autoload' ), true );
210
+        } catch ( Exception $e ) {
211
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
+        }
213
+
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
235
+
236
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
+            GetPaid_Post_Types_Admin::init();
238
+
239
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
240
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
241
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
242
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
245
+            // load the user class only on the users.php page
246
+            global $pagenow;
247
+            if($pagenow=='users.php'){
248
+                new WPInv_Admin_Users();
249
+            }
250
+        }
251
+
252
+        // Register cli commands
253
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
+        }
257
+
258
+    }
259
+
260
+    /**
261
+     * Class autoloader
262
+     *
263
+     * @param       string $class_name The name of the class to load.
264
+     * @access      public
265
+     * @since       1.0.19
266
+     * @return      void
267
+     */
268
+    public function autoload( $class_name ) {
269
+
270
+        // Normalize the class name...
271
+        $class_name  = strtolower( $class_name );
272
+
273
+        // ... and make sure it is our class.
274
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
+            return;
276
+        }
277
+
278
+        // Next, prepare the file name from the class.
279
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
+
281
+        // Base path of the classes.
282
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
+
284
+        // And an array of possible locations in order of importance.
285
+        $locations = array(
286
+            "$plugin_path/includes",
287
+            "$plugin_path/includes/data-stores",
288
+            "$plugin_path/includes/gateways",
289
+            "$plugin_path/includes/payments",
290
+            "$plugin_path/includes/geolocation",
291
+            "$plugin_path/includes/reports",
292
+            "$plugin_path/includes/api",
293
+            "$plugin_path/includes/admin",
294
+            "$plugin_path/includes/admin/meta-boxes",
295
+        );
296
+
297
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
+
299
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
+                include trailingslashit( $location ) . $file_name;
301
+                break;
302
+            }
303
+
304
+        }
305
+
306
+    }
307
+
308
+    /**
309
+     * Inits hooks etc.
310
+     */
311
+    public function init() {
312
+
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
+    /**
346
+     * Checks if this is an IPN request and processes it.
347
+     */
348
+    public function maybe_process_ipn() {
349
+
350
+        // Ensure that this is an IPN request.
351
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
352
+            return;
353
+        }
354
+
355
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
356
+
357
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
358
+        do_action( "wpinv_verify_{$gateway}_ipn" );
359
+        exit;
360
+
361
+    }
362
+
363
+    public function enqueue_scripts() {
364
+
365
+        // Fires before adding scripts.
366
+        do_action( 'getpaid_enqueue_scripts' );
367
+
368
+        $localize                         = array();
369
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
+        $localize['thousands']            = wpinv_thousands_separator();
371
+        $localize['decimals']             = wpinv_decimal_separator();
372
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
373
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
374
+        $localize['UseTaxes']             = wpinv_use_taxes();
375
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
376
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
377
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
378
+
379
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
+
381
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
382
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
383
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
384
+    }
385
+
386
+    public function wpinv_actions() {
387
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
388
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
389
+        }
390
+    }
391
+
392
+    /**
393 393
      * Fires an action after verifying that a user can fire them.
394
-	 *
395
-	 * Note: If the action is on an invoice, subscription etc, esure that the
396
-	 * current user owns the invoice/subscription.
394
+     *
395
+     * Note: If the action is on an invoice, subscription etc, esure that the
396
+     * current user owns the invoice/subscription.
397 397
      */
398 398
     public function maybe_do_authenticated_action() {
399 399
 
400
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
400
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
401
+
402
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
403
+            $data = wp_unslash( $_REQUEST );
404
+            if ( is_user_logged_in() ) {
405
+                do_action( "getpaid_authenticated_action_$key", $data );
406
+            }
407
+
408
+            do_action( "getpaid_unauthenticated_action_$key", $data );
409
+
410
+        }
401 411
 
402
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
403
-			$data = wp_unslash( $_REQUEST );
404
-			if ( is_user_logged_in() ) {
405
-				do_action( "getpaid_authenticated_action_$key", $data );
406
-			}
412
+    }
407 413
 
408
-			do_action( "getpaid_unauthenticated_action_$key", $data );
414
+    public function pre_get_posts( $wp_query ) {
409 415
 
410
-		}
416
+        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() ) {
417
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
418
+        }
411 419
 
420
+        return $wp_query;
412 421
     }
413 422
 
414
-	public function pre_get_posts( $wp_query ) {
415
-
416
-		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() ) {
417
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
418
-		}
419
-
420
-		return $wp_query;
421
-	}
422
-
423
-	/**
424
-	 * Register widgets
425
-	 *
426
-	 */
427
-	public function register_widgets() {
428
-
429
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
430
-		// So we disable our widgets when editing a page with UX Builder.
431
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
432
-			return;
433
-		}
434
-
435
-		$widgets = apply_filters(
436
-			'getpaid_widget_classes',
437
-			array(
438
-				'WPInv_Checkout_Widget',
439
-				'WPInv_History_Widget',
440
-				'WPInv_Receipt_Widget',
441
-				'WPInv_Subscriptions_Widget',
442
-				'WPInv_Buy_Item_Widget',
443
-				'WPInv_Messages_Widget',
444
-				'WPInv_GetPaid_Widget'
445
-			)
446
-		);
447
-
448
-		foreach ( $widgets as $widget ) {
449
-			register_widget( $widget );
450
-		}
423
+    /**
424
+     * Register widgets
425
+     *
426
+     */
427
+    public function register_widgets() {
428
+
429
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
430
+        // So we disable our widgets when editing a page with UX Builder.
431
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
432
+            return;
433
+        }
434
+
435
+        $widgets = apply_filters(
436
+            'getpaid_widget_classes',
437
+            array(
438
+                'WPInv_Checkout_Widget',
439
+                'WPInv_History_Widget',
440
+                'WPInv_Receipt_Widget',
441
+                'WPInv_Subscriptions_Widget',
442
+                'WPInv_Buy_Item_Widget',
443
+                'WPInv_Messages_Widget',
444
+                'WPInv_GetPaid_Widget'
445
+            )
446
+        );
447
+
448
+        foreach ( $widgets as $widget ) {
449
+            register_widget( $widget );
450
+        }
451 451
 		
452
-	}
452
+    }
453 453
 
454
-	/**
455
-	 * Upgrades the database.
456
-	 *
457
-	 * @since 2.0.2
458
-	 */
459
-	public function maybe_upgrade_database() {
454
+    /**
455
+     * Upgrades the database.
456
+     *
457
+     * @since 2.0.2
458
+     */
459
+    public function maybe_upgrade_database() {
460 460
 
461
-		$wpi_version = get_option( 'wpinv_version', 0 );
461
+        $wpi_version = get_option( 'wpinv_version', 0 );
462 462
 
463
-		if ( $wpi_version == WPINV_VERSION ) {
464
-			return;
465
-		}
463
+        if ( $wpi_version == WPINV_VERSION ) {
464
+            return;
465
+        }
466 466
 
467
-		$installer = new GetPaid_Installer();
467
+        $installer = new GetPaid_Installer();
468 468
 
469
-		if ( empty( $wpi_version ) ) {
470
-			return $installer->upgrade_db( 0 );
471
-		}
469
+        if ( empty( $wpi_version ) ) {
470
+            return $installer->upgrade_db( 0 );
471
+        }
472 472
 
473
-		$upgrades  = array(
474
-			'0.0.5' => '004',
475
-			'1.0.3' => '102',
476
-			'2.0.0' => '118',
477
-			'2.0.8' => '207',
478
-		);
473
+        $upgrades  = array(
474
+            '0.0.5' => '004',
475
+            '1.0.3' => '102',
476
+            '2.0.0' => '118',
477
+            '2.0.8' => '207',
478
+        );
479 479
 
480
-		foreach ( $upgrades as $key => $method ) {
480
+        foreach ( $upgrades as $key => $method ) {
481 481
 
482
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
483
-				return $installer->upgrade_db( $method );
484
-			}
482
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
483
+                return $installer->upgrade_db( $method );
484
+            }
485 485
 
486
-		}
486
+        }
487 487
 
488
-	}
488
+    }
489 489
 
490
-	/**
491
-	 * Flushes the permalinks if needed.
492
-	 *
493
-	 * @since 2.0.8
494
-	 */
495
-	public function maybe_flush_permalinks() {
490
+    /**
491
+     * Flushes the permalinks if needed.
492
+     *
493
+     * @since 2.0.8
494
+     */
495
+    public function maybe_flush_permalinks() {
496 496
 
497
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
497
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
498 498
 
499
-		if ( ! empty( $flush ) ) {
500
-			flush_rewrite_rules();
501
-			delete_option( 'wpinv_flush_permalinks' );
502
-		}
499
+        if ( ! empty( $flush ) ) {
500
+            flush_rewrite_rules();
501
+            delete_option( 'wpinv_flush_permalinks' );
502
+        }
503 503
 
504
-	}
504
+    }
505 505
 
506
-	/**
507
-	 * Remove our pages from yoast sitemaps.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param int[] $excluded_posts_ids
511
-	 */
512
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
506
+    /**
507
+     * Remove our pages from yoast sitemaps.
508
+     *
509
+     * @since 1.0.19
510
+     * @param int[] $excluded_posts_ids
511
+     */
512
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
513 513
 
514
-		// Ensure that we have an array.
515
-		if ( ! is_array( $excluded_posts_ids ) ) {
516
-			$excluded_posts_ids = array();
517
-		}
514
+        // Ensure that we have an array.
515
+        if ( ! is_array( $excluded_posts_ids ) ) {
516
+            $excluded_posts_ids = array();
517
+        }
518 518
 
519
-		// Prepare our pages.
520
-		$our_pages = array();
519
+        // Prepare our pages.
520
+        $our_pages = array();
521 521
 
522
-		// Checkout page.
523
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
522
+        // Checkout page.
523
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
524 524
 
525
-		// Success page.
526
-		$our_pages[] = wpinv_get_option( 'success_page', false );
525
+        // Success page.
526
+        $our_pages[] = wpinv_get_option( 'success_page', false );
527 527
 
528
-		// Failure page.
529
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
528
+        // Failure page.
529
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
530 530
 
531
-		// History page.
532
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
531
+        // History page.
532
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
533 533
 
534
-		// Subscriptions page.
535
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
534
+        // Subscriptions page.
535
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
536 536
 
537
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
537
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
538 538
 
539
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
540
-		return array_unique( $excluded_posts_ids );
539
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
540
+        return array_unique( $excluded_posts_ids );
541 541
 
542
-	}
542
+    }
543 543
 
544
-	/**
545
-	 * Displays additional footer code.
546
-	 * 
547
-	 * @since 2.0.0
548
-	 */
549
-	public function wp_footer() {
550
-		wpinv_get_template( 'frontend-footer.php' );
551
-	}
544
+    /**
545
+     * Displays additional footer code.
546
+     * 
547
+     * @since 2.0.0
548
+     */
549
+    public function wp_footer() {
550
+        wpinv_get_template( 'frontend-footer.php' );
551
+    }
552 552
 
553
-	/**
554
-	 * Displays additional header code.
555
-	 * 
556
-	 * @since 2.0.0
557
-	 */
558
-	public function wp_head() {
559
-		wpinv_get_template( 'frontend-head.php' );
560
-	}
553
+    /**
554
+     * Displays additional header code.
555
+     * 
556
+     * @since 2.0.0
557
+     */
558
+    public function wp_head() {
559
+        wpinv_get_template( 'frontend-head.php' );
560
+    }
561 561
 
562
-	/**
563
-	 * Custom query vars.
564
-	 *
565
-	 */
566
-	public function custom_query_vars( $vars ) {
562
+    /**
563
+     * Custom query vars.
564
+     *
565
+     */
566
+    public function custom_query_vars( $vars ) {
567 567
         $vars[] = 'getpaid-ipn';
568 568
         return $vars;
569
-	}
569
+    }
570 570
 
571
-	/**
572
-	 * Add rewrite tags and rules.
573
-	 *
574
-	 */
575
-	public function add_rewrite_rule() {
571
+    /**
572
+     * Add rewrite tags and rules.
573
+     *
574
+     */
575
+    public function add_rewrite_rule() {
576 576
         $tag = 'getpaid-ipn';
577 577
         add_rewrite_tag( "%$tag%", '([^&]+)' );
578 578
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' );
579
-	}
579
+    }
580 580
 
581
-	/**
582
-	 * Processes non-query string ipns.
583
-	 *
584
-	 */
585
-	public function maybe_process_new_ipn( $query ) {
581
+    /**
582
+     * Processes non-query string ipns.
583
+     *
584
+     */
585
+    public function maybe_process_new_ipn( $query ) {
586 586
 
587 587
         if ( is_admin() || ! $query->is_main_query() ) {
588 588
             return;
589 589
         }
590 590
 
591
-		$gateway = get_query_var( 'getpaid-ipn' );
591
+        $gateway = get_query_var( 'getpaid-ipn' );
592 592
 
593 593
         if ( ! empty( $gateway ) ){
594 594
 
595
-			$gateway = sanitize_text_field( $gateway );
596
-			nocache_headers();
597
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
598
-			do_action( "wpinv_verify_{$gateway}_ipn" );
599
-			exit;
595
+            $gateway = sanitize_text_field( $gateway );
596
+            nocache_headers();
597
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
598
+            do_action( "wpinv_verify_{$gateway}_ipn" );
599
+            exit;
600 600
 
601 601
         }
602 602
 
603
-	}
603
+    }
604 604
 
605 605
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-item-details.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Item_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the item.
@@ -270,35 +270,35 @@  discard block
 block discarded – undo
270 270
     }
271 271
 
272 272
     /**
273
-	 * Save meta box data.
274
-	 *
275
-	 * @param int $post_id
276
-	 */
277
-	public static function save( $post_id ) {
273
+     * Save meta box data.
274
+     *
275
+     * @param int $post_id
276
+     */
277
+    public static function save( $post_id ) {
278 278
 
279 279
         // Prepare the item.
280 280
         $item = new WPInv_Item( $post_id );
281 281
 
282 282
         // Load new data.
283 283
         $item->set_props(
284
-			array(
285
-				'price'                => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
-				'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
-				'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
-				'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
-				'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
284
+            array(
285
+                'price'                => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
+                'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
+                'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
+                'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
+                'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
290 290
                 'minimum_price'        => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null,
291
-				'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
292
-				'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
-				'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
-				'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
-				'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
-				'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
-				'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
298
-			)
291
+                'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
292
+                'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
+                'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
+                'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
+                'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
+                'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
+                'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
298
+            )
299 299
         );
300 300
 
301
-		$item->save();
302
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
303
-	}
301
+        $item->save();
302
+        do_action( 'getpaid_item_metabox_save', $post_id, $item );
303
+    }
304 304
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -12,80 +12,80 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+
31
+        // Prepare the selected items.
32
+        $selected_items = array();
33
+        if ( ! empty( $data['getpaid-items'] ) ) {
34
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
35
+        }
36
+
37
+        // For default forms, ensure that an item has been set.
38
+        if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) {
39
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
40
+            $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) );
41
+        }
42
+
43
+        // Process each individual item.
44
+        foreach ( $payment_form->get_items() as $item ) {
45
+            $this->process_item( $item, $selected_items, $submission );
46
+        }
47
+
48
+    }
20 49
 
21 50
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-
31
-		// Prepare the selected items.
32
-		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
-		}
36
-
37
-		// For default forms, ensure that an item has been set.
38
-		if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) {
39
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
40
-			$payment_form->set_items( getpaid_convert_items_to_array( $form_items ) );
41
-		}
42
-
43
-		// Process each individual item.
44
-		foreach ( $payment_form->get_items() as $item ) {
45
-			$this->process_item( $item, $selected_items, $submission );
46
-		}
47
-
48
-	}
49
-
50
-	/**
51
-	 * Process a single item.
52
-	 *
53
-	 * @param GetPaid_Form_Item $item
54
-	 * @param array $selected_items
55
-	 * @param GetPaid_Payment_Form_Submission $submission
56
-	 */
57
-	public function process_item( $item, $selected_items, $submission ) {
58
-
59
-		// Abort if this is an optional item and it has not been selected.
60
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
61
-			return;
62
-		}
63
-
64
-		// (maybe) let customers change the quantities and prices.
65
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
66
-
67
-			// Maybe change the quantities.
68
-			if ( $item->allows_quantities() ) {
69
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
70
-			}
71
-
72
-			// Maybe change the price.
73
-			if ( $item->user_can_set_their_price() ) {
74
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
75
-
76
-				if ( $item->get_minimum_price() > $price ) {
77
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
78
-				}
79
-
80
-				$item->set_price( $price );
81
-
82
-			}
83
-
84
-		}
85
-
86
-		// Save the item.
87
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
88
-
89
-	}
51
+     * Process a single item.
52
+     *
53
+     * @param GetPaid_Form_Item $item
54
+     * @param array $selected_items
55
+     * @param GetPaid_Payment_Form_Submission $submission
56
+     */
57
+    public function process_item( $item, $selected_items, $submission ) {
58
+
59
+        // Abort if this is an optional item and it has not been selected.
60
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
61
+            return;
62
+        }
63
+
64
+        // (maybe) let customers change the quantities and prices.
65
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
66
+
67
+            // Maybe change the quantities.
68
+            if ( $item->allows_quantities() ) {
69
+                $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
70
+            }
71
+
72
+            // Maybe change the price.
73
+            if ( $item->user_can_set_their_price() ) {
74
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
75
+
76
+                if ( $item->get_minimum_price() > $price ) {
77
+                    throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
78
+                }
79
+
80
+                $item->set_price( $price );
81
+
82
+            }
83
+
84
+        }
85
+
86
+        // Save the item.
87
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
88
+
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-fees.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -12,114 +12,114 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Fees {
14 14
 
15
-	/**
16
-	 * The fee validation error.
17
-	 * @var string
18
-	 */
19
-	public $fee_error;
20
-
21
-	/**
22
-	 * Submission fees.
23
-	 * @var array
24
-	 */
25
-	public $fees = array();
15
+    /**
16
+     * The fee validation error.
17
+     * @var string
18
+     */
19
+    public $fee_error;
20
+
21
+    /**
22
+     * Submission fees.
23
+     * @var array
24
+     */
25
+    public $fees = array();
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Process any existing invoice fees.
35
+        if ( $submission->has_invoice() ) {
36
+            $this->fees = $submission->get_invoice()->get_fees();
37
+        }
38
+
39
+        // Process price fields.
40
+        $data         = $submission->get_data();
41
+        $payment_form = $submission->get_payment_form();
42
+
43
+        foreach ( $payment_form->get_elements() as $element ) {
44
+
45
+            if ( 'price_input' == $element['type'] ) {
46
+                $this->process_price_input( $element, $data, $submission );
47
+            }
48
+
49
+            if ( 'price_select' == $element['type'] ) {
50
+                $this->process_price_select( $element, $data );
51
+            }
52
+
53
+        }
54
+
55
+    }
56
+
57
+    /**
58
+     * Process a price input field.
59
+     *
60
+     * @param array $element
61
+     * @param array $data
62
+     * @param GetPaid_Payment_Form_Submission $submission
63
+     */
64
+    public function process_price_input( $element, $data, $submission ) {
65
+
66
+        // Abort if not passed.
67
+        if ( empty( $data[ $element['id'] ] ) ) {
68
+            return;
69
+        }
70
+
71
+        $amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
72
+        $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] );
73
+
74
+        if ( $amount < $minimum ) {
75
+            throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) );
76
+        }
77
+
78
+        $this->fees[ $element['label'] ] = array(
79
+            'name'          => $element['label'],
80
+            'initial_fee'   => $amount,
81
+            'recurring_fee' => 0,
82
+        );
83
+
84
+    }
26 85
 
27 86
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Process any existing invoice fees.
35
-		if ( $submission->has_invoice() ) {
36
-			$this->fees = $submission->get_invoice()->get_fees();
37
-		}
38
-
39
-		// Process price fields.
40
-		$data         = $submission->get_data();
41
-		$payment_form = $submission->get_payment_form();
42
-
43
-		foreach ( $payment_form->get_elements() as $element ) {
44
-
45
-			if ( 'price_input' == $element['type'] ) {
46
-				$this->process_price_input( $element, $data, $submission );
47
-			}
48
-
49
-			if ( 'price_select' == $element['type'] ) {
50
-				$this->process_price_select( $element, $data );
51
-			}
52
-
53
-		}
54
-
55
-	}
56
-
57
-	/**
58
-	 * Process a price input field.
59
-	 *
60
-	 * @param array $element
61
-	 * @param array $data
62
-	 * @param GetPaid_Payment_Form_Submission $submission
63
-	 */
64
-	public function process_price_input( $element, $data, $submission ) {
65
-
66
-		// Abort if not passed.
67
-		if ( empty( $data[ $element['id'] ] ) ) {
68
-			return;
69
-		}
70
-
71
-		$amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
72
-		$minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] );
73
-
74
-		if ( $amount < $minimum ) {
75
-			throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) );
76
-		}
77
-
78
-		$this->fees[ $element['label'] ] = array(
79
-			'name'          => $element['label'],
80
-			'initial_fee'   => $amount,
81
-			'recurring_fee' => 0,
82
-		);
83
-
84
-	}
85
-
86
-	/**
87
-	 * Process a price select field.
88
-	 *
89
-	 * @param array $element
90
-	 * @param array $data
91
-	 */
92
-	public function process_price_select( $element, $data ) {
93
-
94
-		// Abort if not passed.
95
-		if ( empty( $data[ $element['id'] ] ) ) {
96
-			return;
97
-		}
98
-
99
-		$options    = getpaid_convert_price_string_to_options( $element['options'] );
100
-		$selected   = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) );
101
-		$total      = 0;
102
-		$sub_labels = array();
103
-
104
-		foreach ( $selected as $price ) {
105
-
106
-			if ( ! isset( $options[ $price ] ) ) {
107
-				throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) );
108
-			}
109
-
110
-			$price = explode( '|', $price );
111
-
112
-			$sub_labels[] = $price[0];
113
-			$total += (float) wpinv_sanitize_amount( $price[1] );
114
-		}
115
-
116
-		$this->fees[ $element['label'] ] = array(
117
-			'name'          => $element['label'],
118
-			'initial_fee'   => $total,
119
-			'recurring_fee' => 0,
120
-			'description'   => implode( ', ', $sub_labels ),
121
-		);
122
-
123
-	}
87
+     * Process a price select field.
88
+     *
89
+     * @param array $element
90
+     * @param array $data
91
+     */
92
+    public function process_price_select( $element, $data ) {
93
+
94
+        // Abort if not passed.
95
+        if ( empty( $data[ $element['id'] ] ) ) {
96
+            return;
97
+        }
98
+
99
+        $options    = getpaid_convert_price_string_to_options( $element['options'] );
100
+        $selected   = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) );
101
+        $total      = 0;
102
+        $sub_labels = array();
103
+
104
+        foreach ( $selected as $price ) {
105
+
106
+            if ( ! isset( $options[ $price ] ) ) {
107
+                throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) );
108
+            }
109
+
110
+            $price = explode( '|', $price );
111
+
112
+            $sub_labels[] = $price[0];
113
+            $total += (float) wpinv_sanitize_amount( $price[1] );
114
+        }
115
+
116
+        $this->fees[ $element['label'] ] = array(
117
+            'name'          => $element['label'],
118
+            'initial_fee'   => $total,
119
+            'recurring_fee' => 0,
120
+            'description'   => implode( ', ', $sub_labels ),
121
+        );
122
+
123
+    }
124 124
 
125 125
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-setup-wizard.php 1 patch
Indentation   +385 added lines, -385 removed lines patch added patch discarded remove patch
@@ -17,397 +17,397 @@
 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
-		}
51
-
52
-	}
53
-
54
-	/**
55
-	 * Add admin menus/screens.
56
-	 *
57
-	 * @since 2.4.0
58
-	 */
59
-	public function add_menu() {
60
-		add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
61
-	}
62
-
63
-	/**
64
-	 * Sets up the setup wizard.
65
-	 *
66
-	 * @since 2.4.0
67
-	 */
68
-	public function setup_wizard() {
69
-
70
-		if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
71
-			$this->setup_globals();
72
-			$this->maybe_save_current_step();
73
-			$this->display_wizard();
74
-			exit;
75
-		}
76
-
77
-	}
78
-
79
-	/**
80
-	 * Sets up class variables.
81
-	 *
82
-	 * @since 2.4.0
83
-	 */
84
-	protected function setup_globals() {
85
-		$this->steps         = $this->get_setup_steps();
86
-		$this->step          = $this->get_current_step();
87
-		$this->previous_step = $this->get_previous_step();
88
-		$this->next_step     = $this->get_next_step();
89
-	}
90
-
91
-	/**
92
-	 * Saves the current step.
93
-	 *
94
-	 * @since 2.4.0
95
-	 */
96
-	protected function maybe_save_current_step() {
97
-		if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
98
-			call_user_func( $this->steps[ $this->step ]['handler'], $this );
99
-		}
100
-	}
101
-
102
-	/**
103
-	 * Returns the setup steps.
104
-	 *
105
-	 * @since 2.4.0
106
-	 * @return array
107
-	 */
108
-	protected function get_setup_steps() {
109
-
110
-		$steps = array(
111
-
112
-			'introduction'     => array(
113
-				'name'    => __( 'Introduction', 'invoicing' ),
114
-				'view'    => array( $this, 'setup_introduction' ),
115
-				'handler' => '',
116
-			),
117
-
118
-			'business_details'             => array(
119
-				'name'    => __( "Business Details", 'invoicing' ),
120
-				'view'    => array( $this, 'setup_business' ),
121
-				'handler' => '',
122
-			),
123
-
124
-			'currency' => array(
125
-				'name'    => __( 'Currency', 'invoicing' ),
126
-				'view'    => array( $this, 'setup_currency' ),
127
-				'handler' => '',
128
-			),
129
-
130
-			'payments'        => array(
131
-				'name'    => __( 'Payment Gateways', 'invoicing' ),
132
-				'view'    => array( $this, 'setup_payments' ),
133
-				'handler' => array( $this, 'setup_payments_save' ),
134
-			),
135
-
136
-			'recommend'          => array(
137
-				'name'    => __( 'Recommend', 'invoicing' ),
138
-				'view'    => array( $this, 'setup_recommend' ),
139
-				'handler' => '',
140
-			),
141
-
142
-			'next_steps'       => array(
143
-				'name'    => __( 'Get Paid', 'invoicing' ),
144
-				'view'    => array( $this, 'setup_ready' ),
145
-				'handler' => '',
146
-			),
147
-
148
-		);
149
-
150
-		return apply_filters( 'getpaid_setup_wizard_steps', $steps );
151
-
152
-	}
153
-
154
-	/**
155
-	 * Returns the current step.
156
-	 *
157
-	 * @since 2.4.0
158
-	 * @return string
159
-	 */
160
-	protected function get_current_step() {
161
-		$step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
162
-		return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
163
-	}
164
-
165
-	/**
166
-	 * Returns the previous step.
167
-	 *
168
-	 * @since 2.4.0
169
-	 * @return string|false
170
-	 */
171
-	protected function get_previous_step() {
172
-
173
-		$previous = false;
174
-		$current  = $this->step;
175
-		foreach ( array_keys( $this->steps ) as $step ) {
176
-			if ( $current === $step ) {
177
-				return $previous;
178
-			}
179
-
180
-			$previous = $step;
181
-		}
182
-
183
-		return false;
184
-	}
185
-
186
-	/**
187
-	 * Returns the next step.
188
-	 *
189
-	 * @since 2.4.0
190
-	 * @return string|false
191
-	 */
192
-	protected function get_next_step() {
193
-
194
-		$on_current = false;
195
-		$current    = $this->step;
196
-		foreach ( array_keys( $this->steps ) as $step ) {
197
-
198
-			if ( $on_current ) {
199
-				return $step;
200
-			}
201
-
202
-			if ( $current === $step ) {
203
-				return $on_current = true;
204
-			}
205
-
206
-		}
207
-
208
-		return false;
209
-	}
210
-
211
-	/**
212
-	 * Displays the setup wizard.
213
-	 *
214
-	 * @since 2.4.0
215
-	 */
216
-	public function display_wizard() {
217
-		$this->display_header();
218
-		$this->display_current_step();
219
-		$this->display_footer();
220
-	}
221
-
222
-	/**
223
-	 * Displays the Wizard Header.
224
-	 *
225
-	 * @since 2.0.0
226
-	 */
227
-	public function display_header() {
228
-		$steps     = $this->steps;
229
-		$current   = $this->step;
230
-		$next_step = $this->next_step;
231
-		array_shift( $steps );
232
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
233
-	}
234
-
235
-	/**
236
-	 * Displays the content for the current step.
237
-	 *
238
-	 * @since 2.4.0
239
-	 */
240
-	public function display_current_step() {
241
-		?>
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
+        }
51
+
52
+    }
53
+
54
+    /**
55
+     * Add admin menus/screens.
56
+     *
57
+     * @since 2.4.0
58
+     */
59
+    public function add_menu() {
60
+        add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
61
+    }
62
+
63
+    /**
64
+     * Sets up the setup wizard.
65
+     *
66
+     * @since 2.4.0
67
+     */
68
+    public function setup_wizard() {
69
+
70
+        if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
71
+            $this->setup_globals();
72
+            $this->maybe_save_current_step();
73
+            $this->display_wizard();
74
+            exit;
75
+        }
76
+
77
+    }
78
+
79
+    /**
80
+     * Sets up class variables.
81
+     *
82
+     * @since 2.4.0
83
+     */
84
+    protected function setup_globals() {
85
+        $this->steps         = $this->get_setup_steps();
86
+        $this->step          = $this->get_current_step();
87
+        $this->previous_step = $this->get_previous_step();
88
+        $this->next_step     = $this->get_next_step();
89
+    }
90
+
91
+    /**
92
+     * Saves the current step.
93
+     *
94
+     * @since 2.4.0
95
+     */
96
+    protected function maybe_save_current_step() {
97
+        if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
98
+            call_user_func( $this->steps[ $this->step ]['handler'], $this );
99
+        }
100
+    }
101
+
102
+    /**
103
+     * Returns the setup steps.
104
+     *
105
+     * @since 2.4.0
106
+     * @return array
107
+     */
108
+    protected function get_setup_steps() {
109
+
110
+        $steps = array(
111
+
112
+            'introduction'     => array(
113
+                'name'    => __( 'Introduction', 'invoicing' ),
114
+                'view'    => array( $this, 'setup_introduction' ),
115
+                'handler' => '',
116
+            ),
117
+
118
+            'business_details'             => array(
119
+                'name'    => __( "Business Details", 'invoicing' ),
120
+                'view'    => array( $this, 'setup_business' ),
121
+                'handler' => '',
122
+            ),
123
+
124
+            'currency' => array(
125
+                'name'    => __( 'Currency', 'invoicing' ),
126
+                'view'    => array( $this, 'setup_currency' ),
127
+                'handler' => '',
128
+            ),
129
+
130
+            'payments'        => array(
131
+                'name'    => __( 'Payment Gateways', 'invoicing' ),
132
+                'view'    => array( $this, 'setup_payments' ),
133
+                'handler' => array( $this, 'setup_payments_save' ),
134
+            ),
135
+
136
+            'recommend'          => array(
137
+                'name'    => __( 'Recommend', 'invoicing' ),
138
+                'view'    => array( $this, 'setup_recommend' ),
139
+                'handler' => '',
140
+            ),
141
+
142
+            'next_steps'       => array(
143
+                'name'    => __( 'Get Paid', 'invoicing' ),
144
+                'view'    => array( $this, 'setup_ready' ),
145
+                'handler' => '',
146
+            ),
147
+
148
+        );
149
+
150
+        return apply_filters( 'getpaid_setup_wizard_steps', $steps );
151
+
152
+    }
153
+
154
+    /**
155
+     * Returns the current step.
156
+     *
157
+     * @since 2.4.0
158
+     * @return string
159
+     */
160
+    protected function get_current_step() {
161
+        $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
162
+        return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
163
+    }
164
+
165
+    /**
166
+     * Returns the previous step.
167
+     *
168
+     * @since 2.4.0
169
+     * @return string|false
170
+     */
171
+    protected function get_previous_step() {
172
+
173
+        $previous = false;
174
+        $current  = $this->step;
175
+        foreach ( array_keys( $this->steps ) as $step ) {
176
+            if ( $current === $step ) {
177
+                return $previous;
178
+            }
179
+
180
+            $previous = $step;
181
+        }
182
+
183
+        return false;
184
+    }
185
+
186
+    /**
187
+     * Returns the next step.
188
+     *
189
+     * @since 2.4.0
190
+     * @return string|false
191
+     */
192
+    protected function get_next_step() {
193
+
194
+        $on_current = false;
195
+        $current    = $this->step;
196
+        foreach ( array_keys( $this->steps ) as $step ) {
197
+
198
+            if ( $on_current ) {
199
+                return $step;
200
+            }
201
+
202
+            if ( $current === $step ) {
203
+                return $on_current = true;
204
+            }
205
+
206
+        }
207
+
208
+        return false;
209
+    }
210
+
211
+    /**
212
+     * Displays the setup wizard.
213
+     *
214
+     * @since 2.4.0
215
+     */
216
+    public function display_wizard() {
217
+        $this->display_header();
218
+        $this->display_current_step();
219
+        $this->display_footer();
220
+    }
221
+
222
+    /**
223
+     * Displays the Wizard Header.
224
+     *
225
+     * @since 2.0.0
226
+     */
227
+    public function display_header() {
228
+        $steps     = $this->steps;
229
+        $current   = $this->step;
230
+        $next_step = $this->next_step;
231
+        array_shift( $steps );
232
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
233
+    }
234
+
235
+    /**
236
+     * Displays the content for the current step.
237
+     *
238
+     * @since 2.4.0
239
+     */
240
+    public function display_current_step() {
241
+        ?>
242 242
 			<div class="gp-setup-content rowx mw-100 text-center mb-3">
243 243
 				<div class="col-12 col-md-5 m-auto">
244 244
 					<?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?>
245 245
 				</div>
246 246
 			</div>
247 247
 		<?php
248
-	}
249
-
250
-	/**
251
-	 * Setup Wizard Footer.
252
-	 *
253
-	 * @since 2.4.0
254
-	 */
255
-	public function display_footer() {
256
-
257
-		if ( isset( $_GET['step'] ) ) {
258
-			$next_url = esc_url( $this->get_next_step_link() );
259
-			$label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
260
-
261
-			echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>';
262
-		}
263
-
264
-		echo '</body></html>';
265
-	}
266
-
267
-	/**
268
-	 * Introduction step.
269
-	 *
270
-	 * @since 2.0.0
271
-	 */
272
-	public function setup_introduction() {
273
-		$next_url = $this->get_next_step_link();
274
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
275
-	}
276
-
277
-	/**
278
-	 * Get the URL for the next step's screen.
279
-	 *
280
-	 * @param string step   slug (default: current step)
281
-	 *
282
-	 * @return string       URL for next step if a next step exists.
283
-	 *                      Admin URL if it's the last step.
284
-	 *                      Empty string on failure.
285
-	 * @since 3.0.0
286
-	 */
287
-	public function get_next_step_link( $step = '' ) {
288
-		if ( ! $step ) {
289
-			$step = $this->step;
290
-		}
291
-
292
-		$keys = array_keys( $this->steps );
293
-		if ( end( $keys ) === $step ) {
294
-			return admin_url();
295
-		}
296
-
297
-		$step_index = array_search( $step, $keys );
298
-		if ( false === $step_index ) {
299
-			return '';
300
-		}
301
-
302
-		return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ));
303
-	}
304
-
305
-	/**
306
-	 * Setup maps api.
307
-	 *
308
-	 * @since 2.0.0
309
-	 */
310
-	public function setup_business() {
311
-		$next_url = $this->get_next_step_link();
312
-		$wizard   = $this;
313
-		$page     = 'wpinv_settings_general_main';
314
-		$section  = 'wpinv_settings_general_main';
315
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
316
-	}
317
-
318
-	/**
319
-	 * Default Location settings.
320
-	 *
321
-	 * @since 2.0.0
322
-	 */
323
-	public function setup_currency() {
324
-		$next_url = $this->get_next_step_link();
325
-		$wizard   = $this;
326
-		$page     = 'wpinv_settings_general_currency_section';
327
-		$section  = 'wpinv_settings_general_currency_section';
328
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
329
-	}
330
-
331
-	/**
332
-	 * Installation of recommended plugins.
333
-	 *
334
-	 * @since 1.0.0
335
-	 */
336
-	public function setup_recommend() {
337
-		$next_url            = $this->get_next_step_link();
338
-		$recommended_plugins = self::get_recommend_wp_plugins();
339
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
340
-	}
341
-
342
-	/**
343
-	 * A list of recommended wp.org plugins.
344
-	 * @return array
345
-	 */
346
-	public static function get_recommend_wp_plugins(){
347
-		return array(
348
-			'ayecode-connect' => array(
349
-				'file'   => 'ayecode-connect/ayecode-connect.php',
350
-				'url'    => 'https://wordpress.org/plugins/ayecode-connect/',
351
-				'slug'   => 'ayecode-connect',
352
-				'name'   => 'AyeCode Connect',
353
-				'desc'   => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ),
354
-			),
355
-			'invoicing-quotes' => array(
356
-				'file'   => 'invoicing-quotes/wpinv-quote.php',
357
-				'url'    => 'https://wordpress.org/plugins/invoicing-quotes/',
358
-				'slug'   => 'invoicing-quotes',
359
-				'name'   => 'Customer Quotes',
360
-				'desc'   => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'),
361
-			),
362
-			'userswp'    => array(
363
-				'file'   => 'userswp/userswp.php',
364
-				'url'    => 'https://wordpress.org/plugins/userswp/',
365
-				'slug'   => 'userswp',
366
-				'name'   => 'UsersWP',
367
-				'desc'   => __('Frontend user login and registration as well as slick profile pages.','geodirectory'),
368
-			),
369
-		);
370
-	}
371
-
372
-	/**
373
-	 * Dummy Data setup.
374
-	 *
375
-	 * @since 2.4.0
376
-	 */
377
-	public function setup_payments() {
378
-		$next_url = $this->get_next_step_link();
379
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
380
-	}
381
-
382
-	/**
383
-	 * Dummy data save.
384
-	 *
385
-	 * This is done via ajax so we just pass onto the next step.
386
-	 *
387
-	 * @since 2.0.0
388
-	 */
389
-	public function setup_payments_save() {
390
-		check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
391
-		wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
392
-
393
-		if ( ! empty( $_POST['paypal-email'] ) ) {
394
-			wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) );
395
-			wpinv_update_option( 'paypal_active', 1 );
396
-			wpinv_update_option( 'paypal_sandbox', 0 );
397
-		}
398
-
399
-		wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
400
-		exit;
401
-	}
402
-
403
-	/**
404
-	 * Final step.
405
-	 *
406
-	 * @since 2.0.0
407
-	 */
408
-	public function setup_ready() {
409
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
410
-	}
248
+    }
249
+
250
+    /**
251
+     * Setup Wizard Footer.
252
+     *
253
+     * @since 2.4.0
254
+     */
255
+    public function display_footer() {
256
+
257
+        if ( isset( $_GET['step'] ) ) {
258
+            $next_url = esc_url( $this->get_next_step_link() );
259
+            $label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
260
+
261
+            echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>';
262
+        }
263
+
264
+        echo '</body></html>';
265
+    }
266
+
267
+    /**
268
+     * Introduction step.
269
+     *
270
+     * @since 2.0.0
271
+     */
272
+    public function setup_introduction() {
273
+        $next_url = $this->get_next_step_link();
274
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
275
+    }
276
+
277
+    /**
278
+     * Get the URL for the next step's screen.
279
+     *
280
+     * @param string step   slug (default: current step)
281
+     *
282
+     * @return string       URL for next step if a next step exists.
283
+     *                      Admin URL if it's the last step.
284
+     *                      Empty string on failure.
285
+     * @since 3.0.0
286
+     */
287
+    public function get_next_step_link( $step = '' ) {
288
+        if ( ! $step ) {
289
+            $step = $this->step;
290
+        }
291
+
292
+        $keys = array_keys( $this->steps );
293
+        if ( end( $keys ) === $step ) {
294
+            return admin_url();
295
+        }
296
+
297
+        $step_index = array_search( $step, $keys );
298
+        if ( false === $step_index ) {
299
+            return '';
300
+        }
301
+
302
+        return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ));
303
+    }
304
+
305
+    /**
306
+     * Setup maps api.
307
+     *
308
+     * @since 2.0.0
309
+     */
310
+    public function setup_business() {
311
+        $next_url = $this->get_next_step_link();
312
+        $wizard   = $this;
313
+        $page     = 'wpinv_settings_general_main';
314
+        $section  = 'wpinv_settings_general_main';
315
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
316
+    }
317
+
318
+    /**
319
+     * Default Location settings.
320
+     *
321
+     * @since 2.0.0
322
+     */
323
+    public function setup_currency() {
324
+        $next_url = $this->get_next_step_link();
325
+        $wizard   = $this;
326
+        $page     = 'wpinv_settings_general_currency_section';
327
+        $section  = 'wpinv_settings_general_currency_section';
328
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
329
+    }
330
+
331
+    /**
332
+     * Installation of recommended plugins.
333
+     *
334
+     * @since 1.0.0
335
+     */
336
+    public function setup_recommend() {
337
+        $next_url            = $this->get_next_step_link();
338
+        $recommended_plugins = self::get_recommend_wp_plugins();
339
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
340
+    }
341
+
342
+    /**
343
+     * A list of recommended wp.org plugins.
344
+     * @return array
345
+     */
346
+    public static function get_recommend_wp_plugins(){
347
+        return array(
348
+            'ayecode-connect' => array(
349
+                'file'   => 'ayecode-connect/ayecode-connect.php',
350
+                'url'    => 'https://wordpress.org/plugins/ayecode-connect/',
351
+                'slug'   => 'ayecode-connect',
352
+                'name'   => 'AyeCode Connect',
353
+                'desc'   => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ),
354
+            ),
355
+            'invoicing-quotes' => array(
356
+                'file'   => 'invoicing-quotes/wpinv-quote.php',
357
+                'url'    => 'https://wordpress.org/plugins/invoicing-quotes/',
358
+                'slug'   => 'invoicing-quotes',
359
+                'name'   => 'Customer Quotes',
360
+                'desc'   => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'),
361
+            ),
362
+            'userswp'    => array(
363
+                'file'   => 'userswp/userswp.php',
364
+                'url'    => 'https://wordpress.org/plugins/userswp/',
365
+                'slug'   => 'userswp',
366
+                'name'   => 'UsersWP',
367
+                'desc'   => __('Frontend user login and registration as well as slick profile pages.','geodirectory'),
368
+            ),
369
+        );
370
+    }
371
+
372
+    /**
373
+     * Dummy Data setup.
374
+     *
375
+     * @since 2.4.0
376
+     */
377
+    public function setup_payments() {
378
+        $next_url = $this->get_next_step_link();
379
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
380
+    }
381
+
382
+    /**
383
+     * Dummy data save.
384
+     *
385
+     * This is done via ajax so we just pass onto the next step.
386
+     *
387
+     * @since 2.0.0
388
+     */
389
+    public function setup_payments_save() {
390
+        check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
391
+        wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
392
+
393
+        if ( ! empty( $_POST['paypal-email'] ) ) {
394
+            wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) );
395
+            wpinv_update_option( 'paypal_active', 1 );
396
+            wpinv_update_option( 'paypal_sandbox', 0 );
397
+        }
398
+
399
+        wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
400
+        exit;
401
+    }
402
+
403
+    /**
404
+     * Final step.
405
+     *
406
+     * @since 2.0.0
407
+     */
408
+    public function setup_ready() {
409
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
410
+    }
411 411
 
412 412
 }
413 413
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Indentation   +353 added lines, -353 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
 
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89 89
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
90
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92 92
 
93 93
         parent::__construct();
94 94
     }
95 95
 
96 96
     /**
97
-	 * Process Payment.
98
-	 *
99
-	 *
100
-	 * @param WPInv_Invoice $invoice Invoice.
101
-	 * @param array $submission_data Posted checkout fields.
102
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
-	 * @return array
104
-	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
97
+     * Process Payment.
98
+     *
99
+     *
100
+     * @param WPInv_Invoice $invoice Invoice.
101
+     * @param array $submission_data Posted checkout fields.
102
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
+     * @return array
104
+     */
105
+    public function process_payment( $invoice, $submission_data, $submission ) {
106 106
 
107 107
         // Get redirect url.
108 108
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get the PayPal request URL for an invoice.
129
-	 *
130
-	 * @param  WPInv_Invoice $invoice Invoice object.
131
-	 * @return string
132
-	 */
133
-	public function get_request_url( $invoice ) {
128
+     * Get the PayPal request URL for an invoice.
129
+     *
130
+     * @param  WPInv_Invoice $invoice Invoice object.
131
+     * @return string
132
+     */
133
+    public function get_request_url( $invoice ) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139 139
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -146,44 +146,44 @@  discard block
 block discarded – undo
146 146
 
147 147
         return add_query_arg( $paypal_args, $this->endpoint );
148 148
 
149
-	}
149
+    }
150 150
 
151 151
     /**
152
-	 * Get PayPal Args for passing to PP.
153
-	 *
154
-	 * @param  WPInv_Invoice $invoice Invoice object.
155
-	 * @return array
156
-	 */
157
-	protected function get_paypal_args( $invoice ) {
152
+     * Get PayPal Args for passing to PP.
153
+     *
154
+     * @param  WPInv_Invoice $invoice Invoice object.
155
+     * @return array
156
+     */
157
+    protected function get_paypal_args( $invoice ) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
160
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161 161
 
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
-			$force_one_line_item = true;
164
-		}
162
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+            $force_one_line_item = true;
164
+        }
165 165
 
166
-		$paypal_args = apply_filters(
167
-			'getpaid_paypal_args',
168
-			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
171
-			),
172
-			$invoice
173
-		);
166
+        $paypal_args = apply_filters(
167
+            'getpaid_paypal_args',
168
+            array_merge(
169
+                $this->get_transaction_args( $invoice ),
170
+                $this->get_line_item_args( $invoice, $force_one_line_item )
171
+            ),
172
+            $invoice
173
+        );
174 174
 
175
-		return $this->fix_request_length( $invoice, $paypal_args );
175
+        return $this->fix_request_length( $invoice, $paypal_args );
176 176
     }
177 177
 
178 178
     /**
179
-	 * Get transaction args for paypal request.
180
-	 *
181
-	 * @param WPInv_Invoice $invoice Invoice object.
182
-	 * @return array
183
-	 */
184
-	protected function get_transaction_args( $invoice ) {
185
-
186
-		return array(
179
+     * Get transaction args for paypal request.
180
+     *
181
+     * @param WPInv_Invoice $invoice Invoice object.
182
+     * @return array
183
+     */
184
+    protected function get_transaction_args( $invoice ) {
185
+
186
+        return array(
187 187
             'cmd'           => '_cart',
188 188
             'business'      => wpinv_get_option( 'paypal_email', false ),
189 189
             'no_shipping'   => '1',
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
     }
209 209
 
210 210
     /**
211
-	 * Get line item args for paypal request.
212
-	 *
213
-	 * @param  WPInv_Invoice $invoice Invoice object.
214
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
215
-	 * @return array
216
-	 */
217
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
211
+     * Get line item args for paypal request.
212
+     *
213
+     * @param  WPInv_Invoice $invoice Invoice object.
214
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
215
+     * @return array
216
+     */
217
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
218 218
 
219 219
         // Maybe send invoice as a single item.
220
-		if ( $force_one_line_item ) {
220
+        if ( $force_one_line_item ) {
221 221
             return $this->get_line_item_args_single_item( $invoice );
222 222
         }
223 223
 
@@ -237,129 +237,129 @@  discard block
 block discarded – undo
237 237
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
238 238
         }
239 239
 
240
-		return array_merge( $line_item_args, $this->get_line_items() );
240
+        return array_merge( $line_item_args, $this->get_line_items() );
241 241
 
242 242
     }
243 243
 
244 244
     /**
245
-	 * Get line item args for paypal request as a single line item.
246
-	 *
247
-	 * @param  WPInv_Invoice $invoice Invoice object.
248
-	 * @return array
249
-	 */
250
-	protected function get_line_item_args_single_item( $invoice ) {
251
-		$this->delete_line_items();
245
+     * Get line item args for paypal request as a single line item.
246
+     *
247
+     * @param  WPInv_Invoice $invoice Invoice object.
248
+     * @return array
249
+     */
250
+    protected function get_line_item_args_single_item( $invoice ) {
251
+        $this->delete_line_items();
252 252
 
253 253
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
254
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
254
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255 255
 
256
-		return $this->get_line_items();
256
+        return $this->get_line_items();
257 257
     }
258 258
 
259 259
     /**
260
-	 * Return all line items.
261
-	 */
262
-	protected function get_line_items() {
263
-		return $this->line_items;
264
-	}
260
+     * Return all line items.
261
+     */
262
+    protected function get_line_items() {
263
+        return $this->line_items;
264
+    }
265 265
 
266 266
     /**
267
-	 * Remove all line items.
268
-	 */
269
-	protected function delete_line_items() {
270
-		$this->line_items = array();
267
+     * Remove all line items.
268
+     */
269
+    protected function delete_line_items() {
270
+        $this->line_items = array();
271 271
     }
272 272
 
273 273
     /**
274
-	 * Prepare line items to send to paypal.
275
-	 *
276
-	 * @param  WPInv_Invoice $invoice Invoice object.
277
-	 */
278
-	protected function prepare_line_items( $invoice ) {
279
-		$this->delete_line_items();
280
-
281
-		// Items.
282
-		foreach ( $invoice->get_items() as $item ) {
283
-			$amount   = $item->get_price();
284
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
285
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
274
+     * Prepare line items to send to paypal.
275
+     *
276
+     * @param  WPInv_Invoice $invoice Invoice object.
277
+     */
278
+    protected function prepare_line_items( $invoice ) {
279
+        $this->delete_line_items();
280
+
281
+        // Items.
282
+        foreach ( $invoice->get_items() as $item ) {
283
+            $amount   = $item->get_price();
284
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
285
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
286 286
         }
287 287
 
288 288
         // Fees.
289
-		foreach ( $invoice->get_fees() as $fee => $data ) {
289
+        foreach ( $invoice->get_fees() as $fee => $data ) {
290 290
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
291 291
         }
292 292
 
293 293
     }
294 294
 
295 295
     /**
296
-	 * Add PayPal Line Item.
297
-	 *
298
-	 * @param  string $item_name Item name.
299
-	 * @param  float    $quantity Item quantity.
300
-	 * @param  float  $amount Amount.
301
-	 * @param  string $item_number Item number.
302
-	 */
303
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
304
-		$index = ( count( $this->line_items ) / 4 ) + 1;
305
-
306
-		$item = apply_filters(
307
-			'getpaid_paypal_line_item',
308
-			array(
309
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
310
-				'quantity'    => (float) $quantity,
311
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
312
-				'item_number' => $item_number,
313
-			),
314
-			$item_name,
315
-			$quantity,
316
-			$amount,
317
-			$item_number
318
-		);
296
+     * Add PayPal Line Item.
297
+     *
298
+     * @param  string $item_name Item name.
299
+     * @param  float    $quantity Item quantity.
300
+     * @param  float  $amount Amount.
301
+     * @param  string $item_number Item number.
302
+     */
303
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
304
+        $index = ( count( $this->line_items ) / 4 ) + 1;
319 305
 
320
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
306
+        $item = apply_filters(
307
+            'getpaid_paypal_line_item',
308
+            array(
309
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
310
+                'quantity'    => (float) $quantity,
311
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
312
+                'item_number' => $item_number,
313
+            ),
314
+            $item_name,
315
+            $quantity,
316
+            $amount,
317
+            $item_number
318
+        );
319
+
320
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
321 321
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
322 322
 
323 323
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
324
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
325
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
324
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
325
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
326 326
     }
327 327
 
328 328
     /**
329
-	 * If the default request with line items is too long, generate a new one with only one line item.
330
-	 *
331
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
332
-	 *
333
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
334
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
335
-	 * @return array
336
-	 */
337
-	protected function fix_request_length( $invoice, $paypal_args ) {
338
-		$max_paypal_length = 2083;
339
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
340
-
341
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
342
-			return $paypal_args;
343
-		}
344
-
345
-		return apply_filters(
346
-			'getpaid_paypal_args',
347
-			array_merge(
348
-				$this->get_transaction_args( $invoice ),
349
-				$this->get_line_item_args( $invoice, true )
350
-			),
351
-			$invoice
352
-		);
329
+     * If the default request with line items is too long, generate a new one with only one line item.
330
+     *
331
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
332
+     *
333
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
334
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
335
+     * @return array
336
+     */
337
+    protected function fix_request_length( $invoice, $paypal_args ) {
338
+        $max_paypal_length = 2083;
339
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
340
+
341
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
342
+            return $paypal_args;
343
+        }
344
+
345
+        return apply_filters(
346
+            'getpaid_paypal_args',
347
+            array_merge(
348
+                $this->get_transaction_args( $invoice ),
349
+                $this->get_line_item_args( $invoice, true )
350
+            ),
351
+            $invoice
352
+        );
353 353
 
354 354
     }
355 355
 
356 356
     /**
357
-	 * Processes recurring invoices.
358
-	 *
359
-	 * @param  array $paypal_args PayPal args.
360
-	 * @param  WPInv_Invoice    $invoice Invoice object.
361
-	 */
362
-	public function process_subscription( $paypal_args, $invoice ) {
357
+     * Processes recurring invoices.
358
+     *
359
+     * @param  array $paypal_args PayPal args.
360
+     * @param  WPInv_Invoice    $invoice Invoice object.
361
+     */
362
+    public function process_subscription( $paypal_args, $invoice ) {
363 363
 
364 364
         // Make sure this is a subscription.
365 365
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -384,11 +384,11 @@  discard block
 block discarded – undo
384 384
 
385 385
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
386 386
 
387
-			// Trial period length.
388
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
387
+            // Trial period length.
388
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
389 389
 
390
-			// Trial period.
391
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
390
+            // Trial period.
391
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
392 392
 
393 393
         } else if ( $initial_amount != $recurring_amount ) {
394 394
 
@@ -411,40 +411,40 @@  discard block
 block discarded – undo
411 411
         }
412 412
 
413 413
         // We have a recurring payment
414
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
414
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
415 415
 
416
-			// Subscription price
417
-			$paypal_args['a3'] = $recurring_amount;
416
+            // Subscription price
417
+            $paypal_args['a3'] = $recurring_amount;
418 418
 
419
-			// Subscription duration
420
-			$paypal_args['p3'] = $interval;
419
+            // Subscription duration
420
+            $paypal_args['p3'] = $interval;
421 421
 
422
-			// Subscription period
423
-			$paypal_args['t3'] = $period;
422
+            // Subscription period
423
+            $paypal_args['t3'] = $period;
424 424
 
425 425
         }
426 426
 
427 427
         // Recurring payments
428
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
428
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
429 429
 
430
-			// Non-recurring payments
431
-			$paypal_args['src'] = 0;
430
+            // Non-recurring payments
431
+            $paypal_args['src'] = 0;
432 432
 
433
-		} else {
433
+        } else {
434 434
 
435
-			$paypal_args['src'] = 1;
435
+            $paypal_args['src'] = 1;
436 436
 
437
-			if ( $bill_times > 0 ) {
437
+            if ( $bill_times > 0 ) {
438 438
 
439
-				// An initial period is being used to charge a sign-up fee
440
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
441
-					$bill_times--;
442
-				}
439
+                // An initial period is being used to charge a sign-up fee
440
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
441
+                    $bill_times--;
442
+                }
443 443
 
444 444
                 // Make sure it's not over the max of 52
445 445
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
446 446
 
447
-			}
447
+            }
448 448
         }
449 449
 
450 450
         // Force return URL so that order description & instructions display
@@ -460,19 +460,19 @@  discard block
 block discarded – undo
460 460
         }
461 461
 
462 462
         return apply_filters(
463
-			'getpaid_paypal_subscription_args',
464
-			$paypal_args,
465
-			$invoice
463
+            'getpaid_paypal_subscription_args',
464
+            $paypal_args,
465
+            $invoice
466 466
         );
467 467
 
468 468
     }
469 469
 
470 470
     /**
471
-	 * Processes ipns and marks payments as complete.
472
-	 *
473
-	 * @return void
474
-	 */
475
-	public function verify_ipn() {
471
+     * Processes ipns and marks payments as complete.
472
+     *
473
+     * @return void
474
+     */
475
+    public function verify_ipn() {
476 476
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
477 477
     }
478 478
 
@@ -482,19 +482,19 @@  discard block
 block discarded – undo
482 482
     public function sandbox_notice() {
483 483
 
484 484
         return sprintf(
485
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
486
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
487
-			'</a>'
488
-		);
485
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
486
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
487
+            '</a>'
488
+        );
489 489
 
490 490
     }
491 491
 
492
-	/**
493
-	 * Filters the gateway settings.
494
-	 *
495
-	 * @param array $admin_settings
496
-	 */
497
-	public function admin_settings( $admin_settings ) {
492
+    /**
493
+     * Filters the gateway settings.
494
+     *
495
+     * @param array $admin_settings
496
+     */
497
+    public function admin_settings( $admin_settings ) {
498 498
 
499 499
         $currencies = sprintf(
500 500
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 
504 504
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
505 505
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
506
-		/*
506
+        /*
507 507
 		// Access tokens.
508 508
         $live_account    = wpinv_get_option( 'paypal_live_access_token' );
509 509
         $sandbox_account = wpinv_get_option( 'paypal_test_access_token' );
@@ -534,12 +534,12 @@  discard block
 block discarded – undo
534 534
 		*/
535 535
         $admin_settings['paypal_email'] = array(
536 536
             'type'  => 'text',
537
-			'class' => 'live-auth-data',
537
+            'class' => 'live-auth-data',
538 538
             'id'    => 'paypal_email',
539 539
             'name'  => __( 'Live Email Address', 'invoicing' ),
540 540
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
541 541
         );
542
-		/*
542
+        /*
543 543
 		$admin_settings['paypal_merchant_id'] = array(
544 544
             'type'  => 'text',
545 545
 			'class' => 'live-auth-data',
@@ -600,29 +600,29 @@  discard block
 block discarded – undo
600 600
             'readonly' => true,
601 601
         );
602 602
 
603
-		return $admin_settings;
604
-	}
603
+        return $admin_settings;
604
+    }
605 605
 
606
-	/**
607
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
608
-	 *
609
-	 *
606
+    /**
607
+     * Retrieves the PayPal connect URL when using the setup wizzard.
608
+     *
609
+     *
610 610
      * @param array $data
611 611
      * @return string
612
-	 */
613
-	public static function maybe_get_connect_url( $url = '', $data ) {
614
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
615
-	}
616
-
617
-	/**
618
-	 * Retrieves the PayPal connect URL.
619
-	 *
620
-	 *
612
+     */
613
+    public static function maybe_get_connect_url( $url = '', $data ) {
614
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
615
+    }
616
+
617
+    /**
618
+     * Retrieves the PayPal connect URL.
619
+     *
620
+     *
621 621
      * @param bool $is_sandbox
622
-	 * @param string $redirect
622
+     * @param string $redirect
623 623
      * @return string
624
-	 */
625
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
624
+     */
625
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
626 626
 
627 627
         $redirect_url = add_query_arg(
628 628
             array(
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
                 'tab'                  => 'gateways',
633 633
                 'section'              => 'paypal',
634 634
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
635
-				'redirect'             => urlencode( $redirect ),
635
+                'redirect'             => urlencode( $redirect ),
636 636
             ),
637 637
             admin_url( 'admin.php' )
638 638
         );
@@ -647,12 +647,12 @@  discard block
 block discarded – undo
647 647
 
648 648
     }
649 649
 
650
-	/**
651
-	 * Generates settings page js.
652
-	 *
650
+    /**
651
+     * Generates settings page js.
652
+     *
653 653
      * @return void
654
-	 */
655
-	public static function get_js() { return '';
654
+     */
655
+    public static function get_js() { return '';
656 656
         ob_start();
657 657
         ?>
658 658
             <script>
@@ -698,109 +698,109 @@  discard block
 block discarded – undo
698 698
         return ob_get_clean();
699 699
     }
700 700
 
701
-	/**
702
-	 * Connects to PayPal.
703
-	 *
704
-	 * @param array $data Connection data.
705
-	 * @return void
706
-	 */
707
-	public function connect_paypal( $data ) {
708
-
709
-		$sandbox      = $this->is_sandbox();
710
-		$data         = wp_unslash( $data );
711
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
712
-
713
-		if ( isset( $data['live_mode'] ) ) {
714
-			$sandbox = empty( $data['live_mode'] );
715
-		}
716
-
717
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
718
-		wpinv_update_option( 'paypal_active', 1 );
719
-
720
-		if ( ! empty( $data['error_description'] ) ) {
721
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
722
-		} else {
723
-
724
-			// Retrieve the user info.
725
-			$user_info = wp_remote_get(
726
-				! $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',
727
-				array(
728
-
729
-					'headers' => array(
730
-						'Authorization' => 'Bearer ' . $access_token,
731
-						'Content-type'  => 'application/json',
732
-					)
733
-
734
-				)
735
-			);
736
-
737
-			if ( is_wp_error( $user_info ) ) {
738
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
739
-			} else {
740
-
741
-				// Create application.
742
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
743
-				$app       = wp_remote_post(
744
-					! $sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications',
745
-					array(
746
-
747
-						'body'    => array(
748
-							'application_type' => 'web',
749
-							'redirect_uris'    => array(
750
-								add_query_arg( 'getpaid_oauth', 'paypal', home_url() ),
751
-							),
752
-							'client_name'      => 'GetPaid',
753
-							'contacts'         => array( $user_info->emails[0]->value ),
754
-							'payer_id'         => $user_info->payer_id,
755
-							'migrated_app'     => '',
756
-						),
757
-						'headers' => array(
758
-							'Authorization' => 'Bearer ' . $access_token,
759
-							'Content-type'  => 'application/json',
760
-						)
761
-
762
-					)
763
-				);
764
-
765
-				if ( is_wp_error( $app ) ) {
766
-					getpaid_admin()->show_error( wp_kses_post( $app->get_error_message() ) );
767
-				} else {
768
-
769
-					$app = json_decode( wp_remote_retrieve_body( $app ) );
770
-					wpinv_error_log( $app );
771
-					if ( $sandbox ) {
772
-						wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
773
-						wpinv_update_option( 'paypal_sandbox_merchant_id', '' );
774
-						wpinv_update_option( 'paypal_sandbox_client_id', sanitize_text_field( '' ) );
775
-						wpinv_update_option( 'paypal_sandbox_client_secret', sanitize_text_field( '' ) );
776
-						wpinv_update_option( 'paypal_sandbox_client_secret_expires_at', sanitize_text_field( '' ) );
777
-						wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
778
-						set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
779
-						getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
780
-					} else {
781
-						wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
782
-						wpinv_update_option( 'paypal_merchant_id', '' );
783
-						wpinv_update_option( 'paypal_client_id', sanitize_text_field( '' ) );
784
-						wpinv_update_option( 'paypal_client_secret', sanitize_text_field( '' ) );
785
-						wpinv_update_option( 'paypal_client_secret_expires_at', sanitize_text_field( '' ) );
786
-						wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
787
-						set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
788
-						getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
789
-					}
701
+    /**
702
+     * Connects to PayPal.
703
+     *
704
+     * @param array $data Connection data.
705
+     * @return void
706
+     */
707
+    public function connect_paypal( $data ) {
790 708
 
791
-				}
709
+        $sandbox      = $this->is_sandbox();
710
+        $data         = wp_unslash( $data );
711
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
792 712
 
793
-			}
713
+        if ( isset( $data['live_mode'] ) ) {
714
+            $sandbox = empty( $data['live_mode'] );
715
+        }
794 716
 
795
-		}
717
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
718
+        wpinv_update_option( 'paypal_active', 1 );
796 719
 
797
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
720
+        if ( ! empty( $data['error_description'] ) ) {
721
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
722
+        } else {
723
+
724
+            // Retrieve the user info.
725
+            $user_info = wp_remote_get(
726
+                ! $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',
727
+                array(
728
+
729
+                    'headers' => array(
730
+                        'Authorization' => 'Bearer ' . $access_token,
731
+                        'Content-type'  => 'application/json',
732
+                    )
798 733
 
799
-		if ( isset( $data['step'] ) ) {
800
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
801
-		}
802
-		wp_redirect( $redirect );
803
-		exit;
804
-	}
734
+                )
735
+            );
736
+
737
+            if ( is_wp_error( $user_info ) ) {
738
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
739
+            } else {
740
+
741
+                // Create application.
742
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
743
+                $app       = wp_remote_post(
744
+                    ! $sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications',
745
+                    array(
746
+
747
+                        'body'    => array(
748
+                            'application_type' => 'web',
749
+                            'redirect_uris'    => array(
750
+                                add_query_arg( 'getpaid_oauth', 'paypal', home_url() ),
751
+                            ),
752
+                            'client_name'      => 'GetPaid',
753
+                            'contacts'         => array( $user_info->emails[0]->value ),
754
+                            'payer_id'         => $user_info->payer_id,
755
+                            'migrated_app'     => '',
756
+                        ),
757
+                        'headers' => array(
758
+                            'Authorization' => 'Bearer ' . $access_token,
759
+                            'Content-type'  => 'application/json',
760
+                        )
761
+
762
+                    )
763
+                );
764
+
765
+                if ( is_wp_error( $app ) ) {
766
+                    getpaid_admin()->show_error( wp_kses_post( $app->get_error_message() ) );
767
+                } else {
768
+
769
+                    $app = json_decode( wp_remote_retrieve_body( $app ) );
770
+                    wpinv_error_log( $app );
771
+                    if ( $sandbox ) {
772
+                        wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
773
+                        wpinv_update_option( 'paypal_sandbox_merchant_id', '' );
774
+                        wpinv_update_option( 'paypal_sandbox_client_id', sanitize_text_field( '' ) );
775
+                        wpinv_update_option( 'paypal_sandbox_client_secret', sanitize_text_field( '' ) );
776
+                        wpinv_update_option( 'paypal_sandbox_client_secret_expires_at', sanitize_text_field( '' ) );
777
+                        wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
778
+                        set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
779
+                        getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
780
+                    } else {
781
+                        wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
782
+                        wpinv_update_option( 'paypal_merchant_id', '' );
783
+                        wpinv_update_option( 'paypal_client_id', sanitize_text_field( '' ) );
784
+                        wpinv_update_option( 'paypal_client_secret', sanitize_text_field( '' ) );
785
+                        wpinv_update_option( 'paypal_client_secret_expires_at', sanitize_text_field( '' ) );
786
+                        wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
787
+                        set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
788
+                        getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
789
+                    }
790
+
791
+                }
792
+
793
+            }
794
+
795
+        }
796
+
797
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
798
+
799
+        if ( isset( $data['step'] ) ) {
800
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
801
+        }
802
+        wp_redirect( $redirect );
803
+        exit;
804
+    }
805 805
 
806 806
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +543 added lines, -543 removed lines patch added patch discarded remove patch
@@ -14,89 +14,89 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29 29
 	
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct(){
38
+     * Class constructor.
39
+     */
40
+    public function __construct(){
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect') );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
66 66
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
74
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
75
-		do_action( 'getpaid_init_admin_hooks', $this );
76
-
77
-		// Setup/welcome
78
-		if ( ! empty( $_GET['page'] ) ) {
79
-			switch ( $_GET['page'] ) {
80
-				case 'gp-setup' :
81
-					include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
82
-					break;
83
-			}
84
-		}
67
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
68
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
69
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
70
+        add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
71
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
72
+        add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
73
+        add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
74
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
75
+        do_action( 'getpaid_init_admin_hooks', $this );
76
+
77
+        // Setup/welcome
78
+        if ( ! empty( $_GET['page'] ) ) {
79
+            switch ( $_GET['page'] ) {
80
+                case 'gp-setup' :
81
+                    include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
82
+                    break;
83
+            }
84
+        }
85 85
 
86 86
     }
87 87
 
88 88
     /**
89
-	 * Register admin scripts
90
-	 *
91
-	 */
92
-	public function enqeue_scripts() {
89
+     * Register admin scripts
90
+     *
91
+     */
92
+    public function enqeue_scripts() {
93 93
         global $current_screen, $pagenow;
94 94
 
95
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
96
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
95
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
96
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
97 97
 
98 98
         if ( ! empty( $current_screen->post_type ) ) {
99
-			$page = $current_screen->post_type;
99
+            $page = $current_screen->post_type;
100 100
         }
101 101
 
102 102
         // General styles.
@@ -117,54 +117,54 @@  discard block
 block discarded – undo
117 117
         }
118 118
 
119 119
         // Payment form scripts.
120
-		if ( 'wpi_payment_form' == $page && $editing ) {
120
+        if ( 'wpi_payment_form' == $page && $editing ) {
121 121
             $this->load_payment_form_scripts();
122 122
         }
123 123
 
124
-		if ( $page == 'wpinv-subscriptions' ) {
125
-			wp_enqueue_script( 'postbox' );
126
-		}
124
+        if ( $page == 'wpinv-subscriptions' ) {
125
+            wp_enqueue_script( 'postbox' );
126
+        }
127 127
 
128 128
     }
129 129
 
130 130
     /**
131
-	 * Returns admin js translations.
132
-	 *
133
-	 */
134
-	protected function get_admin_i18() {
131
+     * Returns admin js translations.
132
+     *
133
+     */
134
+    protected function get_admin_i18() {
135 135
         global $post;
136 136
 
137
-		$date_range = array(
138
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
139
-		);
137
+        $date_range = array(
138
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
139
+        );
140 140
 
141
-		if ( $date_range['period'] == 'custom' ) {
141
+        if ( $date_range['period'] == 'custom' ) {
142 142
 			
143
-			if ( isset( $_GET['from'] ) ) {
144
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
145
-			}
143
+            if ( isset( $_GET['from'] ) ) {
144
+                $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
145
+            }
146 146
 
147
-			if ( isset( $_GET['to'] ) ) {
148
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
149
-			}
147
+            if ( isset( $_GET['to'] ) ) {
148
+                $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
149
+            }
150 150
 
151
-		}
151
+        }
152 152
 
153 153
         $i18n = array(
154 154
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
155 155
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
156
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
157
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
158
-			'rest_root'                 => esc_url_raw( rest_url() ),
159
-			'date_range'                => $date_range,
156
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
157
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
158
+            'rest_root'                 => esc_url_raw( rest_url() ),
159
+            'date_range'                => $date_range,
160 160
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
161 161
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
162 162
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
163 163
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
164 164
             'tax'                       => wpinv_tax_amount(),
165 165
             'discount'                  => 0,
166
-			'currency_symbol'           => wpinv_currency_symbol(),
167
-			'currency'                  => wpinv_get_currency(),
166
+            'currency_symbol'           => wpinv_currency_symbol(),
167
+            'currency'                  => wpinv_get_currency(),
168 168
             'currency_pos'              => wpinv_currency_position(),
169 169
             'thousand_sep'              => wpinv_thousands_separator(),
170 170
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -184,118 +184,118 @@  discard block
 block discarded – undo
184 184
             'item_description'          => __( 'Item Description', 'invoicing' ),
185 185
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
186 186
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
187
-			'searching'                 => __( 'Searching', 'invoicing' ),
188
-			'loading'                   => __( 'Loading...', 'invoicing' ),
189
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
190
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
187
+            'searching'                 => __( 'Searching', 'invoicing' ),
188
+            'loading'                   => __( 'Loading...', 'invoicing' ),
189
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
190
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
191 191
         );
192 192
 
193
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
193
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
194 194
 
195
-			$invoice              = new WPInv_Invoice( $post );
196
-			$i18n['save_invoice'] = sprintf(
197
-				__( 'Save %s', 'invoicing' ),
198
-				ucfirst( $invoice->get_invoice_quote_type() )
199
-			);
195
+            $invoice              = new WPInv_Invoice( $post );
196
+            $i18n['save_invoice'] = sprintf(
197
+                __( 'Save %s', 'invoicing' ),
198
+                ucfirst( $invoice->get_invoice_quote_type() )
199
+            );
200 200
 
201
-			$i18n['invoice_description'] = sprintf(
202
-				__( '%s Description', 'invoicing' ),
203
-				ucfirst( $invoice->get_invoice_quote_type() )
204
-			);
201
+            $i18n['invoice_description'] = sprintf(
202
+                __( '%s Description', 'invoicing' ),
203
+                ucfirst( $invoice->get_invoice_quote_type() )
204
+            );
205 205
 
206
-		}
207
-		return $i18n;
208
-	}
206
+        }
207
+        return $i18n;
208
+    }
209 209
 
210
-	/**
211
-	 * Change the admin footer text on GetPaid admin pages.
212
-	 *
213
-	 * @since  2.0.0
214
-	 * @param  string $footer_text
215
-	 * @return string
216
-	 */
217
-	public function admin_footer_text( $footer_text ) {
218
-		global $current_screen;
210
+    /**
211
+     * Change the admin footer text on GetPaid admin pages.
212
+     *
213
+     * @since  2.0.0
214
+     * @param  string $footer_text
215
+     * @return string
216
+     */
217
+    public function admin_footer_text( $footer_text ) {
218
+        global $current_screen;
219 219
 
220
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
220
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
221 221
 
222 222
         if ( ! empty( $current_screen->post_type ) ) {
223
-			$page = $current_screen->post_type;
223
+            $page = $current_screen->post_type;
224 224
         }
225 225
 
226 226
         // General styles.
227 227
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
228 228
 
229
-			// Change the footer text
230
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
231
-
232
-				$rating_url  = esc_url(
233
-					wp_nonce_url(
234
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
235
-						'getpaid-nonce',
236
-						'getpaid-nonce'
237
-						)
238
-				);
239
-
240
-				$footer_text = sprintf(
241
-					/* translators: %s: five stars */
242
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
243
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
244
-				);
245
-
246
-			} else {
247
-
248
-				$footer_text = sprintf(
249
-					/* translators: %s: GetPaid */
250
-					__( 'Thank you for using %s!', 'invoicing' ),
251
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
252
-				);
253
-
254
-			}
255
-
256
-		}
257
-
258
-		return $footer_text;
259
-	}
260
-
261
-	/**
262
-	 * Redirects to wp.org to rate the plugin.
263
-	 *
264
-	 * @since  2.0.0
265
-	 */
266
-	public function redirect_to_wordpress_rating_page() {
267
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
268
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
269
-		exit;
270
-	}
271
-
272
-    /**
273
-	 * Loads payment form js.
274
-	 *
275
-	 */
276
-	protected function load_payment_form_scripts() {
229
+            // Change the footer text
230
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
231
+
232
+                $rating_url  = esc_url(
233
+                    wp_nonce_url(
234
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
235
+                        'getpaid-nonce',
236
+                        'getpaid-nonce'
237
+                        )
238
+                );
239
+
240
+                $footer_text = sprintf(
241
+                    /* translators: %s: five stars */
242
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
243
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
244
+                );
245
+
246
+            } else {
247
+
248
+                $footer_text = sprintf(
249
+                    /* translators: %s: GetPaid */
250
+                    __( 'Thank you for using %s!', 'invoicing' ),
251
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
252
+                );
253
+
254
+            }
255
+
256
+        }
257
+
258
+        return $footer_text;
259
+    }
260
+
261
+    /**
262
+     * Redirects to wp.org to rate the plugin.
263
+     *
264
+     * @since  2.0.0
265
+     */
266
+    public function redirect_to_wordpress_rating_page() {
267
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
268
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
269
+        exit;
270
+    }
271
+
272
+    /**
273
+     * Loads payment form js.
274
+     *
275
+     */
276
+    protected function load_payment_form_scripts() {
277 277
         global $post;
278 278
 
279 279
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
280
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
281
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
280
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
281
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
282 282
 
283
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
284
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
283
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
284
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
285 285
 
286
-		wp_localize_script(
286
+        wp_localize_script(
287 287
             'wpinv-admin-payment-form-script',
288 288
             'wpinvPaymentFormAdmin',
289 289
             array(
290
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
291
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
292
-				'currency'      => wpinv_currency_symbol(),
293
-				'position'      => wpinv_currency_position(),
294
-				'decimals'      => (int) wpinv_decimals(),
295
-				'thousands_sep' => wpinv_thousands_separator(),
296
-				'decimals_sep'  => wpinv_decimal_separator(),
297
-				'form_items'    => gepaid_get_form_items( $post->ID ),
298
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
290
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
291
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
292
+                'currency'      => wpinv_currency_symbol(),
293
+                'position'      => wpinv_currency_position(),
294
+                'decimals'      => (int) wpinv_decimals(),
295
+                'thousands_sep' => wpinv_thousands_separator(),
296
+                'decimals_sep'  => wpinv_decimal_separator(),
297
+                'form_items'    => gepaid_get_form_items( $post->ID ),
298
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
299 299
             )
300 300
         );
301 301
 
@@ -304,20 +304,20 @@  discard block
 block discarded – undo
304 304
     }
305 305
 
306 306
     /**
307
-	 * Add our classes to admin pages.
307
+     * Add our classes to admin pages.
308 308
      *
309 309
      * @param string $classes
310 310
      * @return string
311
-	 *
312
-	 */
311
+     *
312
+     */
313 313
     public function admin_body_class( $classes ) {
314
-		global $pagenow, $post, $current_screen;
314
+        global $pagenow, $post, $current_screen;
315 315
 
316 316
 
317 317
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
318 318
 
319 319
         if ( ! empty( $current_screen->post_type ) ) {
320
-			$page = $current_screen->post_type;
320
+            $page = $current_screen->post_type;
321 321
         }
322 322
 
323 323
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -326,68 +326,68 @@  discard block
 block discarded – undo
326 326
 
327 327
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
328 328
             $classes .= ' wpinv-cpt wpinv';
329
-		}
329
+        }
330 330
 		
331
-		if ( getpaid_is_invoice_post_type( $page ) ) {
331
+        if ( getpaid_is_invoice_post_type( $page ) ) {
332 332
             $classes .= ' getpaid-is-invoice-cpt';
333 333
         }
334 334
 
335
-		return $classes;
335
+        return $classes;
336 336
     }
337 337
 
338 338
     /**
339
-	 * Maybe show the AyeCode Connect Notice.
340
-	 */
341
-	public function init_ayecode_connect_helper(){
339
+     * Maybe show the AyeCode Connect Notice.
340
+     */
341
+    public function init_ayecode_connect_helper(){
342 342
 
343
-		// Register with the deactivation survey class.
344
-		AyeCode_Deactivation_Survey::instance(array(
345
-			'slug'		        => 'invoicing',
346
-			'version'	        => WPINV_VERSION,
347
-			'support_url'       => 'https://wpgetpaid.com/support/',
348
-			'documentation_url' => 'https://docs.wpgetpaid.com/',
349
-			'activated'         => (int) get_option( 'gepaid_installed_on' ),
350
-		));
343
+        // Register with the deactivation survey class.
344
+        AyeCode_Deactivation_Survey::instance(array(
345
+            'slug'		        => 'invoicing',
346
+            'version'	        => WPINV_VERSION,
347
+            'support_url'       => 'https://wpgetpaid.com/support/',
348
+            'documentation_url' => 'https://docs.wpgetpaid.com/',
349
+            'activated'         => (int) get_option( 'gepaid_installed_on' ),
350
+        ));
351 351
 
352 352
         new AyeCode_Connect_Helper(
353 353
             array(
354
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
355
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
356
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
357
-				'connect_button'    => __("Connect Site","invoicing"),
358
-				'connecting_button'    => __("Connecting...","invoicing"),
359
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
360
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
354
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
355
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
356
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
357
+                'connect_button'    => __("Connect Site","invoicing"),
358
+                'connecting_button'    => __("Connecting...","invoicing"),
359
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
360
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
361 361
             ),
362 362
             array( 'wpi-addons' )
363 363
         );
364 364
 
365 365
     }
366 366
 
367
-	/**
368
-	 * Redirect users to settings on activation.
369
-	 *
370
-	 * @return void
371
-	 */
372
-	public function activation_redirect() {
367
+    /**
368
+     * Redirect users to settings on activation.
369
+     *
370
+     * @return void
371
+     */
372
+    public function activation_redirect() {
373 373
 
374
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
374
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
375 375
 
376
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
377
-			return;
378
-		}
376
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
377
+            return;
378
+        }
379 379
 
380
-		// Bail if activating from network, or bulk
381
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
382
-			return;
383
-		}
380
+        // Bail if activating from network, or bulk
381
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
382
+            return;
383
+        }
384 384
 
385
-	    update_option( 'wpinv_redirected_to_settings', 1 );
385
+        update_option( 'wpinv_redirected_to_settings', 1 );
386 386
 
387 387
         wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
388 388
         exit;
389 389
 
390
-	}
390
+    }
391 391
 
392 392
     /**
393 393
      * Fires an admin action after verifying that a user can fire them.
@@ -401,458 +401,458 @@  discard block
 block discarded – undo
401 401
 
402 402
     }
403 403
 
404
-	/**
404
+    /**
405 405
      * Sends a payment reminder to a customer.
406
-	 * 
407
-	 * @param array $args
406
+     * 
407
+     * @param array $args
408 408
      */
409 409
     public function send_customer_invoice( $args ) {
410
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
410
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
411 411
 
412
-		if ( $sent ) {
413
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
414
-		} else {
415
-			$this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
416
-		}
412
+        if ( $sent ) {
413
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
414
+        } else {
415
+            $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
416
+        }
417 417
 
418
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
419
-		exit;
420
-	}
418
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
419
+        exit;
420
+    }
421 421
 
422
-	/**
422
+    /**
423 423
      * Sends a payment reminder to a customer.
424
-	 * 
425
-	 * @param array $args
424
+     * 
425
+     * @param array $args
426 426
      */
427 427
     public function send_customer_payment_reminder( $args ) {
428
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
428
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
429 429
 
430
-		if ( $sent ) {
431
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
432
-		} else {
433
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
434
-		}
430
+        if ( $sent ) {
431
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
432
+        } else {
433
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
434
+        }
435 435
 
436
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
437
-		exit;
438
-	}
436
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
437
+        exit;
438
+    }
439 439
 
440
-	/**
440
+    /**
441 441
      * Resets tax rates.
442
-	 * 
442
+     * 
443 443
      */
444 444
     public function admin_reset_tax_rates() {
445 445
 
446
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
447
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
448
-		exit;
446
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
447
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
448
+        exit;
449 449
 
450
-	}
450
+    }
451 451
 
452
-	/**
452
+    /**
453 453
      * Resets admin pages.
454
-	 * 
454
+     * 
455 455
      */
456 456
     public function admin_create_missing_pages() {
457
-		$installer = new GetPaid_Installer();
458
-		$installer->create_pages();
459
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
460
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
461
-		exit;
462
-	}
463
-
464
-	/**
457
+        $installer = new GetPaid_Installer();
458
+        $installer->create_pages();
459
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
460
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
461
+        exit;
462
+    }
463
+
464
+    /**
465 465
      * Creates an missing admin tables.
466
-	 * 
466
+     * 
467 467
      */
468 468
     public function admin_create_missing_tables() {
469
-		global $wpdb;
470
-		$installer = new GetPaid_Installer();
469
+        global $wpdb;
470
+        $installer = new GetPaid_Installer();
471 471
 
472
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
473
-			$installer->create_subscriptions_table();
472
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
473
+            $installer->create_subscriptions_table();
474 474
 
475
-			if ( $wpdb->last_error !== '' ) {
476
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
477
-			}
478
-		}
475
+            if ( $wpdb->last_error !== '' ) {
476
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
477
+            }
478
+        }
479 479
 
480
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
481
-			$installer->create_invoices_table();
480
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
481
+            $installer->create_invoices_table();
482 482
 
483
-			if ( $wpdb->last_error !== '' ) {
484
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
485
-			}
486
-		}
483
+            if ( $wpdb->last_error !== '' ) {
484
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
485
+            }
486
+        }
487 487
 
488
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
489
-			$installer->create_invoice_items_table();
488
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
489
+            $installer->create_invoice_items_table();
490 490
 
491
-			if ( $wpdb->last_error !== '' ) {
492
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
493
-			}
494
-		}
491
+            if ( $wpdb->last_error !== '' ) {
492
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
493
+            }
494
+        }
495 495
 
496
-		if ( ! $this->has_notices() ) {
497
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
498
-		}
496
+        if ( ! $this->has_notices() ) {
497
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
498
+        }
499 499
 
500
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
501
-		exit;
502
-	}
500
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
501
+        exit;
502
+    }
503 503
 
504
-	/**
504
+    /**
505 505
      * Migrates old invoices to the new database tables.
506
-	 * 
506
+     * 
507 507
      */
508 508
     public function admin_migrate_old_invoices() {
509 509
 
510
-		// Migrate the invoices.
511
-		$installer = new GetPaid_Installer();
512
-		$installer->migrate_old_invoices();
510
+        // Migrate the invoices.
511
+        $installer = new GetPaid_Installer();
512
+        $installer->migrate_old_invoices();
513 513
 
514
-		// Show an admin message.
515
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
514
+        // Show an admin message.
515
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
516 516
 
517
-		// Redirect the admin.
518
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
519
-		exit;
517
+        // Redirect the admin.
518
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
519
+        exit;
520 520
 
521
-	}
521
+    }
522 522
 
523
-	/**
523
+    /**
524 524
      * Download customers.
525
-	 * 
525
+     * 
526 526
      */
527 527
     public function admin_download_customers() {
528
-		global $wpdb;
528
+        global $wpdb;
529 529
 
530
-		$output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
530
+        $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
531 531
 
532
-		header( "Content-Type:text/csv" );
533
-		header( "Content-Disposition:attachment;filename=customers.csv" );
532
+        header( "Content-Type:text/csv" );
533
+        header( "Content-Disposition:attachment;filename=customers.csv" );
534 534
 
535
-		$post_types = '';
535
+        $post_types = '';
536 536
 
537
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
538
-			$post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
539
-		}
537
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
538
+            $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
539
+        }
540 540
 
541
-		$post_types = rtrim( $post_types, ' OR' );
541
+        $post_types = rtrim( $post_types, ' OR' );
542 542
 
543
-		$customers = $wpdb->get_col(
544
-			$wpdb->prepare(
545
-				"SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"
546
-			)
547
-		);
543
+        $customers = $wpdb->get_col(
544
+            $wpdb->prepare(
545
+                "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"
546
+            )
547
+        );
548 548
 
549
-		$columns = array(
550
-			'name'     => __( 'Name', 'invoicing' ),
551
-			'email'    => __( 'Email', 'invoicing' ),
552
-			'country'  => __( 'Country', 'invoicing' ),
553
-			'state'    => __( 'State', 'invoicing' ),
554
-			'city'     => __( 'City', 'invoicing' ),
555
-			'zip'      => __( 'ZIP', 'invoicing' ),
556
-			'address'  => __( 'Address', 'invoicing' ),
557
-			'phone'    => __( 'Phone', 'invoicing' ),
558
-			'company'  => __( 'Company', 'invoicing' ),
559
-			'invoices' => __( 'Invoices', 'invoicing' ),
560
-			'total'    => __( 'Total Spend', 'invoicing' ),
561
-			'signup'   => __( 'Date created', 'invoicing' ),
562
-		);
549
+        $columns = array(
550
+            'name'     => __( 'Name', 'invoicing' ),
551
+            'email'    => __( 'Email', 'invoicing' ),
552
+            'country'  => __( 'Country', 'invoicing' ),
553
+            'state'    => __( 'State', 'invoicing' ),
554
+            'city'     => __( 'City', 'invoicing' ),
555
+            'zip'      => __( 'ZIP', 'invoicing' ),
556
+            'address'  => __( 'Address', 'invoicing' ),
557
+            'phone'    => __( 'Phone', 'invoicing' ),
558
+            'company'  => __( 'Company', 'invoicing' ),
559
+            'invoices' => __( 'Invoices', 'invoicing' ),
560
+            'total'    => __( 'Total Spend', 'invoicing' ),
561
+            'signup'   => __( 'Date created', 'invoicing' ),
562
+        );
563 563
 
564
-		// Output the csv column headers.
565
-		fputcsv( $output, array_values( $columns ) );
564
+        // Output the csv column headers.
565
+        fputcsv( $output, array_values( $columns ) );
566 566
 
567
-		// Loop through
568
-		$table = new WPInv_Customers_Table();
569
-		foreach ( $customers as $customer_id ) {
567
+        // Loop through
568
+        $table = new WPInv_Customers_Table();
569
+        foreach ( $customers as $customer_id ) {
570 570
 
571
-			$user = get_user_by( 'id', $customer_id );
572
-			$row  = array();
573
-			if ( empty( $user ) ) {
574
-				continue;
575
-			}
571
+            $user = get_user_by( 'id', $customer_id );
572
+            $row  = array();
573
+            if ( empty( $user ) ) {
574
+                continue;
575
+            }
576 576
 
577
-			foreach ( array_keys( $columns ) as $column ) {
577
+            foreach ( array_keys( $columns ) as $column ) {
578 578
 
579
-				$method = 'column_' . $column;
579
+                $method = 'column_' . $column;
580 580
 
581
-				if ( 'name' == $column ) {
582
-					$value = sanitize_text_field( $user->display_name );
583
-				} else if( 'email' == $column ) {
584
-					$value = sanitize_email( $user->user_email );
585
-				} else if ( is_callable( array( $table, $method ) ) ) {
586
-					$value = strip_tags( $table->$method( $user ) );
587
-				}
581
+                if ( 'name' == $column ) {
582
+                    $value = sanitize_text_field( $user->display_name );
583
+                } else if( 'email' == $column ) {
584
+                    $value = sanitize_email( $user->user_email );
585
+                } else if ( is_callable( array( $table, $method ) ) ) {
586
+                    $value = strip_tags( $table->$method( $user ) );
587
+                }
588 588
 
589
-				if ( empty( $value ) ) {
590
-					$value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
591
-				}
589
+                if ( empty( $value ) ) {
590
+                    $value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
591
+                }
592 592
 
593
-				$row[] = $value;
593
+                $row[] = $value;
594 594
 
595
-			}
595
+            }
596 596
 
597
-			fputcsv( $output, $row );
598
-		}
597
+            fputcsv( $output, $row );
598
+        }
599 599
 
600
-		fclose( $output );
601
-		exit;
600
+        fclose( $output );
601
+        exit;
602 602
 
603
-	}
603
+    }
604 604
 
605
-	/**
605
+    /**
606 606
      * Installs a plugin.
607
-	 *
608
-	 * @param array $data
607
+     *
608
+     * @param array $data
609 609
      */
610 610
     public function admin_install_plugin( $data ) {
611 611
 
612
-		if ( ! empty( $data['plugins'] ) ) {
613
-			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
614
-			wp_cache_flush();
612
+        if ( ! empty( $data['plugins'] ) ) {
613
+            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
614
+            wp_cache_flush();
615 615
 
616
-			foreach ( $data['plugins'] as $slug => $file ) {
617
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
618
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
619
-				$installed  = $upgrader->install( $plugin_zip );
616
+            foreach ( $data['plugins'] as $slug => $file ) {
617
+                $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
618
+                $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
619
+                $installed  = $upgrader->install( $plugin_zip );
620 620
 
621
-				if ( ! is_wp_error( $installed ) && $installed ) {
622
-					activate_plugin( $file, '', false, true );
623
-				} else {
624
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
625
-				}
621
+                if ( ! is_wp_error( $installed ) && $installed ) {
622
+                    activate_plugin( $file, '', false, true );
623
+                } else {
624
+                    wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
625
+                }
626 626
 
627
-			}
627
+            }
628 628
 
629
-		}
629
+        }
630 630
 
631
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
632
-		wp_safe_redirect( $redirect );
633
-		exit;
631
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
632
+        wp_safe_redirect( $redirect );
633
+        exit;
634 634
 
635
-	}
635
+    }
636 636
 
637
-	/**
637
+    /**
638 638
      * Connects a gateway.
639
-	 *
640
-	 * @param array $data
639
+     *
640
+     * @param array $data
641 641
      */
642 642
     public function admin_connect_gateway( $data ) {
643 643
 
644
-		if ( ! empty( $data['plugin'] ) ) {
644
+        if ( ! empty( $data['plugin'] ) ) {
645 645
 
646
-			$gateway     = sanitize_key( $data['plugin'] );
647
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
646
+            $gateway     = sanitize_key( $data['plugin'] );
647
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
648 648
 
649
-			if ( ! empty( $connect_url ) ) {
650
-				wp_redirect( $connect_url );
651
-				exit;
652
-			}
649
+            if ( ! empty( $connect_url ) ) {
650
+                wp_redirect( $connect_url );
651
+                exit;
652
+            }
653 653
 
654
-			if ( 'stripe' == $data['plugin'] ) {
655
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
654
+            if ( 'stripe' == $data['plugin'] ) {
655
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
656 656
 
657
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
658
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
659
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
660
-					$upgrader->install( $plugin_zip );
661
-				}
657
+                if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
658
+                    $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
659
+                    $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
660
+                    $upgrader->install( $plugin_zip );
661
+                }
662 662
 
663
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
664
-			}
663
+                activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
664
+            }
665 665
 
666
-			if ( ! empty( $connect_url ) ) {
667
-				wp_redirect( $connect_url );
668
-				exit;
669
-			}
666
+            if ( ! empty( $connect_url ) ) {
667
+                wp_redirect( $connect_url );
668
+                exit;
669
+            }
670 670
 
671
-		}
671
+        }
672 672
 
673
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
674
-		wp_safe_redirect( $redirect );
675
-		exit;
673
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
674
+        wp_safe_redirect( $redirect );
675
+        exit;
676 676
 
677
-	}
677
+    }
678 678
 
679
-	/**
679
+    /**
680 680
      * Recalculates discounts.
681
-	 * 
681
+     * 
682 682
      */
683 683
     public function admin_recalculate_discounts() {
684
-		global $wpdb;
684
+        global $wpdb;
685 685
 
686
-		// Fetch all invoices that have discount codes.
687
-		$table    = $wpdb->prefix . 'getpaid_invoices';
688
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
686
+        // Fetch all invoices that have discount codes.
687
+        $table    = $wpdb->prefix . 'getpaid_invoices';
688
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
689 689
 
690
-		foreach ( $invoices as $invoice ) {
690
+        foreach ( $invoices as $invoice ) {
691 691
 
692
-			$invoice = new WPInv_Invoice( $invoice );
692
+            $invoice = new WPInv_Invoice( $invoice );
693 693
 
694
-			if ( ! $invoice->exists() ) {
695
-				continue;
696
-			}
694
+            if ( ! $invoice->exists() ) {
695
+                continue;
696
+            }
697 697
 
698
-			// Abort if the discount does not exist or does not apply here.
699
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
700
-			if ( ! $discount->exists() ) {
701
-				continue;
702
-			}
698
+            // Abort if the discount does not exist or does not apply here.
699
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
700
+            if ( ! $discount->exists() ) {
701
+                continue;
702
+            }
703 703
 
704
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
705
-			$invoice->recalculate_total();
704
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
705
+            $invoice->recalculate_total();
706 706
 
707
-			if ( $invoice->get_total_discount() > 0 ) {
708
-				$invoice->save();
709
-			}
707
+            if ( $invoice->get_total_discount() > 0 ) {
708
+                $invoice->save();
709
+            }
710 710
 
711
-		}
711
+        }
712 712
 
713
-		// Show an admin message.
714
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
713
+        // Show an admin message.
714
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
715 715
 
716
-		// Redirect the admin.
717
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
718
-		exit;
716
+        // Redirect the admin.
717
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
718
+        exit;
719 719
 
720
-	}
720
+    }
721 721
 
722 722
     /**
723
-	 * Returns an array of admin notices.
724
-	 *
725
-	 * @since       1.0.19
723
+     * Returns an array of admin notices.
724
+     *
725
+     * @since       1.0.19
726 726
      * @return array
727
-	 */
728
-	public function get_notices() {
729
-		$notices = get_option( 'wpinv_admin_notices' );
727
+     */
728
+    public function get_notices() {
729
+        $notices = get_option( 'wpinv_admin_notices' );
730 730
         return is_array( $notices ) ? $notices : array();
731
-	}
731
+    }
732 732
 
733
-	/**
734
-	 * Checks if we have any admin notices.
735
-	 *
736
-	 * @since       2.0.4
733
+    /**
734
+     * Checks if we have any admin notices.
735
+     *
736
+     * @since       2.0.4
737 737
      * @return array
738
-	 */
739
-	public function has_notices() {
740
-		return count( $this->get_notices() ) > 0;
741
-	}
742
-
743
-	/**
744
-	 * Clears all admin notices
745
-	 *
746
-	 * @access      public
747
-	 * @since       1.0.19
748
-	 */
749
-	public function clear_notices() {
750
-		delete_option( 'wpinv_admin_notices' );
751
-	}
752
-
753
-	/**
754
-	 * Saves a new admin notice
755
-	 *
756
-	 * @access      public
757
-	 * @since       1.0.19
758
-	 */
759
-	public function save_notice( $type, $message ) {
760
-		$notices = $this->get_notices();
761
-
762
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
763
-			$notices[ $type ] = array();
764
-		}
765
-
766
-		$notices[ $type ][] = $message;
767
-
768
-		update_option( 'wpinv_admin_notices', $notices );
769
-	}
770
-
771
-	/**
772
-	 * Displays a success notice
773
-	 *
774
-	 * @param       string $msg The message to qeue.
775
-	 * @access      public
776
-	 * @since       1.0.19
777
-	 */
778
-	public function show_success( $msg ) {
779
-		$this->save_notice( 'success', $msg );
780
-	}
781
-
782
-	/**
783
-	 * Displays a error notice
784
-	 *
785
-	 * @access      public
786
-	 * @param       string $msg The message to qeue.
787
-	 * @since       1.0.19
788
-	 */
789
-	public function show_error( $msg ) {
790
-		$this->save_notice( 'error', $msg );
791
-	}
792
-
793
-	/**
794
-	 * Displays a warning notice
795
-	 *
796
-	 * @access      public
797
-	 * @param       string $msg The message to qeue.
798
-	 * @since       1.0.19
799
-	 */
800
-	public function show_warning( $msg ) {
801
-		$this->save_notice( 'warning', $msg );
802
-	}
803
-
804
-	/**
805
-	 * Displays a info notice
806
-	 *
807
-	 * @access      public
808
-	 * @param       string $msg The message to qeue.
809
-	 * @since       1.0.19
810
-	 */
811
-	public function show_info( $msg ) {
812
-		$this->save_notice( 'info', $msg );
813
-	}
814
-
815
-	/**
816
-	 * Show notices
817
-	 *
818
-	 * @access      public
819
-	 * @since       1.0.19
820
-	 */
821
-	public function show_notices() {
738
+     */
739
+    public function has_notices() {
740
+        return count( $this->get_notices() ) > 0;
741
+    }
742
+
743
+    /**
744
+     * Clears all admin notices
745
+     *
746
+     * @access      public
747
+     * @since       1.0.19
748
+     */
749
+    public function clear_notices() {
750
+        delete_option( 'wpinv_admin_notices' );
751
+    }
752
+
753
+    /**
754
+     * Saves a new admin notice
755
+     *
756
+     * @access      public
757
+     * @since       1.0.19
758
+     */
759
+    public function save_notice( $type, $message ) {
760
+        $notices = $this->get_notices();
761
+
762
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
763
+            $notices[ $type ] = array();
764
+        }
765
+
766
+        $notices[ $type ][] = $message;
767
+
768
+        update_option( 'wpinv_admin_notices', $notices );
769
+    }
770
+
771
+    /**
772
+     * Displays a success notice
773
+     *
774
+     * @param       string $msg The message to qeue.
775
+     * @access      public
776
+     * @since       1.0.19
777
+     */
778
+    public function show_success( $msg ) {
779
+        $this->save_notice( 'success', $msg );
780
+    }
781
+
782
+    /**
783
+     * Displays a error notice
784
+     *
785
+     * @access      public
786
+     * @param       string $msg The message to qeue.
787
+     * @since       1.0.19
788
+     */
789
+    public function show_error( $msg ) {
790
+        $this->save_notice( 'error', $msg );
791
+    }
792
+
793
+    /**
794
+     * Displays a warning notice
795
+     *
796
+     * @access      public
797
+     * @param       string $msg The message to qeue.
798
+     * @since       1.0.19
799
+     */
800
+    public function show_warning( $msg ) {
801
+        $this->save_notice( 'warning', $msg );
802
+    }
803
+
804
+    /**
805
+     * Displays a info notice
806
+     *
807
+     * @access      public
808
+     * @param       string $msg The message to qeue.
809
+     * @since       1.0.19
810
+     */
811
+    public function show_info( $msg ) {
812
+        $this->save_notice( 'info', $msg );
813
+    }
814
+
815
+    /**
816
+     * Show notices
817
+     *
818
+     * @access      public
819
+     * @since       1.0.19
820
+     */
821
+    public function show_notices() {
822 822
 
823 823
         $notices = $this->get_notices();
824 824
         $this->clear_notices();
825 825
 
826
-		foreach ( $notices as $type => $messages ) {
826
+        foreach ( $notices as $type => $messages ) {
827 827
 
828
-			if ( ! is_array( $messages ) ) {
829
-				continue;
830
-			}
828
+            if ( ! is_array( $messages ) ) {
829
+                continue;
830
+            }
831 831
 
832 832
             $type  = sanitize_key( $type );
833
-			foreach ( $messages as $message ) {
833
+            foreach ( $messages as $message ) {
834 834
                 $message = wp_kses_post( $message );
835
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
835
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
836 836
             }
837 837
 
838 838
         }
839 839
 
840
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
841
-
842
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
843
-				$url     = wp_nonce_url(
844
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
845
-					'getpaid-nonce',
846
-					'getpaid-nonce'
847
-				);
848
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
849
-				$message2 = __( 'Generate Pages', 'invoicing' );
850
-				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
851
-				break;
852
-			}
840
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
841
+
842
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
843
+                $url     = wp_nonce_url(
844
+                    add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
845
+                    'getpaid-nonce',
846
+                    'getpaid-nonce'
847
+                );
848
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
849
+                $message2 = __( 'Generate Pages', 'invoicing' );
850
+                echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
851
+                break;
852
+            }
853 853
 
854
-		}
854
+        }
855 855
 
856
-	}
856
+    }
857 857
 
858 858
 }
Please login to merge, or discard this patch.