Passed
Push — master ( 65bd19...9109d4 )
by Brian
04:59
created
includes/wpinv-payment-functions.php 2 patches
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -1,196 +1,196 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 function wpinv_is_subscription_payment( $invoice = '' ) {
3
-	if ( empty( $invoice ) ) {
4
-		return false;
5
-	}
3
+    if ( empty( $invoice ) ) {
4
+        return false;
5
+    }
6 6
 
7
-	if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
8
-		$invoice = wpinv_get_invoice( $invoice );
9
-	}
7
+    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
8
+        $invoice = wpinv_get_invoice( $invoice );
9
+    }
10 10
 
11
-	if ( empty( $invoice ) ) {
12
-		return false;
13
-	}
11
+    if ( empty( $invoice ) ) {
12
+        return false;
13
+    }
14 14
 
15
-	if ( $invoice->is_renewal() ) {
16
-		return true;
17
-	}
15
+    if ( $invoice->is_renewal() ) {
16
+        return true;
17
+    }
18 18
 
19
-	return false;
19
+    return false;
20 20
 }
21 21
 
22 22
 function wpinv_payment_link_transaction_id( $invoice = '' ) {
23
-	if ( empty( $invoice ) ) {
24
-		return false;
25
-	}
23
+    if ( empty( $invoice ) ) {
24
+        return false;
25
+    }
26 26
 
27
-	if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
28
-		$invoice = wpinv_get_invoice( $invoice );
29
-	}
27
+    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
28
+        $invoice = wpinv_get_invoice( $invoice );
29
+    }
30 30
 
31
-	if ( empty( $invoice ) ) {
32
-		return false;
33
-	}
31
+    if ( empty( $invoice ) ) {
32
+        return false;
33
+    }
34 34
 
35
-	return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
35
+    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
36 36
 }
37 37
 
38 38
 function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
39
-	$interval   = (int)$interval > 0 ? (int)$interval : 1;
40
-
41
-	if ( $trial_interval > 0 && ! empty( $trial_period ) ) {
42
-		$amount = __( 'Free', 'invoicing' );
43
-		$interval = $trial_interval;
44
-		$period = $trial_period;
45
-	}
46
-
47
-	$description = '';
48
-	switch ( $period ) {
49
-		case 'D':
50
-		case 'day':
51
-			$description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval );
52
-			break;
53
-		case 'W':
54
-		case 'week':
55
-			$description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval );
56
-			break;
57
-		case 'M':
58
-		case 'month':
59
-			$description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval );
60
-			break;
61
-		case 'Y':
62
-		case 'year':
63
-			$description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval );
64
-			break;
65
-	}
66
-
67
-	return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval );
39
+    $interval   = (int)$interval > 0 ? (int)$interval : 1;
40
+
41
+    if ( $trial_interval > 0 && ! empty( $trial_period ) ) {
42
+        $amount = __( 'Free', 'invoicing' );
43
+        $interval = $trial_interval;
44
+        $period = $trial_period;
45
+    }
46
+
47
+    $description = '';
48
+    switch ( $period ) {
49
+        case 'D':
50
+        case 'day':
51
+            $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval );
52
+            break;
53
+        case 'W':
54
+        case 'week':
55
+            $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval );
56
+            break;
57
+        case 'M':
58
+        case 'month':
59
+            $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval );
60
+            break;
61
+        case 'Y':
62
+        case 'year':
63
+            $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval );
64
+            break;
65
+    }
66
+
67
+    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval );
68 68
 }
69 69
 
70 70
 function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
71
-	$interval   = (int)$interval > 0 ? (int)$interval : 1;
72
-	$bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
73
-
74
-	$description = '';
75
-	switch ( $period ) {
76
-		case 'D':
77
-		case 'day':
78
-			if ( (int)$bill_times > 0 ) {
79
-				if ( $interval > 1 ) {
80
-					if ( $bill_times > 1 ) {
81
-						$description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
82
-					} else {
83
-						$description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval );
84
-					}
85
-				} else {
86
-					$description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
87
-				}
88
-			} else {
89
-				$description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval );
90
-			}
91
-			break;
92
-		case 'W':
93
-		case 'week':
94
-			if ( (int)$bill_times > 0 ) {
95
-				if ( $interval > 1 ) {
96
-					if ( $bill_times > 1 ) {
97
-						$description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
98
-					} else {
99
-						$description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval );
100
-					}
101
-				} else {
102
-					$description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
103
-				}
104
-			} else {
105
-				$description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval );
106
-			}
107
-			break;
108
-		case 'M':
109
-		case 'month':
110
-			if ( (int)$bill_times > 0 ) {
111
-				if ( $interval > 1 ) {
112
-					if ( $bill_times > 1 ) {
113
-						$description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
114
-					} else {
115
-						$description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval );
116
-					}
117
-				} else {
118
-					$description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
119
-				}
120
-			} else {
121
-				$description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval );
122
-			}
123
-			break;
124
-		case 'Y':
125
-		case 'year':
126
-			if ( (int)$bill_times > 0 ) {
127
-				if ( $interval > 1 ) {
128
-					if ( $bill_times > 1 ) {
129
-						$description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
130
-					} else {
131
-						$description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval );
132
-					}
133
-				} else {
134
-					$description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
135
-				}
136
-			} else {
137
-				$description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval );
138
-			}
139
-			break;
140
-	}
141
-
142
-	return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
71
+    $interval   = (int)$interval > 0 ? (int)$interval : 1;
72
+    $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
73
+
74
+    $description = '';
75
+    switch ( $period ) {
76
+        case 'D':
77
+        case 'day':
78
+            if ( (int)$bill_times > 0 ) {
79
+                if ( $interval > 1 ) {
80
+                    if ( $bill_times > 1 ) {
81
+                        $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
82
+                    } else {
83
+                        $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval );
84
+                    }
85
+                } else {
86
+                    $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
87
+                }
88
+            } else {
89
+                $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval );
90
+            }
91
+            break;
92
+        case 'W':
93
+        case 'week':
94
+            if ( (int)$bill_times > 0 ) {
95
+                if ( $interval > 1 ) {
96
+                    if ( $bill_times > 1 ) {
97
+                        $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
98
+                    } else {
99
+                        $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval );
100
+                    }
101
+                } else {
102
+                    $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
103
+                }
104
+            } else {
105
+                $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval );
106
+            }
107
+            break;
108
+        case 'M':
109
+        case 'month':
110
+            if ( (int)$bill_times > 0 ) {
111
+                if ( $interval > 1 ) {
112
+                    if ( $bill_times > 1 ) {
113
+                        $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
114
+                    } else {
115
+                        $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval );
116
+                    }
117
+                } else {
118
+                    $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
119
+                }
120
+            } else {
121
+                $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval );
122
+            }
123
+            break;
124
+        case 'Y':
125
+        case 'year':
126
+            if ( (int)$bill_times > 0 ) {
127
+                if ( $interval > 1 ) {
128
+                    if ( $bill_times > 1 ) {
129
+                        $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
130
+                    } else {
131
+                        $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval );
132
+                    }
133
+                } else {
134
+                    $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
135
+                }
136
+            } else {
137
+                $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval );
138
+            }
139
+            break;
140
+    }
141
+
142
+    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
143 143
 }
144 144
 
145 145
 function wpinv_subscription_payment_desc( $invoice ) {
146
-	if ( empty( $invoice ) ) {
147
-		return null;
148
-	}
149
-
150
-	$description = '';
151
-	if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
-		if ( $item->has_free_trial() ) {
153
-			$trial_period = $item->get_trial_period();
154
-			$trial_interval = $item->get_trial_interval();
155
-		} else {
156
-			$trial_period = '';
157
-			$trial_interval = 0;
158
-		}
159
-
160
-		$description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
161
-	}
162
-
163
-	return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
146
+    if ( empty( $invoice ) ) {
147
+        return null;
148
+    }
149
+
150
+    $description = '';
151
+    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
+        if ( $item->has_free_trial() ) {
153
+            $trial_period = $item->get_trial_period();
154
+            $trial_interval = $item->get_trial_interval();
155
+        } else {
156
+            $trial_period = '';
157
+            $trial_interval = 0;
158
+        }
159
+
160
+        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
161
+    }
162
+
163
+    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
164 164
 }
165 165
 
166 166
 function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
167
-	$initial_total      = wpinv_round_amount( $initial );
168
-	$recurring_total    = wpinv_round_amount( $recurring );
167
+    $initial_total      = wpinv_round_amount( $initial );
168
+    $recurring_total    = wpinv_round_amount( $recurring );
169 169
 
170
-	if ( $trial_interval > 0 && ! empty( $trial_period ) ) {
171
-		// Free trial
172
-	} else {
173
-		if ( $bill_times == 1 ) {
174
-			$recurring_total = $initial_total;
175
-		} elseif ( $bill_times > 1 && $initial_total != $recurring_total ) {
176
-			$bill_times--;
177
-		}
178
-	}
170
+    if ( $trial_interval > 0 && ! empty( $trial_period ) ) {
171
+        // Free trial
172
+    } else {
173
+        if ( $bill_times == 1 ) {
174
+            $recurring_total = $initial_total;
175
+        } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) {
176
+            $bill_times--;
177
+        }
178
+    }
179 179
 
180
-	$initial_amount     = wpinv_price( $initial_total, $currency );
181
-	$recurring_amount   = wpinv_price( $recurring_total, $currency );
180
+    $initial_amount     = wpinv_price( $initial_total, $currency );
181
+    $recurring_amount   = wpinv_price( $recurring_total, $currency );
182 182
 
183
-	$recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
183
+    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
184 184
 
185
-	if ( $initial_total != $recurring_total ) {
186
-		$initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
185
+    if ( $initial_total != $recurring_total ) {
186
+        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
187 187
 
188
-		$description    = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring );
189
-	} else {
190
-		$description    = $recurring;
191
-	}
188
+        $description    = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring );
189
+    } else {
190
+        $description    = $recurring;
191
+    }
192 192
 
193
-	return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
193
+    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
194 194
 }
195 195
 
196 196
 /**
@@ -202,25 +202,25 @@  discard block
 block discarded – undo
202 202
  */
203 203
 function getpaid_get_card_name( $card_number ) {
204 204
 
205
-	// Known regexes.
206
-	$regexes = array(
207
-		'/^4/'                     => __( 'Visa', 'invoicing' ),
208
-		'/^5[1-5]/'                => __( 'Mastercard', 'invoicing' ),
209
-		'/^3[47]/'                 => __( 'Amex', 'invoicing' ),
210
-		'/^3(?:0[0-5]|[68])/'      => __( 'Diners Club', 'invoicing' ),
211
-		'/^6(?:011|5)/'            => __( 'Discover', 'invoicing' ),
212
-		'/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ),
213
-	);
214
-
215
-	// Confirm if one matches.
216
-	foreach ( $regexes as $regex => $card ) {
217
-		if ( preg_match( $regex, $card_number ) >= 1 ) {
218
-			return $card;
219
-		}
220
-	}
221
-
222
-	// None matched.
223
-	return __( 'Card', 'invoicing' );
205
+    // Known regexes.
206
+    $regexes = array(
207
+        '/^4/'                     => __( 'Visa', 'invoicing' ),
208
+        '/^5[1-5]/'                => __( 'Mastercard', 'invoicing' ),
209
+        '/^3[47]/'                 => __( 'Amex', 'invoicing' ),
210
+        '/^3(?:0[0-5]|[68])/'      => __( 'Diners Club', 'invoicing' ),
211
+        '/^6(?:011|5)/'            => __( 'Discover', 'invoicing' ),
212
+        '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ),
213
+    );
214
+
215
+    // Confirm if one matches.
216
+    foreach ( $regexes as $regex => $card ) {
217
+        if ( preg_match( $regex, $card_number ) >= 1 ) {
218
+            return $card;
219
+        }
220
+    }
221
+
222
+    // None matched.
223
+    return __( 'Card', 'invoicing' );
224 224
 
225 225
 }
226 226
 
@@ -230,24 +230,24 @@  discard block
 block discarded – undo
230 230
  * @param WPInv_Invoice|int|null $invoice
231 231
  */
232 232
 function wpinv_send_back_to_checkout( $invoice = null ) {
233
-	$response = array( 'success' => false );
234
-	$invoice  = wpinv_get_invoice( $invoice );
235
-
236
-	// Was an invoice created?
237
-	if ( ! empty( $invoice ) ) {
238
-		$invoice             = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice;
239
-		$response['invoice'] = $invoice->get_id();
240
-		do_action( 'getpaid_checkout_invoice_exception', $invoice );
241
-	}
242
-
243
-	// Do we have any errors?
244
-	if ( wpinv_get_errors() ) {
245
-		$response['data'] = getpaid_get_errors_html( true, false );
246
-	} else {
247
-		$response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' );
248
-	}
249
-
250
-	wp_send_json( $response );
233
+    $response = array( 'success' => false );
234
+    $invoice  = wpinv_get_invoice( $invoice );
235
+
236
+    // Was an invoice created?
237
+    if ( ! empty( $invoice ) ) {
238
+        $invoice             = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice;
239
+        $response['invoice'] = $invoice->get_id();
240
+        do_action( 'getpaid_checkout_invoice_exception', $invoice );
241
+    }
242
+
243
+    // Do we have any errors?
244
+    if ( wpinv_get_errors() ) {
245
+        $response['data'] = getpaid_get_errors_html( true, false );
246
+    } else {
247
+        $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' );
248
+    }
249
+
250
+    wp_send_json( $response );
251 251
 }
252 252
 
253 253
 /**
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
  * @return string
257 257
  */
258 258
 function getpaid_get_recaptcha_site_key() {
259
-	return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) );
259
+    return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) );
260 260
 }
261 261
 
262 262
 /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
  * @return string
266 266
  */
267 267
 function getpaid_get_recaptcha_secret_key() {
268
-	return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) );
268
+    return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) );
269 269
 }
270 270
 
271 271
 /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
  * @return bool
275 275
  */
276 276
 function getpaid_is_recaptcha_enabled() {
277
-	return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key();
277
+    return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key();
278 278
 }
279 279
 
280 280
 /**
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
  * @return string
284 284
  */
285 285
 function getpaid_get_recaptcha_version() {
286
-	return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) );
286
+    return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) );
287 287
 }
288 288
 
289 289
 /**
@@ -292,41 +292,41 @@  discard block
 block discarded – undo
292 292
  * @return array
293 293
  */
294 294
 function getpaid_get_recaptcha_settings() {
295
-	$settings = array(
296
-		'enabled' => getpaid_is_recaptcha_enabled(),
297
-		'version' => getpaid_get_recaptcha_version(),
298
-	);
299
-
300
-	if ( ! getpaid_is_recaptcha_enabled() ) {
301
-		return $settings;
302
-	}
303
-
304
-	$settings['sitekey'] = getpaid_get_recaptcha_site_key();
305
-
306
-	// Version 2 render params.
307
-	if ( 'v2' === getpaid_get_recaptcha_version() ) {
308
-		$settings['render_params'] = array(
309
-			'sitekey'  => getpaid_get_recaptcha_site_key(),
310
-			'theme'    => 'light',
311
-			'size'     => 'normal',
312
-			'tabindex' => 0,
313
-		);
314
-	}
315
-
316
-	return apply_filters( 'getpaid_recaptcha_settings', $settings );
295
+    $settings = array(
296
+        'enabled' => getpaid_is_recaptcha_enabled(),
297
+        'version' => getpaid_get_recaptcha_version(),
298
+    );
299
+
300
+    if ( ! getpaid_is_recaptcha_enabled() ) {
301
+        return $settings;
302
+    }
303
+
304
+    $settings['sitekey'] = getpaid_get_recaptcha_site_key();
305
+
306
+    // Version 2 render params.
307
+    if ( 'v2' === getpaid_get_recaptcha_version() ) {
308
+        $settings['render_params'] = array(
309
+            'sitekey'  => getpaid_get_recaptcha_site_key(),
310
+            'theme'    => 'light',
311
+            'size'     => 'normal',
312
+            'tabindex' => 0,
313
+        );
314
+    }
315
+
316
+    return apply_filters( 'getpaid_recaptcha_settings', $settings );
317 317
 }
318 318
 
319 319
 /**
320 320
  * Displays reCAPTCHA before payment button.
321 321
  */
322 322
 function getpaid_display_recaptcha_before_payment_button() {
323
-	if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) {
324
-		return;
325
-	}
326
-
327
-	printf(
328
-		'<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha" id="getpaid-recaptcha-%s"></div></div>',
329
-		esc_attr( wp_unique_id() )
330
-	);
323
+    if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) {
324
+        return;
325
+    }
326
+
327
+    printf(
328
+        '<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha" id="getpaid-recaptcha-%s"></div></div>',
329
+        esc_attr( wp_unique_id() )
330
+    );
331 331
 }
332 332
 add_action( 'getpaid_before_payment_form_pay_button', 'getpaid_display_recaptcha_before_payment_button' );
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -1,155 +1,155 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_is_subscription_payment( $invoice = '' ) {
3
-	if ( empty( $invoice ) ) {
2
+function wpinv_is_subscription_payment($invoice = '') {
3
+	if (empty($invoice)) {
4 4
 		return false;
5 5
 	}
6 6
 
7
-	if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
8
-		$invoice = wpinv_get_invoice( $invoice );
7
+	if (!is_object($invoice) && is_scalar($invoice)) {
8
+		$invoice = wpinv_get_invoice($invoice);
9 9
 	}
10 10
 
11
-	if ( empty( $invoice ) ) {
11
+	if (empty($invoice)) {
12 12
 		return false;
13 13
 	}
14 14
 
15
-	if ( $invoice->is_renewal() ) {
15
+	if ($invoice->is_renewal()) {
16 16
 		return true;
17 17
 	}
18 18
 
19 19
 	return false;
20 20
 }
21 21
 
22
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
23
-	if ( empty( $invoice ) ) {
22
+function wpinv_payment_link_transaction_id($invoice = '') {
23
+	if (empty($invoice)) {
24 24
 		return false;
25 25
 	}
26 26
 
27
-	if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
28
-		$invoice = wpinv_get_invoice( $invoice );
27
+	if (!is_object($invoice) && is_scalar($invoice)) {
28
+		$invoice = wpinv_get_invoice($invoice);
29 29
 	}
30 30
 
31
-	if ( empty( $invoice ) ) {
31
+	if (empty($invoice)) {
32 32
 		return false;
33 33
 	}
34 34
 
35
-	return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
35
+	return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
36 36
 }
37 37
 
38
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
39
-	$interval   = (int)$interval > 0 ? (int)$interval : 1;
38
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
39
+	$interval = (int) $interval > 0 ? (int) $interval : 1;
40 40
 
41
-	if ( $trial_interval > 0 && ! empty( $trial_period ) ) {
42
-		$amount = __( 'Free', 'invoicing' );
41
+	if ($trial_interval > 0 && !empty($trial_period)) {
42
+		$amount = __('Free', 'invoicing');
43 43
 		$interval = $trial_interval;
44 44
 		$period = $trial_period;
45 45
 	}
46 46
 
47 47
 	$description = '';
48
-	switch ( $period ) {
48
+	switch ($period) {
49 49
 		case 'D':
50 50
 		case 'day':
51
-			$description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval );
51
+			$description = wp_sprintf(_n('%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing'), $amount, $interval);
52 52
 			break;
53 53
 		case 'W':
54 54
 		case 'week':
55
-			$description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval );
55
+			$description = wp_sprintf(_n('%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing'), $amount, $interval);
56 56
 			break;
57 57
 		case 'M':
58 58
 		case 'month':
59
-			$description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval );
59
+			$description = wp_sprintf(_n('%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing'), $amount, $interval);
60 60
 			break;
61 61
 		case 'Y':
62 62
 		case 'year':
63
-			$description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval );
63
+			$description = wp_sprintf(_n('%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing'), $amount, $interval);
64 64
 			break;
65 65
 	}
66 66
 
67
-	return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval );
67
+	return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
68 68
 }
69 69
 
70
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
71
-	$interval   = (int)$interval > 0 ? (int)$interval : 1;
72
-	$bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
70
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
71
+	$interval   = (int) $interval > 0 ? (int) $interval : 1;
72
+	$bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0;
73 73
 
74 74
 	$description = '';
75
-	switch ( $period ) {
75
+	switch ($period) {
76 76
 		case 'D':
77 77
 		case 'day':
78
-			if ( (int)$bill_times > 0 ) {
79
-				if ( $interval > 1 ) {
80
-					if ( $bill_times > 1 ) {
81
-						$description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
78
+			if ((int) $bill_times > 0) {
79
+				if ($interval > 1) {
80
+					if ($bill_times > 1) {
81
+						$description = wp_sprintf(__('%1$s for each %2$d days, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times);
82 82
 					} else {
83
-						$description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval );
83
+						$description = wp_sprintf(__('%1$s for %2$d days.', 'invoicing'), $amount, $interval);
84 84
 					}
85 85
 				} else {
86
-					$description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
86
+					$description = wp_sprintf(_n('%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
87 87
 				}
88 88
 			} else {
89
-				$description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval );
89
+				$description = wp_sprintf(_n('%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing'), $amount, $interval);
90 90
 			}
91 91
 			break;
92 92
 		case 'W':
93 93
 		case 'week':
94
-			if ( (int)$bill_times > 0 ) {
95
-				if ( $interval > 1 ) {
96
-					if ( $bill_times > 1 ) {
97
-						$description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
94
+			if ((int) $bill_times > 0) {
95
+				if ($interval > 1) {
96
+					if ($bill_times > 1) {
97
+						$description = wp_sprintf(__('%1$s for each %2$d weeks, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times);
98 98
 					} else {
99
-						$description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval );
99
+						$description = wp_sprintf(__('%1$s for %2$d weeks.', 'invoicing'), $amount, $interval);
100 100
 					}
101 101
 				} else {
102
-					$description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
102
+					$description = wp_sprintf(_n('%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
103 103
 				}
104 104
 			} else {
105
-				$description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval );
105
+				$description = wp_sprintf(_n('%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing'), $amount, $interval);
106 106
 			}
107 107
 			break;
108 108
 		case 'M':
109 109
 		case 'month':
110
-			if ( (int)$bill_times > 0 ) {
111
-				if ( $interval > 1 ) {
112
-					if ( $bill_times > 1 ) {
113
-						$description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
110
+			if ((int) $bill_times > 0) {
111
+				if ($interval > 1) {
112
+					if ($bill_times > 1) {
113
+						$description = wp_sprintf(__('%1$s for each %2$d months, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times);
114 114
 					} else {
115
-						$description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval );
115
+						$description = wp_sprintf(__('%1$s for %2$d months.', 'invoicing'), $amount, $interval);
116 116
 					}
117 117
 				} else {
118
-					$description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
118
+					$description = wp_sprintf(_n('%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
119 119
 				}
120 120
 			} else {
121
-				$description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval );
121
+				$description = wp_sprintf(_n('%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing'), $amount, $interval);
122 122
 			}
123 123
 			break;
124 124
 		case 'Y':
125 125
 		case 'year':
126
-			if ( (int)$bill_times > 0 ) {
127
-				if ( $interval > 1 ) {
128
-					if ( $bill_times > 1 ) {
129
-						$description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times );
126
+			if ((int) $bill_times > 0) {
127
+				if ($interval > 1) {
128
+					if ($bill_times > 1) {
129
+						$description = wp_sprintf(__('%1$s for each %2$d years, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times);
130 130
 					} else {
131
-						$description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval );
131
+						$description = wp_sprintf(__('%1$s for %2$d years.', 'invoicing'), $amount, $interval);
132 132
 					}
133 133
 				} else {
134
-					$description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
134
+					$description = wp_sprintf(_n('%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
135 135
 				}
136 136
 			} else {
137
-				$description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval );
137
+				$description = wp_sprintf(_n('%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing'), $amount, $interval);
138 138
 			}
139 139
 			break;
140 140
 	}
141 141
 
142
-	return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
142
+	return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
143 143
 }
144 144
 
145
-function wpinv_subscription_payment_desc( $invoice ) {
146
-	if ( empty( $invoice ) ) {
145
+function wpinv_subscription_payment_desc($invoice) {
146
+	if (empty($invoice)) {
147 147
 		return null;
148 148
 	}
149 149
 
150 150
 	$description = '';
151
-	if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
-		if ( $item->has_free_trial() ) {
151
+	if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
152
+		if ($item->has_free_trial()) {
153 153
 			$trial_period = $item->get_trial_period();
154 154
 			$trial_interval = $item->get_trial_interval();
155 155
 		} else {
@@ -157,40 +157,40 @@  discard block
 block discarded – undo
157 157
 			$trial_interval = 0;
158 158
 		}
159 159
 
160
-		$description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
160
+		$description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
161 161
 	}
162 162
 
163
-	return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
163
+	return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
164 164
 }
165 165
 
166
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
167
-	$initial_total      = wpinv_round_amount( $initial );
168
-	$recurring_total    = wpinv_round_amount( $recurring );
166
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
167
+	$initial_total      = wpinv_round_amount($initial);
168
+	$recurring_total    = wpinv_round_amount($recurring);
169 169
 
170
-	if ( $trial_interval > 0 && ! empty( $trial_period ) ) {
170
+	if ($trial_interval > 0 && !empty($trial_period)) {
171 171
 		// Free trial
172 172
 	} else {
173
-		if ( $bill_times == 1 ) {
173
+		if ($bill_times == 1) {
174 174
 			$recurring_total = $initial_total;
175
-		} elseif ( $bill_times > 1 && $initial_total != $recurring_total ) {
175
+		} elseif ($bill_times > 1 && $initial_total != $recurring_total) {
176 176
 			$bill_times--;
177 177
 		}
178 178
 	}
179 179
 
180
-	$initial_amount     = wpinv_price( $initial_total, $currency );
181
-	$recurring_amount   = wpinv_price( $recurring_total, $currency );
180
+	$initial_amount     = wpinv_price($initial_total, $currency);
181
+	$recurring_amount   = wpinv_price($recurring_total, $currency);
182 182
 
183
-	$recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
183
+	$recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
184 184
 
185
-	if ( $initial_total != $recurring_total ) {
186
-		$initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
185
+	if ($initial_total != $recurring_total) {
186
+		$initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
187 187
 
188
-		$description    = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring );
188
+		$description    = wp_sprintf(__('%1$s Then %2$s', 'invoicing'), $initial, $recurring);
189 189
 	} else {
190 190
 		$description    = $recurring;
191 191
 	}
192 192
 
193
-	return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
193
+	return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
194 194
 }
195 195
 
196 196
 /**
@@ -200,27 +200,27 @@  discard block
 block discarded – undo
200 200
  * @param string $card_number Card number.
201 201
  * @return string
202 202
  */
203
-function getpaid_get_card_name( $card_number ) {
203
+function getpaid_get_card_name($card_number) {
204 204
 
205 205
 	// Known regexes.
206 206
 	$regexes = array(
207
-		'/^4/'                     => __( 'Visa', 'invoicing' ),
208
-		'/^5[1-5]/'                => __( 'Mastercard', 'invoicing' ),
209
-		'/^3[47]/'                 => __( 'Amex', 'invoicing' ),
210
-		'/^3(?:0[0-5]|[68])/'      => __( 'Diners Club', 'invoicing' ),
211
-		'/^6(?:011|5)/'            => __( 'Discover', 'invoicing' ),
212
-		'/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ),
207
+		'/^4/'                     => __('Visa', 'invoicing'),
208
+		'/^5[1-5]/'                => __('Mastercard', 'invoicing'),
209
+		'/^3[47]/'                 => __('Amex', 'invoicing'),
210
+		'/^3(?:0[0-5]|[68])/'      => __('Diners Club', 'invoicing'),
211
+		'/^6(?:011|5)/'            => __('Discover', 'invoicing'),
212
+		'/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'),
213 213
 	);
214 214
 
215 215
 	// Confirm if one matches.
216
-	foreach ( $regexes as $regex => $card ) {
217
-		if ( preg_match( $regex, $card_number ) >= 1 ) {
216
+	foreach ($regexes as $regex => $card) {
217
+		if (preg_match($regex, $card_number) >= 1) {
218 218
 			return $card;
219 219
 		}
220 220
 	}
221 221
 
222 222
 	// None matched.
223
-	return __( 'Card', 'invoicing' );
223
+	return __('Card', 'invoicing');
224 224
 
225 225
 }
226 226
 
@@ -229,25 +229,25 @@  discard block
 block discarded – undo
229 229
  *
230 230
  * @param WPInv_Invoice|int|null $invoice
231 231
  */
232
-function wpinv_send_back_to_checkout( $invoice = null ) {
233
-	$response = array( 'success' => false );
234
-	$invoice  = wpinv_get_invoice( $invoice );
232
+function wpinv_send_back_to_checkout($invoice = null) {
233
+	$response = array('success' => false);
234
+	$invoice  = wpinv_get_invoice($invoice);
235 235
 
236 236
 	// Was an invoice created?
237
-	if ( ! empty( $invoice ) ) {
238
-		$invoice             = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice;
237
+	if (!empty($invoice)) {
238
+		$invoice             = is_scalar($invoice) ? new WPInv_Invoice($invoice) : $invoice;
239 239
 		$response['invoice'] = $invoice->get_id();
240
-		do_action( 'getpaid_checkout_invoice_exception', $invoice );
240
+		do_action('getpaid_checkout_invoice_exception', $invoice);
241 241
 	}
242 242
 
243 243
 	// Do we have any errors?
244
-	if ( wpinv_get_errors() ) {
245
-		$response['data'] = getpaid_get_errors_html( true, false );
244
+	if (wpinv_get_errors()) {
245
+		$response['data'] = getpaid_get_errors_html(true, false);
246 246
 	} else {
247
-		$response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' );
247
+		$response['data'] = __('An error occured while processing your payment. Please try again.', 'invoicing');
248 248
 	}
249 249
 
250
-	wp_send_json( $response );
250
+	wp_send_json($response);
251 251
 }
252 252
 
253 253
 /**
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
  * @return string
257 257
  */
258 258
 function getpaid_get_recaptcha_site_key() {
259
-	return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) );
259
+	return apply_filters('getpaid_recaptcha_site_key', wpinv_get_option('recaptcha_site_key', ''));
260 260
 }
261 261
 
262 262
 /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
  * @return string
266 266
  */
267 267
 function getpaid_get_recaptcha_secret_key() {
268
-	return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) );
268
+	return apply_filters('getpaid_recaptcha_secret_key', wpinv_get_option('recaptcha_secret_key', ''));
269 269
 }
270 270
 
271 271
 /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
  * @return bool
275 275
  */
276 276
 function getpaid_is_recaptcha_enabled() {
277
-	return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key();
277
+	return wpinv_get_option('enable_recaptcha', false) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key();
278 278
 }
279 279
 
280 280
 /**
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
  * @return string
284 284
  */
285 285
 function getpaid_get_recaptcha_version() {
286
-	return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) );
286
+	return apply_filters('getpaid_recaptcha_version', wpinv_get_option('recaptcha_version', 'v2'));
287 287
 }
288 288
 
289 289
 /**
@@ -297,14 +297,14 @@  discard block
 block discarded – undo
297 297
 		'version' => getpaid_get_recaptcha_version(),
298 298
 	);
299 299
 
300
-	if ( ! getpaid_is_recaptcha_enabled() ) {
300
+	if (!getpaid_is_recaptcha_enabled()) {
301 301
 		return $settings;
302 302
 	}
303 303
 
304 304
 	$settings['sitekey'] = getpaid_get_recaptcha_site_key();
305 305
 
306 306
 	// Version 2 render params.
307
-	if ( 'v2' === getpaid_get_recaptcha_version() ) {
307
+	if ('v2' === getpaid_get_recaptcha_version()) {
308 308
 		$settings['render_params'] = array(
309 309
 			'sitekey'  => getpaid_get_recaptcha_site_key(),
310 310
 			'theme'    => 'light',
@@ -313,20 +313,20 @@  discard block
 block discarded – undo
313 313
 		);
314 314
 	}
315 315
 
316
-	return apply_filters( 'getpaid_recaptcha_settings', $settings );
316
+	return apply_filters('getpaid_recaptcha_settings', $settings);
317 317
 }
318 318
 
319 319
 /**
320 320
  * Displays reCAPTCHA before payment button.
321 321
  */
322 322
 function getpaid_display_recaptcha_before_payment_button() {
323
-	if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) {
323
+	if (!getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version()) {
324 324
 		return;
325 325
 	}
326 326
 
327 327
 	printf(
328 328
 		'<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha" id="getpaid-recaptcha-%s"></div></div>',
329
-		esc_attr( wp_unique_id() )
329
+		esc_attr(wp_unique_id())
330 330
 	);
331 331
 }
332
-add_action( 'getpaid_before_payment_form_pay_button', 'getpaid_display_recaptcha_before_payment_button' );
332
+add_action('getpaid_before_payment_form_pay_button', 'getpaid_display_recaptcha_before_payment_button');
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +605 added lines, -605 removed lines patch added patch discarded remove patch
@@ -14,650 +14,650 @@
 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( 'notes', new WPInv_Notes() );
90
-		$this->set( 'api', new WPInv_API() );
91
-		$this->set( 'post_types', new GetPaid_Post_Types() );
92
-		$this->set( 'template', new GetPaid_Template() );
93
-		$this->set( 'admin', new GetPaid_Admin() );
94
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
95
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
96
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
97
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
98
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
99
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
100
-
101
-	}
102
-
103
-	 /**
104
-	 * Define plugin constants.
105
-	 */
106
-	public function define_constants() {
107
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
108
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
109
-		$this->version = WPINV_VERSION;
110
-	}
111
-
112
-	/**
113
-	 * Hook into actions and filters.
114
-	 *
115
-	 * @since 1.0.19
116
-	 */
117
-	protected function init_hooks() {
118
-		/* Internationalize the text strings used. */
119
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
-
121
-		// Init the plugin after WordPress inits.
122
-		add_action( 'init', array( $this, 'init' ), 1 );
123
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
124
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
125
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
126
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
127
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
128
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
129
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
130
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
131
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
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( 'notes', new WPInv_Notes() );
90
+        $this->set( 'api', new WPInv_API() );
91
+        $this->set( 'post_types', new GetPaid_Post_Types() );
92
+        $this->set( 'template', new GetPaid_Template() );
93
+        $this->set( 'admin', new GetPaid_Admin() );
94
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
95
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
96
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
97
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
98
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
99
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
100
+
101
+    }
102
+
103
+        /**
104
+         * Define plugin constants.
105
+         */
106
+    public function define_constants() {
107
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
108
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
109
+        $this->version = WPINV_VERSION;
110
+    }
111
+
112
+    /**
113
+     * Hook into actions and filters.
114
+     *
115
+     * @since 1.0.19
116
+     */
117
+    protected function init_hooks() {
118
+        /* Internationalize the text strings used. */
119
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
+
121
+        // Init the plugin after WordPress inits.
122
+        add_action( 'init', array( $this, 'init' ), 1 );
123
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
124
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
125
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
126
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
127
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
128
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
129
+        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
130
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
131
+        add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135 135
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load Localisation files.
158
-	 *
159
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
-	 *
161
-	 * Locales found in:
162
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
-	 *
165
-	 * @since 1.0.0
166
-	 */
167
-	public function load_textdomain() {
168
-
169
-		load_plugin_textdomain(
170
-			'invoicing',
171
-			false,
172
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
-		);
174
-
175
-	}
176
-
177
-	/**
178
-	 * Include required core files used in admin and on the frontend.
179
-	 */
180
-	public function includes() {
181
-
182
-		// Start with the settings.
183
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
184
-
185
-		// Packages/libraries.
186
-		require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
187
-		require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
188
-
189
-		// Load functions.
190
-		require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
191
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
192
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
193
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
194
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
195
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
196
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
197
-		require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
198
-		require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
199
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
200
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
201
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
202
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
203
-		require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
204
-		require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
205
-
206
-		// Register autoloader.
207
-		try {
208
-			spl_autoload_register( array( $this, 'autoload' ), true );
209
-		} catch ( Exception $e ) {
210
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
-		}
212
-
213
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
214
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
215
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
216
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
217
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
218
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
219
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
220
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
221
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
222
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
223
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
224
-		require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
225
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
226
-		require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
227
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
228
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
229
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
230
-		require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
231
-		require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
232
-		require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
233
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.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
-			}
136
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load Localisation files.
158
+     *
159
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
+     *
161
+     * Locales found in:
162
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
+     *
165
+     * @since 1.0.0
166
+     */
167
+    public function load_textdomain() {
168
+
169
+        load_plugin_textdomain(
170
+            'invoicing',
171
+            false,
172
+            plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
+        );
174
+
175
+    }
176
+
177
+    /**
178
+     * Include required core files used in admin and on the frontend.
179
+     */
180
+    public function includes() {
181
+
182
+        // Start with the settings.
183
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
184
+
185
+        // Packages/libraries.
186
+        require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
187
+        require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
188
+
189
+        // Load functions.
190
+        require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
191
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
192
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
193
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
194
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
195
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
196
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
197
+        require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
198
+        require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
199
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
200
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
201
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
202
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
203
+        require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
204
+        require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
205
+
206
+        // Register autoloader.
207
+        try {
208
+            spl_autoload_register( array( $this, 'autoload' ), true );
209
+        } catch ( Exception $e ) {
210
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
+        }
212
+
213
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
214
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
215
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
216
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
217
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
218
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
219
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
220
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
221
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
222
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
223
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
224
+        require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
225
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
226
+        require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
227
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
228
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
229
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
230
+        require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
231
+        require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
232
+        require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
233
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice.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 303
 }
304 304
 
305
-	}
306
-
307
-	/**
308
-	 * Inits hooks etc.
309
-	 */
310
-	public function init() {
311
-
312
-		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
314
-
315
-		// Maybe upgrade.
316
-		$this->maybe_upgrade_database();
317
-
318
-		// Load default gateways.
319
-		$gateways = apply_filters(
320
-			'getpaid_default_gateways',
321
-			array(
322
-				'manual'        => 'GetPaid_Manual_Gateway',
323
-				'paypal'        => 'GetPaid_Paypal_Gateway',
324
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
-			)
328
-		);
329
-
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
332
-		}
333
-
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
-			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
337
-		}
338
-
339
-		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
341
-
342
-	}
343
-
344
-	/**
345
-	 * Checks if this is an IPN request and processes it.
346
-	 */
347
-	public function maybe_process_ipn() {
348
-
349
-		// Ensure that this is an IPN request.
350
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
-			return;
352
-		}
353
-
354
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
355
-
356
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
357
-		do_action( "wpinv_verify_{$gateway}_ipn" );
358
-		exit;
359
-
360
-	}
361
-
362
-	public function enqueue_scripts() {
363
-
364
-		// Fires before adding scripts.
365
-		do_action( 'getpaid_enqueue_scripts' );
366
-
367
-		$localize                         = array();
368
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
-		$localize['thousands']            = wpinv_thousands_separator();
370
-		$localize['decimals']             = wpinv_decimal_separator();
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
-		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
-		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
378
-
379
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
-
381
-		// reCaptcha.
382
-		if ( getpaid_is_recaptcha_enabled() ) {
383
-			$url = apply_filters(
384
-				'getpaid_recaptcha_api_url',
385
-				add_query_arg(
386
-					array(
387
-						'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(),
388
-					),
389
-					'https://www.google.com/recaptcha/api.js'
390
-				)
391
-			);
392
-			wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
393
-		}
394
-
395
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
396
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
397
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
398
-	}
399
-
400
-	public function wpinv_actions() {
401
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
402
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
403
-		}
404
-
405
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
406
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
407
-		}
408
-	}
409
-
410
-	/**
305
+    }
306
+
307
+    /**
308
+     * Inits hooks etc.
309
+     */
310
+    public function init() {
311
+
312
+        // Fires before getpaid inits.
313
+        do_action( 'before_getpaid_init', $this );
314
+
315
+        // Maybe upgrade.
316
+        $this->maybe_upgrade_database();
317
+
318
+        // Load default gateways.
319
+        $gateways = apply_filters(
320
+            'getpaid_default_gateways',
321
+            array(
322
+                'manual'        => 'GetPaid_Manual_Gateway',
323
+                'paypal'        => 'GetPaid_Paypal_Gateway',
324
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
+            )
328
+        );
329
+
330
+        foreach ( $gateways as $id => $class ) {
331
+            $this->gateways[ $id ] = new $class();
332
+        }
333
+
334
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
+            GetPaid_Installer::rename_gateways_label();
336
+            update_option( 'wpinv_renamed_gateways', 'yes' );
337
+        }
338
+
339
+        // Fires after getpaid inits.
340
+        do_action( 'getpaid_init', $this );
341
+
342
+    }
343
+
344
+    /**
345
+     * Checks if this is an IPN request and processes it.
346
+     */
347
+    public function maybe_process_ipn() {
348
+
349
+        // Ensure that this is an IPN request.
350
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
+            return;
352
+        }
353
+
354
+        $gateway = sanitize_text_field( $_GET['wpi-gateway'] );
355
+
356
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
357
+        do_action( "wpinv_verify_{$gateway}_ipn" );
358
+        exit;
359
+
360
+    }
361
+
362
+    public function enqueue_scripts() {
363
+
364
+        // Fires before adding scripts.
365
+        do_action( 'getpaid_enqueue_scripts' );
366
+
367
+        $localize                         = array();
368
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
+        $localize['thousands']            = wpinv_thousands_separator();
370
+        $localize['decimals']             = wpinv_decimal_separator();
371
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
+        $localize['UseTaxes']             = wpinv_use_taxes();
374
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
376
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
+        $localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
378
+
379
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
+
381
+        // reCaptcha.
382
+        if ( getpaid_is_recaptcha_enabled() ) {
383
+            $url = apply_filters(
384
+                'getpaid_recaptcha_api_url',
385
+                add_query_arg(
386
+                    array(
387
+                        'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(),
388
+                    ),
389
+                    'https://www.google.com/recaptcha/api.js'
390
+                )
391
+            );
392
+            wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
393
+        }
394
+
395
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
396
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
397
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
398
+    }
399
+
400
+    public function wpinv_actions() {
401
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
402
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
403
+        }
404
+
405
+        if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
406
+            include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
407
+        }
408
+    }
409
+
410
+    /**
411 411
      * Fires an action after verifying that a user can fire them.
412
-	 *
413
-	 * Note: If the action is on an invoice, subscription etc, esure that the
414
-	 * current user owns the invoice/subscription.
412
+     *
413
+     * Note: If the action is on an invoice, subscription etc, esure that the
414
+     * current user owns the invoice/subscription.
415 415
      */
416 416
     public function maybe_do_authenticated_action() {
417 417
 
418
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
418
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
419 419
 
420
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
421
-			$data = wp_unslash( $_REQUEST );
422
-			if ( is_user_logged_in() ) {
423
-				do_action( "getpaid_authenticated_action_$key", $data );
424
-			}
420
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
421
+            $data = wp_unslash( $_REQUEST );
422
+            if ( is_user_logged_in() ) {
423
+                do_action( "getpaid_authenticated_action_$key", $data );
424
+            }
425 425
 
426
-			do_action( "getpaid_unauthenticated_action_$key", $data );
426
+            do_action( "getpaid_unauthenticated_action_$key", $data );
427 427
 
428
-		}
428
+        }
429 429
 
430 430
     }
431 431
 
432
-	public function pre_get_posts( $wp_query ) {
433
-
434
-		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() ) {
435
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
436
-		}
437
-
438
-		return $wp_query;
439
-	}
440
-
441
-	/**
442
-	 * Register widgets
443
-	 *
444
-	 */
445
-	public function register_widgets() {
446
-		global $pagenow;
447
-
448
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
449
-		// So we disable our widgets when editing a page with UX Builder.
450
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
451
-			return;
452
-		}
453
-
454
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
455
-
456
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
457
-			// don't initiate in these conditions.
458
-		} else {
459
-
460
-			// Only load allowed widgets.
461
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
462
-			$widgets = apply_filters(
463
-				'getpaid_widget_classes',
464
-				array(
465
-					'WPInv_Checkout_Widget',
466
-					'WPInv_History_Widget',
467
-					'WPInv_Receipt_Widget',
468
-					'WPInv_Subscriptions_Widget',
469
-					'WPInv_Buy_Item_Widget',
470
-					'WPInv_Messages_Widget',
471
-					'WPInv_GetPaid_Widget',
472
-					'WPInv_Invoice_Widget',
473
-				)
474
-			);
475
-
476
-			// For each widget...
477
-			foreach ( $widgets as $widget ) {
478
-
479
-				// Abort early if it is excluded for this page.
480
-				if ( in_array( $widget, $exclude ) ) {
481
-					continue;
482
-				}
483
-
484
-				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
485
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
486
-					register_widget( $widget );
487
-				} else {
488
-					new $widget();
489
-				}
432
+    public function pre_get_posts( $wp_query ) {
433
+
434
+        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() ) {
435
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
436
+        }
437
+
438
+        return $wp_query;
439
+    }
440
+
441
+    /**
442
+     * Register widgets
443
+     *
444
+     */
445
+    public function register_widgets() {
446
+        global $pagenow;
447
+
448
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
449
+        // So we disable our widgets when editing a page with UX Builder.
450
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
451
+            return;
452
+        }
453
+
454
+        $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
455
+
456
+        if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
457
+            // don't initiate in these conditions.
458
+        } else {
459
+
460
+            // Only load allowed widgets.
461
+            $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
462
+            $widgets = apply_filters(
463
+                'getpaid_widget_classes',
464
+                array(
465
+                    'WPInv_Checkout_Widget',
466
+                    'WPInv_History_Widget',
467
+                    'WPInv_Receipt_Widget',
468
+                    'WPInv_Subscriptions_Widget',
469
+                    'WPInv_Buy_Item_Widget',
470
+                    'WPInv_Messages_Widget',
471
+                    'WPInv_GetPaid_Widget',
472
+                    'WPInv_Invoice_Widget',
473
+                )
474
+            );
475
+
476
+            // For each widget...
477
+            foreach ( $widgets as $widget ) {
478
+
479
+                // Abort early if it is excluded for this page.
480
+                if ( in_array( $widget, $exclude ) ) {
481
+                    continue;
482
+                }
483
+
484
+                // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
485
+                if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
486
+                    register_widget( $widget );
487
+                } else {
488
+                    new $widget();
489
+                }
490 490
 }
491 491
 }
492 492
 
493
-	}
493
+    }
494
+
495
+    /**
496
+     * Upgrades the database.
497
+     *
498
+     * @since 2.0.2
499
+     */
500
+    public function maybe_upgrade_database() {
501
+
502
+        $wpi_version = get_option( 'wpinv_version', 0 );
503
+
504
+        if ( $wpi_version == WPINV_VERSION ) {
505
+            return;
506
+        }
507
+
508
+        $installer = new GetPaid_Installer();
509
+
510
+        if ( empty( $wpi_version ) ) {
511
+            return $installer->upgrade_db( 0 );
512
+        }
513
+
514
+        $upgrades  = array(
515
+            '0.0.5'  => '004',
516
+            '1.0.3'  => '102',
517
+            '2.0.0'  => '118',
518
+            '2.0.8'  => '207',
519
+            '2.6.16' => '2615',
520
+        );
521
+
522
+        foreach ( $upgrades as $key => $method ) {
523
+
524
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
525
+                return $installer->upgrade_db( $method );
526
+            }
527
+        }
528
+
529
+    }
530
+
531
+    /**
532
+     * Flushes the permalinks if needed.
533
+     *
534
+     * @since 2.0.8
535
+     */
536
+    public function maybe_flush_permalinks() {
537
+
538
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
539
+
540
+        if ( ! empty( $flush ) ) {
541
+            flush_rewrite_rules();
542
+            delete_option( 'wpinv_flush_permalinks' );
543
+        }
544
+
545
+    }
546
+
547
+    /**
548
+     * Remove our pages from yoast sitemaps.
549
+     *
550
+     * @since 1.0.19
551
+     * @param int[] $excluded_posts_ids
552
+     */
553
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
554
+
555
+        // Ensure that we have an array.
556
+        if ( ! is_array( $excluded_posts_ids ) ) {
557
+            $excluded_posts_ids = array();
558
+        }
559
+
560
+        // Prepare our pages.
561
+        $our_pages = array();
562
+
563
+        // Checkout page.
564
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
565
+
566
+        // Success page.
567
+        $our_pages[] = wpinv_get_option( 'success_page', false );
568
+
569
+        // Failure page.
570
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
571
+
572
+        // History page.
573
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
494 574
 
495
-	/**
496
-	 * Upgrades the database.
497
-	 *
498
-	 * @since 2.0.2
499
-	 */
500
-	public function maybe_upgrade_database() {
575
+        // Subscriptions page.
576
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
501 577
 
502
-		$wpi_version = get_option( 'wpinv_version', 0 );
578
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
503 579
 
504
-		if ( $wpi_version == WPINV_VERSION ) {
505
-			return;
506
-		}
580
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
581
+        return array_unique( $excluded_posts_ids );
507 582
 
508
-		$installer = new GetPaid_Installer();
583
+    }
584
+
585
+    /**
586
+     * Remove our pages from yoast sitemaps.
587
+     *
588
+     * @since 1.0.19
589
+     * @param string[] $post_types
590
+     */
591
+    public function exclude_invoicing_post_types( $post_types ) {
592
+
593
+        // Ensure that we have an array.
594
+        if ( ! is_array( $post_types ) ) {
595
+            $post_types = array();
596
+        }
597
+
598
+        // Remove our post types.
599
+        return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
600
+    }
601
+
602
+    /**
603
+     * Displays additional footer code.
604
+     *
605
+     * @since 2.0.0
606
+     */
607
+    public function wp_footer() {
608
+        wpinv_get_template( 'frontend-footer.php' );
609
+    }
509 610
 
510
-		if ( empty( $wpi_version ) ) {
511
-			return $installer->upgrade_db( 0 );
512
-		}
611
+    /**
612
+     * Displays additional header code.
613
+     *
614
+     * @since 2.0.0
615
+     */
616
+    public function wp_head() {
617
+        wpinv_get_template( 'frontend-head.php' );
618
+    }
513 619
 
514
-		$upgrades  = array(
515
-			'0.0.5'  => '004',
516
-			'1.0.3'  => '102',
517
-			'2.0.0'  => '118',
518
-			'2.0.8'  => '207',
519
-			'2.6.16' => '2615',
520
-		);
521
-
522
-		foreach ( $upgrades as $key => $method ) {
523
-
524
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
525
-				return $installer->upgrade_db( $method );
526
-			}
527
-		}
528
-
529
-	}
530
-
531
-	/**
532
-	 * Flushes the permalinks if needed.
533
-	 *
534
-	 * @since 2.0.8
535
-	 */
536
-	public function maybe_flush_permalinks() {
537
-
538
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
539
-
540
-		if ( ! empty( $flush ) ) {
541
-			flush_rewrite_rules();
542
-			delete_option( 'wpinv_flush_permalinks' );
543
-		}
544
-
545
-	}
546
-
547
-	/**
548
-	 * Remove our pages from yoast sitemaps.
549
-	 *
550
-	 * @since 1.0.19
551
-	 * @param int[] $excluded_posts_ids
552
-	 */
553
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
554
-
555
-		// Ensure that we have an array.
556
-		if ( ! is_array( $excluded_posts_ids ) ) {
557
-			$excluded_posts_ids = array();
558
-		}
559
-
560
-		// Prepare our pages.
561
-		$our_pages = array();
562
-
563
-		// Checkout page.
564
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
565
-
566
-		// Success page.
567
-		$our_pages[] = wpinv_get_option( 'success_page', false );
568
-
569
-		// Failure page.
570
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
571
-
572
-		// History page.
573
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
574
-
575
-		// Subscriptions page.
576
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
577
-
578
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
579
-
580
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
581
-		return array_unique( $excluded_posts_ids );
582
-
583
-	}
584
-
585
-	/**
586
-	 * Remove our pages from yoast sitemaps.
587
-	 *
588
-	 * @since 1.0.19
589
-	 * @param string[] $post_types
590
-	 */
591
-	public function exclude_invoicing_post_types( $post_types ) {
592
-
593
-		// Ensure that we have an array.
594
-		if ( ! is_array( $post_types ) ) {
595
-			$post_types = array();
596
-		}
597
-
598
-		// Remove our post types.
599
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
600
-	}
601
-
602
-	/**
603
-	 * Displays additional footer code.
604
-	 *
605
-	 * @since 2.0.0
606
-	 */
607
-	public function wp_footer() {
608
-		wpinv_get_template( 'frontend-footer.php' );
609
-	}
610
-
611
-	/**
612
-	 * Displays additional header code.
613
-	 *
614
-	 * @since 2.0.0
615
-	 */
616
-	public function wp_head() {
617
-		wpinv_get_template( 'frontend-head.php' );
618
-	}
619
-
620
-	/**
621
-	 * Custom query vars.
622
-	 *
623
-	 */
624
-	public function custom_query_vars( $vars ) {
620
+    /**
621
+     * Custom query vars.
622
+     *
623
+     */
624
+    public function custom_query_vars( $vars ) {
625 625
         $vars[] = 'getpaid-ipn';
626 626
         return $vars;
627
-	}
627
+    }
628 628
 
629
-	/**
630
-	 * Add rewrite tags and rules.
631
-	 *
632
-	 */
633
-	public function add_rewrite_rule() {
629
+    /**
630
+     * Add rewrite tags and rules.
631
+     *
632
+     */
633
+    public function add_rewrite_rule() {
634 634
         $tag = 'getpaid-ipn';
635 635
         add_rewrite_tag( "%$tag%", '([^&]+)' );
636 636
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
637
-	}
637
+    }
638 638
 
639
-	/**
640
-	 * Processes non-query string ipns.
641
-	 *
642
-	 */
643
-	public function maybe_process_new_ipn( $query ) {
639
+    /**
640
+     * Processes non-query string ipns.
641
+     *
642
+     */
643
+    public function maybe_process_new_ipn( $query ) {
644 644
 
645 645
         if ( is_admin() || ! $query->is_main_query() ) {
646 646
             return;
647 647
         }
648 648
 
649
-		$gateway = get_query_var( 'getpaid-ipn' );
649
+        $gateway = get_query_var( 'getpaid-ipn' );
650 650
 
651 651
         if ( ! empty( $gateway ) ) {
652 652
 
653
-			$gateway = sanitize_text_field( $gateway );
654
-			nocache_headers();
655
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
656
-			do_action( "wpinv_verify_{$gateway}_ipn" );
657
-			exit;
653
+            $gateway = sanitize_text_field( $gateway );
654
+            nocache_headers();
655
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
656
+            do_action( "wpinv_verify_{$gateway}_ipn" );
657
+            exit;
658 658
 
659 659
         }
660 660
 
661
-	}
661
+    }
662 662
 
663 663
 }
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Main Invoicing class.
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param string $prop The prop to set.
57 57
 	 * @param mixed $value The value to retrieve.
58 58
 	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
59
+	public function set($prop, $value) {
60
+		$this->data[$prop] = $value;
61 61
 	}
62 62
 
63 63
 	/**
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	 * @param string $prop The prop to set.
67 67
 	 * @return mixed The value.
68 68
 	 */
69
-	public function get( $prop ) {
69
+	public function get($prop) {
70 70
 
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
71
+		if (isset($this->data[$prop])) {
72
+			return $this->data[$prop];
73 73
 		}
74 74
 
75 75
 		return null;
@@ -81,22 +81,22 @@  discard block
 block discarded – undo
81 81
 	public function set_properties() {
82 82
 
83 83
 		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
+		$this->set('session', new WPInv_Session_Handler());
85
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
86 86
 		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87 87
 
88 88
 		// Init other objects.
89
-		$this->set( 'notes', new WPInv_Notes() );
90
-		$this->set( 'api', new WPInv_API() );
91
-		$this->set( 'post_types', new GetPaid_Post_Types() );
92
-		$this->set( 'template', new GetPaid_Template() );
93
-		$this->set( 'admin', new GetPaid_Admin() );
94
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
95
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
96
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
97
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
98
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
99
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
89
+		$this->set('notes', new WPInv_Notes());
90
+		$this->set('api', new WPInv_API());
91
+		$this->set('post_types', new GetPaid_Post_Types());
92
+		$this->set('template', new GetPaid_Template());
93
+		$this->set('admin', new GetPaid_Admin());
94
+		$this->set('subscriptions', new WPInv_Subscriptions());
95
+		$this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails());
96
+		$this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails());
97
+		$this->set('daily_maintenace', new GetPaid_Daily_Maintenance());
98
+		$this->set('payment_forms', new GetPaid_Payment_Forms());
99
+		$this->set('maxmind', new GetPaid_MaxMind_Geolocation());
100 100
 
101 101
 	}
102 102
 
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 * Define plugin constants.
105 105
 	 */
106 106
 	public function define_constants() {
107
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
108
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
107
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
108
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
109 109
 		$this->version = WPINV_VERSION;
110 110
 	}
111 111
 
@@ -116,28 +116,28 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	protected function init_hooks() {
118 118
 		/* Internationalize the text strings used. */
119
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
119
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
120 120
 
121 121
 		// Init the plugin after WordPress inits.
122
-		add_action( 'init', array( $this, 'init' ), 1 );
123
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
124
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
125
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
126
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
127
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
128
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
129
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
130
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
131
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135
-        add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
122
+		add_action('init', array($this, 'init'), 1);
123
+		add_action('init', array($this, 'maybe_process_ipn'), 10);
124
+		add_action('init', array($this, 'wpinv_actions'));
125
+		add_action('init', array($this, 'maybe_do_authenticated_action'), 100);
126
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11);
127
+		add_action('wp_footer', array($this, 'wp_footer'));
128
+		add_action('wp_head', array($this, 'wp_head'));
129
+		add_action('widgets_init', array($this, 'register_widgets'));
130
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
131
+		add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types'));
132
+		add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
133
+
134
+		add_filter('query_vars', array($this, 'custom_query_vars'));
135
+        add_action('init', array($this, 'add_rewrite_rule'), 10, 0);
136
+		add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1);
137 137
 
138 138
 		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
139
+		do_action('wpinv_actions', $this);
140
+		do_action('getpaid_actions', $this);
141 141
 
142 142
 	}
143 143
 
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 		/* Internationalize the text strings used. */
146 146
 		$this->load_textdomain();
147 147
 
148
-		do_action( 'wpinv_loaded' );
148
+		do_action('wpinv_loaded');
149 149
 
150 150
 		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
151
+		if (function_exists('ct_css_output')) {
152 152
 			wpinv_oxygen_fix_conflict();
153 153
 		}
154 154
 	}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		load_plugin_textdomain(
170 170
 			'invoicing',
171 171
 			false,
172
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
172
+			plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/'
173 173
 		);
174 174
 
175 175
 	}
@@ -205,9 +205,9 @@  discard block
 block discarded – undo
205 205
 
206 206
 		// Register autoloader.
207 207
 		try {
208
-			spl_autoload_register( array( $this, 'autoload' ), true );
209
-		} catch ( Exception $e ) {
210
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
208
+			spl_autoload_register(array($this, 'autoload'), true);
209
+		} catch (Exception $e) {
210
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
211 211
 		}
212 212
 
213 213
 		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
234 234
 		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
235 235
 
236
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
236
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
237 237
 			GetPaid_Post_Types_Admin::init();
238 238
 
239 239
 			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
@@ -244,15 +244,15 @@  discard block
 block discarded – undo
244 244
 			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
245 245
 			// load the user class only on the users.php page
246 246
 			global $pagenow;
247
-			if ( $pagenow == 'users.php' ) {
247
+			if ($pagenow == 'users.php') {
248 248
 				new WPInv_Admin_Users();
249 249
 			}
250 250
 		}
251 251
 
252 252
 		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
253
+		if (defined('WP_CLI') && WP_CLI) {
254 254
 			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
255
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
256 256
 		}
257 257
 
258 258
 	}
@@ -265,21 +265,21 @@  discard block
 block discarded – undo
265 265
 	 * @since       1.0.19
266 266
 	 * @return      void
267 267
 	 */
268
-	public function autoload( $class_name ) {
268
+	public function autoload($class_name) {
269 269
 
270 270
 		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
271
+		$class_name = strtolower($class_name);
272 272
 
273 273
 		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
274
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
279
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
280 280
 
281 281
 		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
282
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
283 283
 
284 284
 		// And an array of possible locations in order of importance.
285 285
 		$locations = array(
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
 			"$plugin_path/includes/admin/meta-boxes",
295 295
 		);
296 296
 
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
297
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
298 298
 
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
299
+			if (file_exists(trailingslashit($location) . $file_name)) {
300
+				include trailingslashit($location) . $file_name;
301 301
 				break;
302 302
 			}
303 303
 }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	public function init() {
311 311
 
312 312
 		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
313
+		do_action('before_getpaid_init', $this);
314 314
 
315 315
 		// Maybe upgrade.
316 316
 		$this->maybe_upgrade_database();
@@ -327,17 +327,17 @@  discard block
 block discarded – undo
327 327
 			)
328 328
 		);
329 329
 
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
330
+		foreach ($gateways as $id => $class) {
331
+			$this->gateways[$id] = new $class();
332 332
 		}
333 333
 
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
334
+		if ('yes' != get_option('wpinv_renamed_gateways')) {
335 335
 			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
336
+			update_option('wpinv_renamed_gateways', 'yes');
337 337
 		}
338 338
 
339 339
 		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
340
+		do_action('getpaid_init', $this);
341 341
 
342 342
 	}
343 343
 
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
 	public function maybe_process_ipn() {
348 348
 
349 349
 		// Ensure that this is an IPN request.
350
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
350
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
351 351
 			return;
352 352
 		}
353 353
 
354
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
354
+		$gateway = sanitize_text_field($_GET['wpi-gateway']);
355 355
 
356
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
357
-		do_action( "wpinv_verify_{$gateway}_ipn" );
356
+		do_action('wpinv_verify_payment_ipn', $gateway);
357
+		do_action("wpinv_verify_{$gateway}_ipn");
358 358
 		exit;
359 359
 
360 360
 	}
@@ -362,24 +362,24 @@  discard block
 block discarded – undo
362 362
 	public function enqueue_scripts() {
363 363
 
364 364
 		// Fires before adding scripts.
365
-		do_action( 'getpaid_enqueue_scripts' );
365
+		do_action('getpaid_enqueue_scripts');
366 366
 
367 367
 		$localize                         = array();
368
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
368
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
369 369
 		$localize['thousands']            = wpinv_thousands_separator();
370 370
 		$localize['decimals']             = wpinv_decimal_separator();
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
371
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
372
+		$localize['txtComplete']          = __('Continue', 'invoicing');
373 373
 		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
374
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
375
+		$localize['loading']              = __('Loading...', 'invoicing');
376
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
377 377
 		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
378 378
 
379
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
379
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
380 380
 
381 381
 		// reCaptcha.
382
-		if ( getpaid_is_recaptcha_enabled() ) {
382
+		if (getpaid_is_recaptcha_enabled()) {
383 383
 			$url = apply_filters(
384 384
 				'getpaid_recaptcha_api_url',
385 385
 				add_query_arg(
@@ -389,21 +389,21 @@  discard block
 block discarded – undo
389 389
 					'https://www.google.com/recaptcha/api.js'
390 390
 				)
391 391
 			);
392
-			wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
392
+			wp_enqueue_script('recaptcha', $url, array(), null, true); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
393 393
 		}
394 394
 
395
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
396
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
397
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
395
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
396
+		wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true);
397
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
398 398
 	}
399 399
 
400 400
 	public function wpinv_actions() {
401
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
402
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
401
+		if (isset($_REQUEST['wpi_action'])) {
402
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
403 403
 		}
404 404
 
405
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
406
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
405
+		if (defined('WP_ALL_IMPORT_ROOT_DIR')) {
406
+			include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
407 407
 		}
408 408
 	}
409 409
 
@@ -415,24 +415,24 @@  discard block
 block discarded – undo
415 415
      */
416 416
     public function maybe_do_authenticated_action() {
417 417
 
418
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
418
+		if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
419 419
 
420
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
421
-			$data = wp_unslash( $_REQUEST );
422
-			if ( is_user_logged_in() ) {
423
-				do_action( "getpaid_authenticated_action_$key", $data );
420
+			$key  = sanitize_key($_REQUEST['getpaid-action']);
421
+			$data = wp_unslash($_REQUEST);
422
+			if (is_user_logged_in()) {
423
+				do_action("getpaid_authenticated_action_$key", $data);
424 424
 			}
425 425
 
426
-			do_action( "getpaid_unauthenticated_action_$key", $data );
426
+			do_action("getpaid_unauthenticated_action_$key", $data);
427 427
 
428 428
 		}
429 429
 
430 430
     }
431 431
 
432
-	public function pre_get_posts( $wp_query ) {
432
+	public function pre_get_posts($wp_query) {
433 433
 
434
-		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() ) {
435
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
434
+		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()) {
435
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type']));
436 436
 		}
437 437
 
438 438
 		return $wp_query;
@@ -447,18 +447,18 @@  discard block
 block discarded – undo
447 447
 
448 448
 		// Currently, UX Builder does not work particulaly well with SuperDuper.
449 449
 		// So we disable our widgets when editing a page with UX Builder.
450
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
450
+		if (function_exists('ux_builder_is_active') && ux_builder_is_active()) {
451 451
 			return;
452 452
 		}
453 453
 
454
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
454
+		$block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array();
455 455
 
456
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
456
+		if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) {
457 457
 			// don't initiate in these conditions.
458 458
 		} else {
459 459
 
460 460
 			// Only load allowed widgets.
461
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
461
+			$exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array();
462 462
 			$widgets = apply_filters(
463 463
 				'getpaid_widget_classes',
464 464
 				array(
@@ -474,16 +474,16 @@  discard block
 block discarded – undo
474 474
 			);
475 475
 
476 476
 			// For each widget...
477
-			foreach ( $widgets as $widget ) {
477
+			foreach ($widgets as $widget) {
478 478
 
479 479
 				// Abort early if it is excluded for this page.
480
-				if ( in_array( $widget, $exclude ) ) {
480
+				if (in_array($widget, $exclude)) {
481 481
 					continue;
482 482
 				}
483 483
 
484 484
 				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
485
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
486
-					register_widget( $widget );
485
+				if (is_subclass_of($widget, 'WP_Widget')) {
486
+					register_widget($widget);
487 487
 				} else {
488 488
 					new $widget();
489 489
 				}
@@ -499,19 +499,19 @@  discard block
 block discarded – undo
499 499
 	 */
500 500
 	public function maybe_upgrade_database() {
501 501
 
502
-		$wpi_version = get_option( 'wpinv_version', 0 );
502
+		$wpi_version = get_option('wpinv_version', 0);
503 503
 
504
-		if ( $wpi_version == WPINV_VERSION ) {
504
+		if ($wpi_version == WPINV_VERSION) {
505 505
 			return;
506 506
 		}
507 507
 
508 508
 		$installer = new GetPaid_Installer();
509 509
 
510
-		if ( empty( $wpi_version ) ) {
511
-			return $installer->upgrade_db( 0 );
510
+		if (empty($wpi_version)) {
511
+			return $installer->upgrade_db(0);
512 512
 		}
513 513
 
514
-		$upgrades  = array(
514
+		$upgrades = array(
515 515
 			'0.0.5'  => '004',
516 516
 			'1.0.3'  => '102',
517 517
 			'2.0.0'  => '118',
@@ -519,10 +519,10 @@  discard block
 block discarded – undo
519 519
 			'2.6.16' => '2615',
520 520
 		);
521 521
 
522
-		foreach ( $upgrades as $key => $method ) {
522
+		foreach ($upgrades as $key => $method) {
523 523
 
524
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
525
-				return $installer->upgrade_db( $method );
524
+			if (version_compare($wpi_version, $key, '<')) {
525
+				return $installer->upgrade_db($method);
526 526
 			}
527 527
 		}
528 528
 
@@ -535,11 +535,11 @@  discard block
 block discarded – undo
535 535
 	 */
536 536
 	public function maybe_flush_permalinks() {
537 537
 
538
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
538
+		$flush = get_option('wpinv_flush_permalinks', 0);
539 539
 
540
-		if ( ! empty( $flush ) ) {
540
+		if (!empty($flush)) {
541 541
 			flush_rewrite_rules();
542
-			delete_option( 'wpinv_flush_permalinks' );
542
+			delete_option('wpinv_flush_permalinks');
543 543
 		}
544 544
 
545 545
 	}
@@ -550,10 +550,10 @@  discard block
 block discarded – undo
550 550
 	 * @since 1.0.19
551 551
 	 * @param int[] $excluded_posts_ids
552 552
 	 */
553
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
553
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
554 554
 
555 555
 		// Ensure that we have an array.
556
-		if ( ! is_array( $excluded_posts_ids ) ) {
556
+		if (!is_array($excluded_posts_ids)) {
557 557
 			$excluded_posts_ids = array();
558 558
 		}
559 559
 
@@ -561,24 +561,24 @@  discard block
 block discarded – undo
561 561
 		$our_pages = array();
562 562
 
563 563
 		// Checkout page.
564
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
564
+		$our_pages[] = wpinv_get_option('checkout_page', false);
565 565
 
566 566
 		// Success page.
567
-		$our_pages[] = wpinv_get_option( 'success_page', false );
567
+		$our_pages[] = wpinv_get_option('success_page', false);
568 568
 
569 569
 		// Failure page.
570
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
570
+		$our_pages[] = wpinv_get_option('failure_page', false);
571 571
 
572 572
 		// History page.
573
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
573
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
574 574
 
575 575
 		// Subscriptions page.
576
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
576
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
577 577
 
578
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
578
+		$our_pages   = array_map('intval', array_filter($our_pages));
579 579
 
580 580
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
581
-		return array_unique( $excluded_posts_ids );
581
+		return array_unique($excluded_posts_ids);
582 582
 
583 583
 	}
584 584
 
@@ -588,15 +588,15 @@  discard block
 block discarded – undo
588 588
 	 * @since 1.0.19
589 589
 	 * @param string[] $post_types
590 590
 	 */
591
-	public function exclude_invoicing_post_types( $post_types ) {
591
+	public function exclude_invoicing_post_types($post_types) {
592 592
 
593 593
 		// Ensure that we have an array.
594
-		if ( ! is_array( $post_types ) ) {
594
+		if (!is_array($post_types)) {
595 595
 			$post_types = array();
596 596
 		}
597 597
 
598 598
 		// Remove our post types.
599
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
599
+		return array_diff($post_types, array_keys(getpaid_get_invoice_post_types()));
600 600
 	}
601 601
 
602 602
 	/**
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 	 * @since 2.0.0
606 606
 	 */
607 607
 	public function wp_footer() {
608
-		wpinv_get_template( 'frontend-footer.php' );
608
+		wpinv_get_template('frontend-footer.php');
609 609
 	}
610 610
 
611 611
 	/**
@@ -614,14 +614,14 @@  discard block
 block discarded – undo
614 614
 	 * @since 2.0.0
615 615
 	 */
616 616
 	public function wp_head() {
617
-		wpinv_get_template( 'frontend-head.php' );
617
+		wpinv_get_template('frontend-head.php');
618 618
 	}
619 619
 
620 620
 	/**
621 621
 	 * Custom query vars.
622 622
 	 *
623 623
 	 */
624
-	public function custom_query_vars( $vars ) {
624
+	public function custom_query_vars($vars) {
625 625
         $vars[] = 'getpaid-ipn';
626 626
         return $vars;
627 627
 	}
@@ -632,28 +632,28 @@  discard block
 block discarded – undo
632 632
 	 */
633 633
 	public function add_rewrite_rule() {
634 634
         $tag = 'getpaid-ipn';
635
-        add_rewrite_tag( "%$tag%", '([^&]+)' );
636
-        add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
635
+        add_rewrite_tag("%$tag%", '([^&]+)');
636
+        add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top');
637 637
 	}
638 638
 
639 639
 	/**
640 640
 	 * Processes non-query string ipns.
641 641
 	 *
642 642
 	 */
643
-	public function maybe_process_new_ipn( $query ) {
643
+	public function maybe_process_new_ipn($query) {
644 644
 
645
-        if ( is_admin() || ! $query->is_main_query() ) {
645
+        if (is_admin() || !$query->is_main_query()) {
646 646
             return;
647 647
         }
648 648
 
649
-		$gateway = get_query_var( 'getpaid-ipn' );
649
+		$gateway = get_query_var('getpaid-ipn');
650 650
 
651
-        if ( ! empty( $gateway ) ) {
651
+        if (!empty($gateway)) {
652 652
 
653
-			$gateway = sanitize_text_field( $gateway );
653
+			$gateway = sanitize_text_field($gateway);
654 654
 			nocache_headers();
655
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
656
-			do_action( "wpinv_verify_{$gateway}_ipn" );
655
+			do_action('wpinv_verify_payment_ipn', $gateway);
656
+			do_action("wpinv_verify_{$gateway}_ipn");
657 657
 			exit;
658 658
 
659 659
         }
Please login to merge, or discard this patch.