Passed
Push — master ( ed9391...1afebe )
by Brian
05:14
created
includes/data/currency-symbols.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -11,166 +11,166 @@
 block discarded – undo
11 11
 defined( 'ABSPATH' ) || exit;
12 12
 
13 13
 return array(
14
-	'AED' => 'د.إ',
15
-	'AFN' => '؋',
16
-	'ALL' => 'L',
17
-	'AMD' => 'AMD',
18
-	'ANG' => 'ƒ',
19
-	'AOA' => 'Kz',
20
-	'ARS' => '$',
21
-	'AUD' => '$',
22
-	'AWG' => 'ƒ',
23
-	'AZN' => 'AZN',
24
-	'BAM' => 'KM',
25
-	'BBD' => '$',
26
-	'BDT' => '৳',
27
-	'BGN' => 'лв.',
28
-	'BHD' => '.د.ب',
29
-	'BIF' => 'Fr',
30
-	'BMD' => '$',
31
-	'BND' => '$',
32
-	'BOB' => 'Bs.',
33
-	'BRL' => 'R$',
34
-	'BSD' => '$',
35
-	'BTC' => '฿',
36
-	'BTN' => 'Nu.',
37
-	'BWP' => 'P',
38
-	'BYN' => 'Br',
39
-	'BZD' => '$',
40
-	'CAD' => '$',
41
-	'CDF' => 'Fr',
42
-	'CHF' => 'CHF',
43
-	'CLP' => '$',
44
-	'CNY' => '¥',
45
-	'COP' => '$',
46
-	'CRC' => '₡',
47
-	'CUC' => '$',
48
-	'CUP' => '$',
49
-	'CVE' => '$',
50
-	'CZK' => 'Kč',
51
-	'DJF' => 'Fr',
52
-	'DKK' => 'DKK',
53
-	'DOP' => 'RD$',
54
-	'DZD' => 'د.ج',
55
-	'EGP' => 'EGP',
56
-	'ERN' => 'Nfk',
57
-	'ETB' => 'Br',
58
-	'EUR' => '€',
59
-	'FJD' => '$',
60
-	'FKP' => '£',
61
-	'GBP' => '£',
62
-	'GEL' => 'ლ',
63
-	'GGP' => '£',
64
-	'GHS' => '₵',
65
-	'GIP' => '£',
66
-	'GMD' => 'D',
67
-	'GNF' => 'Fr',
68
-	'GTQ' => 'Q',
69
-	'GYD' => '$',
70
-	'HKD' => '$',
71
-	'HNL' => 'L',
72
-	'HRK' => 'Kn',
73
-	'HTG' => 'G',
74
-	'HUF' => 'Ft',
75
-	'IDR' => 'Rp',
76
-	'ILS' => '₪',
77
-	'IMP' => '£',
78
-	'INR' => '₹',
79
-	'IQD' => 'ع.د',
80
-	'IRR' => '﷼',
81
-	'IRT' => 'تومان',
82
-	'ISK' => 'kr.',
83
-	'JEP' => '£',
84
-	'JMD' => '$',
85
-	'JOD' => 'د.ا',
86
-	'JPY' => '¥',
87
-	'KES' => 'KSh',
88
-	'KGS' => 'сом',
89
-	'KHR' => '៛',
90
-	'KMF' => 'Fr',
91
-	'KPW' => '₩',
92
-	'KRW' => '₩',
93
-	'KWD' => 'د.ك',
94
-	'KYD' => '$',
95
-	'KZT' => 'KZT',
96
-	'LAK' => '₭',
97
-	'LBP' => 'ل.ل',
98
-	'LKR' => 'රු',
99
-	'LRD' => '$',
100
-	'LSL' => 'L',
101
-	'LYD' => 'ل.د',
102
-	'MAD' => 'د.م.',
103
-	'MDL' => 'MDL',
104
-	'MGA' => 'Ar',
105
-	'MKD' => 'ден',
106
-	'MMK' => 'Ks',
107
-	'MNT' => '₮',
108
-	'MOP' => 'P',
109
-	'MRO' => 'UM',
110
-	'MUR' => '₨',
111
-	'MVR' => '.ރ',
112
-	'MWK' => 'MK',
113
-	'MXN' => '$',
114
-	'MYR' => 'RM',
115
-	'MZN' => 'MT',
116
-	'NAD' => 'N$',
117
-	'NGN' => '₦',
118
-	'NIO' => 'C$',
119
-	'NOK' => 'kr',
120
-	'NPR' => '₨',
121
-	'NZD' => '$',
122
-	'OMR' => 'ر.ع.',
123
-	'PAB' => 'B/.',
124
-	'PEN' => 'S/.',
125
-	'PGK' => 'K',
126
-	'PHP' => '₱',
127
-	'PKR' => '₨',
128
-	'PLN' => 'zł',
129
-	'PRB' => 'р.',
130
-	'PYG' => '₲',
131
-	'QAR' => 'ر.ق',
132
-	'RMB' => '¥',
133
-	'RON' => 'lei',
134
-	'RSD' => 'дин.',
135
-	'RUB' => '₽',
136
-	'RWF' => 'Fr',
137
-	'SAR' => 'ر.س',
138
-	'SBD' => '$',
139
-	'SCR' => '₨',
140
-	'SDG' => 'ج.س.',
141
-	'SEK' => 'kr',
142
-	'SGD' => '$',
143
-	'SHP' => '£',
144
-	'SLL' => 'Le',
145
-	'SOS' => 'Sh',
146
-	'SRD' => '$',
147
-	'SSP' => '£',
148
-	'STD' => 'Db',
149
-	'SYP' => 'ل.س',
150
-	'SZL' => 'L',
151
-	'THB' => '฿',
152
-	'TJS' => 'ЅМ',
153
-	'TMT' => 'm',
154
-	'TND' => 'د.ت',
155
-	'TOP' => 'T$',
156
-	'TRY' => '₺',
157
-	'TTD' => '$',
158
-	'TWD' => 'NT$',
159
-	'TZS' => 'Sh',
160
-	'UAH' => '₴',
161
-	'UGX' => 'UGX',
162
-	'USD' => '$',
163
-	'UYU' => '$',
164
-	'UZS' => 'UZS',
165
-	'VEF' => 'Bs.',
166
-	'VND' => '₫',
167
-	'VUV' => 'Vt',
168
-	'WST' => 'T',
169
-	'XAF' => 'Fr',
170
-	'XCD' => '$',
171
-	'XOF' => 'Fr',
172
-	'XPF' => 'Fr',
173
-	'YER' => '﷼',
174
-	'ZAR' => 'R',
175
-	'ZMW' => 'ZK',
14
+    'AED' => 'د.إ',
15
+    'AFN' => '؋',
16
+    'ALL' => 'L',
17
+    'AMD' => 'AMD',
18
+    'ANG' => 'ƒ',
19
+    'AOA' => 'Kz',
20
+    'ARS' => '$',
21
+    'AUD' => '$',
22
+    'AWG' => 'ƒ',
23
+    'AZN' => 'AZN',
24
+    'BAM' => 'KM',
25
+    'BBD' => '$',
26
+    'BDT' => '৳',
27
+    'BGN' => 'лв.',
28
+    'BHD' => '.د.ب',
29
+    'BIF' => 'Fr',
30
+    'BMD' => '$',
31
+    'BND' => '$',
32
+    'BOB' => 'Bs.',
33
+    'BRL' => 'R$',
34
+    'BSD' => '$',
35
+    'BTC' => '฿',
36
+    'BTN' => 'Nu.',
37
+    'BWP' => 'P',
38
+    'BYN' => 'Br',
39
+    'BZD' => '$',
40
+    'CAD' => '$',
41
+    'CDF' => 'Fr',
42
+    'CHF' => 'CHF',
43
+    'CLP' => '$',
44
+    'CNY' => '¥',
45
+    'COP' => '$',
46
+    'CRC' => '₡',
47
+    'CUC' => '$',
48
+    'CUP' => '$',
49
+    'CVE' => '$',
50
+    'CZK' => 'Kč',
51
+    'DJF' => 'Fr',
52
+    'DKK' => 'DKK',
53
+    'DOP' => 'RD$',
54
+    'DZD' => 'د.ج',
55
+    'EGP' => 'EGP',
56
+    'ERN' => 'Nfk',
57
+    'ETB' => 'Br',
58
+    'EUR' => '€',
59
+    'FJD' => '$',
60
+    'FKP' => '£',
61
+    'GBP' => '£',
62
+    'GEL' => 'ლ',
63
+    'GGP' => '£',
64
+    'GHS' => '₵',
65
+    'GIP' => '£',
66
+    'GMD' => 'D',
67
+    'GNF' => 'Fr',
68
+    'GTQ' => 'Q',
69
+    'GYD' => '$',
70
+    'HKD' => '$',
71
+    'HNL' => 'L',
72
+    'HRK' => 'Kn',
73
+    'HTG' => 'G',
74
+    'HUF' => 'Ft',
75
+    'IDR' => 'Rp',
76
+    'ILS' => '₪',
77
+    'IMP' => '£',
78
+    'INR' => '₹',
79
+    'IQD' => 'ع.د',
80
+    'IRR' => '﷼',
81
+    'IRT' => 'تومان',
82
+    'ISK' => 'kr.',
83
+    'JEP' => '£',
84
+    'JMD' => '$',
85
+    'JOD' => 'د.ا',
86
+    'JPY' => '¥',
87
+    'KES' => 'KSh',
88
+    'KGS' => 'сом',
89
+    'KHR' => '៛',
90
+    'KMF' => 'Fr',
91
+    'KPW' => '₩',
92
+    'KRW' => '₩',
93
+    'KWD' => 'د.ك',
94
+    'KYD' => '$',
95
+    'KZT' => 'KZT',
96
+    'LAK' => '₭',
97
+    'LBP' => 'ل.ل',
98
+    'LKR' => 'රු',
99
+    'LRD' => '$',
100
+    'LSL' => 'L',
101
+    'LYD' => 'ل.د',
102
+    'MAD' => 'د.م.',
103
+    'MDL' => 'MDL',
104
+    'MGA' => 'Ar',
105
+    'MKD' => 'ден',
106
+    'MMK' => 'Ks',
107
+    'MNT' => '₮',
108
+    'MOP' => 'P',
109
+    'MRO' => 'UM',
110
+    'MUR' => '₨',
111
+    'MVR' => '.ރ',
112
+    'MWK' => 'MK',
113
+    'MXN' => '$',
114
+    'MYR' => 'RM',
115
+    'MZN' => 'MT',
116
+    'NAD' => 'N$',
117
+    'NGN' => '₦',
118
+    'NIO' => 'C$',
119
+    'NOK' => 'kr',
120
+    'NPR' => '₨',
121
+    'NZD' => '$',
122
+    'OMR' => 'ر.ع.',
123
+    'PAB' => 'B/.',
124
+    'PEN' => 'S/.',
125
+    'PGK' => 'K',
126
+    'PHP' => '₱',
127
+    'PKR' => '₨',
128
+    'PLN' => 'zł',
129
+    'PRB' => 'р.',
130
+    'PYG' => '₲',
131
+    'QAR' => 'ر.ق',
132
+    'RMB' => '¥',
133
+    'RON' => 'lei',
134
+    'RSD' => 'дин.',
135
+    'RUB' => '₽',
136
+    'RWF' => 'Fr',
137
+    'SAR' => 'ر.س',
138
+    'SBD' => '$',
139
+    'SCR' => '₨',
140
+    'SDG' => 'ج.س.',
141
+    'SEK' => 'kr',
142
+    'SGD' => '$',
143
+    'SHP' => '£',
144
+    'SLL' => 'Le',
145
+    'SOS' => 'Sh',
146
+    'SRD' => '$',
147
+    'SSP' => '£',
148
+    'STD' => 'Db',
149
+    'SYP' => 'ل.س',
150
+    'SZL' => 'L',
151
+    'THB' => '฿',
152
+    'TJS' => 'ЅМ',
153
+    'TMT' => 'm',
154
+    'TND' => 'د.ت',
155
+    'TOP' => 'T$',
156
+    'TRY' => '₺',
157
+    'TTD' => '$',
158
+    'TWD' => 'NT$',
159
+    'TZS' => 'Sh',
160
+    'UAH' => '₴',
161
+    'UGX' => 'UGX',
162
+    'USD' => '$',
163
+    'UYU' => '$',
164
+    'UZS' => 'UZS',
165
+    'VEF' => 'Bs.',
166
+    'VND' => '₫',
167
+    'VUV' => 'Vt',
168
+    'WST' => 'T',
169
+    'XAF' => 'Fr',
170
+    'XCD' => '$',
171
+    'XOF' => 'Fr',
172
+    'XPF' => 'Fr',
173
+    'YER' => '﷼',
174
+    'ZAR' => 'R',
175
+    'ZMW' => 'ZK',
176 176
 );
Please login to merge, or discard this patch.
includes/subscription-functions.php 1 patch
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
  */
51 51
 function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52 52
     $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
53
+    $matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54 54
     return reset( $matching_group );
55 55
 }
56 56
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
  */
64 64
 function getpaid_get_subscription( $subscription ) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
68
-	}
66
+    if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
+        $subscription = new WPInv_Subscription( $subscription );
68
+    }
69 69
 
70
-	return $subscription->exists() ? $subscription : false;
70
+    return $subscription->exists() ? $subscription : false;
71 71
 }
72 72
 
73 73
 /**
@@ -81,28 +81,28 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
83 83
 
84
-	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
86
-		$args['fields'] = 'id';
87
-		$args['number'] = 1;
88
-	}
84
+    // Do not retrieve all fields if we just want the count.
85
+    if ( 'count' == $return ) {
86
+        $args['fields'] = 'id';
87
+        $args['number'] = 1;
88
+    }
89 89
 
90
-	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
92
-		$args['count_total'] = false;
93
-	}
90
+    // Do not count all matches if we just want the results.
91
+    if ( 'results' == $return ) {
92
+        $args['count_total'] = false;
93
+    }
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+    $query = new GetPaid_Subscriptions_Query( $args );
96 96
 
97
-	if ( 'results' == $return ) {
98
-		return $query->get_results();
99
-	}
97
+    if ( 'results' == $return ) {
98
+        return $query->get_results();
99
+    }
100 100
 
101
-	if ( 'count' == $return ) {
102
-		return $query->get_total();
103
-	}
101
+    if ( 'count' == $return ) {
102
+        return $query->get_total();
103
+    }
104 104
 
105
-	return $query;
105
+    return $query;
106 106
 }
107 107
 
108 108
 /**
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function getpaid_get_subscription_statuses() {
114 114
 
115
-	return apply_filters(
116
-		'getpaid_get_subscription_statuses',
117
-		array(
118
-			'pending'   => __( 'Pending', 'invoicing' ),
119
-			'trialling' => __( 'Trialing', 'invoicing' ),
120
-			'active'    => __( 'Active', 'invoicing' ),
121
-			'failing'   => __( 'Failing', 'invoicing' ),
122
-			'expired'   => __( 'Expired', 'invoicing' ),
123
-			'completed' => __( 'Complete', 'invoicing' ),
124
-			'cancelled' => __( 'Cancelled', 'invoicing' ),
125
-		)
126
-	);
115
+    return apply_filters(
116
+        'getpaid_get_subscription_statuses',
117
+        array(
118
+            'pending'   => __( 'Pending', 'invoicing' ),
119
+            'trialling' => __( 'Trialing', 'invoicing' ),
120
+            'active'    => __( 'Active', 'invoicing' ),
121
+            'failing'   => __( 'Failing', 'invoicing' ),
122
+            'expired'   => __( 'Expired', 'invoicing' ),
123
+            'completed' => __( 'Complete', 'invoicing' ),
124
+            'cancelled' => __( 'Cancelled', 'invoicing' ),
125
+        )
126
+    );
127 127
 
128 128
 }
129 129
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
  * @return string
134 134
  */
135 135
 function getpaid_get_subscription_status_label( $status ) {
136
-	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
136
+    $statuses = getpaid_get_subscription_statuses();
137
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
138 138
 }
139 139
 
140 140
 /**
@@ -144,18 +144,18 @@  discard block
 block discarded – undo
144 144
  */
145 145
 function getpaid_get_subscription_status_classes() {
146 146
 
147
-	return apply_filters(
148
-		'getpaid_get_subscription_status_classes',
149
-		array(
150
-			'pending'   => 'badge-dark',
151
-			'trialling' => 'badge-info',
152
-			'active'    => 'badge-success',
153
-			'failing'   => 'badge-warning',
154
-			'expired'   => 'badge-danger',
155
-			'completed' => 'badge-primary',
156
-			'cancelled' => 'badge-secondary',
157
-		)
158
-	);
147
+    return apply_filters(
148
+        'getpaid_get_subscription_status_classes',
149
+        array(
150
+            'pending'   => 'badge-dark',
151
+            'trialling' => 'badge-info',
152
+            'active'    => 'badge-success',
153
+            'failing'   => 'badge-warning',
154
+            'expired'   => 'badge-danger',
155
+            'completed' => 'badge-primary',
156
+            'cancelled' => 'badge-secondary',
157
+        )
158
+    );
159 159
 
160 160
 }
161 161
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function getpaid_get_subscription_status_counts( $args = array() ) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
170
-	$counts   = array();
169
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
170
+    $counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
-	}
172
+    foreach ( $statuses as $status ) {
173
+        $_args             = wp_parse_args( "status=$status", $args );
174
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
+    }
176 176
 
177
-	return $counts;
177
+    return $counts;
178 178
 
179 179
 }
180 180
 
@@ -185,32 +185,32 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function getpaid_get_subscription_periods() {
187 187
 
188
-	return apply_filters(
189
-		'getpaid_get_subscription_periods',
190
-		array(
188
+    return apply_filters(
189
+        'getpaid_get_subscription_periods',
190
+        array(
191 191
 
192
-			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
195
-			),
192
+            'day'   => array(
193
+                'singular' => __( '%s day', 'invoicing' ),
194
+                'plural'   => __( '%d days', 'invoicing' ),
195
+            ),
196 196
 
197
-			'week'  => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
200
-			),
197
+            'week'  => array(
198
+                'singular' => __( '%s week', 'invoicing' ),
199
+                'plural'   => __( '%d weeks', 'invoicing' ),
200
+            ),
201 201
 
202
-			'month' => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
205
-			),
202
+            'month' => array(
203
+                'singular' => __( '%s month', 'invoicing' ),
204
+                'plural'   => __( '%d months', 'invoicing' ),
205
+            ),
206 206
 
207
-			'year'  => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
210
-			),
207
+            'year'  => array(
208
+                'singular' => __( '%s year', 'invoicing' ),
209
+                'plural'   => __( '%d years', 'invoicing' ),
210
+            ),
211 211
 
212
-		)
213
-	);
212
+        )
213
+    );
214 214
 
215 215
 }
216 216
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
  * @return int
222 222
  */
223 223
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
224
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
225 225
 }
226 226
 
227 227
 /**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
  * @return string
232 232
  */
233 233
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
234
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
235 235
 }
236 236
 
237 237
 /**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
  * @return string
243 243
  */
244 244
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
245
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
+    return strtolower( sanitize_text_field( $label ) );
247 247
 }
248 248
 
249 249
 /**
@@ -254,22 +254,22 @@  discard block
 block discarded – undo
254 254
  */
255 255
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
256 256
 
257
-	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
257
+    $periods = getpaid_get_subscription_periods();
258
+    $period  = strtolower( $period );
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
-	}
260
+    if ( isset( $periods[ $period ] ) ) {
261
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
+    }
263 263
 
264
-	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
268
-		}
269
-	}
264
+    // Backwards compatibility.
265
+    foreach ( $periods as $key => $data ) {
266
+        if ( strpos( $key, $period ) === 0 ) {
267
+            return sprintf( $data['singular'], $singular_prefix );
268
+        }
269
+    }
270 270
 
271
-	// Invalid string.
272
-	return '';
271
+    // Invalid string.
272
+    return '';
273 273
 }
274 274
 
275 275
 /**
@@ -281,22 +281,22 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
283 283
 
284
-	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
284
+    $periods = getpaid_get_subscription_periods();
285
+    $period  = strtolower( $period );
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
289
-	}
287
+    if ( isset( $periods[ $period ] ) ) {
288
+        return sprintf( $periods[ $period ]['plural'], $interval );
289
+    }
290 290
 
291
-	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
295
-		}
296
-	}
291
+    // Backwards compatibility.
292
+    foreach ( $periods as $key => $data ) {
293
+        if ( strpos( $key, $period ) === 0 ) {
294
+            return sprintf( $data['plural'], $interval );
295
+        }
296
+    }
297 297
 
298
-	// Invalid string.
299
-	return '';
298
+    // Invalid string.
299
+    return '';
300 300
 }
301 301
 
302 302
 /**
@@ -307,92 +307,92 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function getpaid_get_formatted_subscription_amount( $subscription ) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
-	$bill_times = $subscription->get_bill_times();
314
-	$bill_times_less = $bill_times - 1;
315
-
316
-	if ( ! empty( $bill_times ) ) {
317
-		$bill_times = $subscription->get_frequency() * $bill_times;
318
-		$bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() );
319
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
320
-	}
321
-
322
-	// Trial periods.
323
-	if ( $subscription->has_trial_period() ) {
324
-
325
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
326
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
327
-
328
-		if ( empty( $bill_times ) ) {
329
-
330
-			return sprintf(
331
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
332
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
333
-				$initial,
334
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
335
-				$recurring,
336
-				$period
337
-			);
338
-
339
-		}
340
-
341
-		return sprintf(
342
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
343
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
344
-			$initial,
345
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
346
-			$recurring,
347
-			$period,
348
-			$bill_times
349
-		);
350
-
351
-	}
352
-
353
-	if ( $initial != $recurring ) {
354
-
355
-		if ( empty( $bill_times ) ) {
356
-
357
-			return sprintf(
358
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
359
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
360
-				$initial,
361
-				$recurring,
362
-				$period
363
-			);
364
-
365
-		}
366
-
367
-		return sprintf(
368
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
369
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
370
-			$initial,
371
-			$recurring,
372
-			$period,
373
-			$bill_times_less
374
-		);
375
-
376
-	}
377
-
378
-	if ( empty( $bill_times ) ) {
379
-
380
-		return sprintf(
381
-			// translators: $1: is the recurring amount, $2: is the recurring period
382
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
383
-			$initial,
384
-			$period
385
-		);
386
-
387
-	}
388
-
389
-	return sprintf(
390
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
391
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
392
-		$bill_times,
393
-		$initial,
394
-		$period
395
-	);
310
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
+    $bill_times = $subscription->get_bill_times();
314
+    $bill_times_less = $bill_times - 1;
315
+
316
+    if ( ! empty( $bill_times ) ) {
317
+        $bill_times = $subscription->get_frequency() * $bill_times;
318
+        $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() );
319
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
320
+    }
321
+
322
+    // Trial periods.
323
+    if ( $subscription->has_trial_period() ) {
324
+
325
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
326
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
327
+
328
+        if ( empty( $bill_times ) ) {
329
+
330
+            return sprintf(
331
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
332
+                _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
333
+                $initial,
334
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
335
+                $recurring,
336
+                $period
337
+            );
338
+
339
+        }
340
+
341
+        return sprintf(
342
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
343
+            _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
344
+            $initial,
345
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
346
+            $recurring,
347
+            $period,
348
+            $bill_times
349
+        );
350
+
351
+    }
352
+
353
+    if ( $initial != $recurring ) {
354
+
355
+        if ( empty( $bill_times ) ) {
356
+
357
+            return sprintf(
358
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
359
+                _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
360
+                $initial,
361
+                $recurring,
362
+                $period
363
+            );
364
+
365
+        }
366
+
367
+        return sprintf(
368
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
369
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
370
+            $initial,
371
+            $recurring,
372
+            $period,
373
+            $bill_times_less
374
+        );
375
+
376
+    }
377
+
378
+    if ( empty( $bill_times ) ) {
379
+
380
+        return sprintf(
381
+            // translators: $1: is the recurring amount, $2: is the recurring period
382
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
383
+            $initial,
384
+            $period
385
+        );
386
+
387
+    }
388
+
389
+    return sprintf(
390
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
391
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
392
+        $bill_times,
393
+        $initial,
394
+        $period
395
+    );
396 396
 
397 397
 }
398 398
 
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
  * @return WPInv_Subscription|false
404 404
  */
405 405
 function getpaid_get_invoice_subscription( $invoice ) {
406
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
406
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
407 407
 }
408 408
 
409 409
 /**
@@ -412,10 +412,10 @@  discard block
 block discarded – undo
412 412
  * @param WPInv_Invoice $invoice
413 413
  */
414 414
 function getpaid_activate_invoice_subscription( $invoice ) {
415
-	$subscription = getpaid_get_invoice_subscription( $invoice );
416
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
417
-		$subscription->activate();
418
-	}
415
+    $subscription = getpaid_get_invoice_subscription( $invoice );
416
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
417
+        $subscription->activate();
418
+    }
419 419
 }
420 420
 
421 421
 /**
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
  * @return WPInv_Subscriptions
425 425
  */
426 426
 function getpaid_subscriptions() {
427
-	return getpaid()->get( 'subscriptions' );
427
+    return getpaid()->get( 'subscriptions' );
428 428
 }
429 429
 
430 430
 /**
@@ -443,15 +443,15 @@  discard block
 block discarded – undo
443 443
         return false;
444 444
     }
445 445
 
446
-	// Fetch the invoice subscription.
447
-	$subscription = getpaid_get_subscriptions(
448
-		array(
449
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
450
-			'number'     => 1,
451
-		)
452
-	);
446
+    // Fetch the invoice subscription.
447
+    $subscription = getpaid_get_subscriptions(
448
+        array(
449
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
450
+            'number'     => 1,
451
+        )
452
+    );
453 453
 
454
-	return empty( $subscription ) ? false : $subscription[0];
454
+    return empty( $subscription ) ? false : $subscription[0];
455 455
 
456 456
 }
457 457
 
@@ -468,48 +468,48 @@  discard block
 block discarded – undo
468 468
  */
469 469
 function getpaid_get_recurring_item_key( $cart_item ) {
470 470
 
471
-	$cart_key     = 'renews_';
472
-	$interval     = $cart_item->get_recurring_interval();
473
-	$period       = $cart_item->get_recurring_period( true );
474
-	$length       = $cart_item->get_recurring_limit() * $interval;
475
-	$trial_period = $cart_item->get_trial_period( true );
476
-	$trial_length = $cart_item->get_trial_interval();
477
-
478
-	// First start with the billing interval and period
479
-	switch ( $interval ) {
480
-		case 1:
481
-			if ( 'day' == $period ) {
482
-				$cart_key .= 'daily';
483
-			} else {
484
-				$cart_key .= sprintf( '%sly', $period );
485
-			}
486
-			break;
487
-		case 2:
488
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
489
-			break;
490
-		case 3:
491
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
492
-		    break;
493
-		default:
494
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
495
-			break;
496
-	}
497
-
498
-	// Maybe add the optional maximum billing periods...
499
-	if ( $length > 0 ) {
500
-		$cart_key .= '_for_';
501
-		$cart_key .= sprintf( '%d_%s', $length, $period );
502
-		if ( $length > 1 ) {
503
-			$cart_key .= 's';
504
-		}
505
-	}
506
-
507
-	// And an optional free trial.
508
-	if ( $cart_item->has_free_trial() ) {
509
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
510
-	}
511
-
512
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
471
+    $cart_key     = 'renews_';
472
+    $interval     = $cart_item->get_recurring_interval();
473
+    $period       = $cart_item->get_recurring_period( true );
474
+    $length       = $cart_item->get_recurring_limit() * $interval;
475
+    $trial_period = $cart_item->get_trial_period( true );
476
+    $trial_length = $cart_item->get_trial_interval();
477
+
478
+    // First start with the billing interval and period
479
+    switch ( $interval ) {
480
+        case 1:
481
+            if ( 'day' == $period ) {
482
+                $cart_key .= 'daily';
483
+            } else {
484
+                $cart_key .= sprintf( '%sly', $period );
485
+            }
486
+            break;
487
+        case 2:
488
+            $cart_key .= sprintf( 'every_2nd_%s', $period );
489
+            break;
490
+        case 3:
491
+            $cart_key .= sprintf( 'every_3rd_%s', $period );
492
+            break;
493
+        default:
494
+            $cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
495
+            break;
496
+    }
497
+
498
+    // Maybe add the optional maximum billing periods...
499
+    if ( $length > 0 ) {
500
+        $cart_key .= '_for_';
501
+        $cart_key .= sprintf( '%d_%s', $length, $period );
502
+        if ( $length > 1 ) {
503
+            $cart_key .= 's';
504
+        }
505
+    }
506
+
507
+    // And an optional free trial.
508
+    if ( $cart_item->has_free_trial() ) {
509
+        $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
510
+    }
511
+
512
+    return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
513 513
 }
514 514
 
515 515
 /**
@@ -520,16 +520,16 @@  discard block
 block discarded – undo
520 520
  */
521 521
 function getpaid_get_subscription_groups( $invoice ) {
522 522
 
523
-	// Generate subscription groups.
524
-	$subscription_groups = array();
525
-	foreach ( $invoice->get_items() as $item ) {
523
+    // Generate subscription groups.
524
+    $subscription_groups = array();
525
+    foreach ( $invoice->get_items() as $item ) {
526 526
 
527
-		if ( $item->is_recurring() ) {
528
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
529
-		}
527
+        if ( $item->is_recurring() ) {
528
+            $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
529
+        }
530 530
 }
531 531
 
532
-	return $subscription_groups;
532
+    return $subscription_groups;
533 533
 }
534 534
 
535 535
 /**
@@ -543,56 +543,56 @@  discard block
 block discarded – undo
543 543
  */
544 544
 function getpaid_calculate_subscription_totals( $invoice ) {
545 545
 
546
-	// Generate subscription groups.
547
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
546
+    // Generate subscription groups.
547
+    $subscription_groups = getpaid_get_subscription_groups( $invoice );
548 548
 
549
-	// Now let's calculate the totals for each group of subscriptions
550
-	$subscription_totals = array();
549
+    // Now let's calculate the totals for each group of subscriptions
550
+    $subscription_totals = array();
551 551
 
552
-	foreach ( $subscription_groups as $subscription_key => $items ) {
552
+    foreach ( $subscription_groups as $subscription_key => $items ) {
553 553
 
554
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
554
+        if ( empty( $subscription_totals[ $subscription_key ] ) ) {
555 555
 
556
-			$subscription_totals[ $subscription_key ] = array(
557
-				'initial_total'   => 0,
558
-				'recurring_total' => 0,
559
-				'items'           => array(),
560
-				'trialling'       => false,
561
-			);
556
+            $subscription_totals[ $subscription_key ] = array(
557
+                'initial_total'   => 0,
558
+                'recurring_total' => 0,
559
+                'items'           => array(),
560
+                'trialling'       => false,
561
+            );
562 562
 
563
-		}
563
+        }
564 564
 
565
-		/**
566
-		 * Get the totals of the group.
567
-		 * @var GetPaid_Form_Item $item
568
-		 */
569
-		foreach ( $items as $item ) {
565
+        /**
566
+         * Get the totals of the group.
567
+         * @var GetPaid_Form_Item $item
568
+         */
569
+        foreach ( $items as $item ) {
570 570
 
571
-			$subscription_totals[ $subscription_key ]['items'][ $item->get_id() ]  = $item->prepare_data_for_saving();
572
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
573
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
574
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
575
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
576
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
577
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
571
+            $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ]  = $item->prepare_data_for_saving();
572
+            $subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
573
+            $subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
574
+            $subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
575
+            $subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
576
+            $subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
577
+            $subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
578 578
 
579
-			// Calculate the next renewal date.
580
-			$period       = $item->get_recurring_period( true );
581
-			$interval     = $item->get_recurring_interval();
579
+            // Calculate the next renewal date.
580
+            $period       = $item->get_recurring_period( true );
581
+            $interval     = $item->get_recurring_interval();
582 582
 
583
-			// If the subscription item has a trial period...
584
-			if ( $item->has_free_trial() ) {
585
-				$period   = $item->get_trial_period( true );
586
-				$interval = $item->get_trial_interval();
587
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
588
-			}
583
+            // If the subscription item has a trial period...
584
+            if ( $item->has_free_trial() ) {
585
+                $period   = $item->get_trial_period( true );
586
+                $interval = $item->get_trial_interval();
587
+                $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
588
+            }
589 589
 
590
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
590
+            $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
591 591
 
592
-		}
592
+        }
593 593
 }
594 594
 
595
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
595
+    return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
596 596
 }
597 597
 
598 598
 /**
@@ -603,16 +603,16 @@  discard block
 block discarded – undo
603 603
  */
604 604
 function getpaid_should_group_subscriptions( $invoice ) {
605 605
 
606
-	$recurring_items = 0;
606
+    $recurring_items = 0;
607 607
 
608
-	foreach ( $invoice->get_items() as $item ) {
608
+    foreach ( $invoice->get_items() as $item ) {
609 609
 
610
-		if ( $item->is_recurring() ) {
611
-			$recurring_items ++;
612
-		}
610
+        if ( $item->is_recurring() ) {
611
+            $recurring_items ++;
612
+        }
613 613
 }
614 614
 
615
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
615
+    return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
616 616
 }
617 617
 
618 618
 /**
@@ -623,39 +623,39 @@  discard block
 block discarded – undo
623 623
  * @return int
624 624
  */
625 625
 function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
626
-	global $wpdb;
626
+    global $wpdb;
627 627
 
628
-	$parent_invoice_id = (int) $parent_invoice_id;
628
+    $parent_invoice_id = (int) $parent_invoice_id;
629 629
 
630
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
630
+    if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
631 631
 
632
-		return (int) $wpdb->get_var(
633
-			$wpdb->prepare(
634
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
635
-				$parent_invoice_id,
636
-				$parent_invoice_id
637
-			)
638
-		);
632
+        return (int) $wpdb->get_var(
633
+            $wpdb->prepare(
634
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
635
+                $parent_invoice_id,
636
+                $parent_invoice_id
637
+            )
638
+        );
639 639
 
640
-	}
640
+    }
641 641
 
642
-	$invoice_ids = $wpdb->get_col(
643
-		$wpdb->prepare(
644
-			"SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
645
-			$parent_invoice_id,
646
-			$parent_invoice_id
647
-		)
648
-	);
642
+    $invoice_ids = $wpdb->get_col(
643
+        $wpdb->prepare(
644
+            "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
645
+            $parent_invoice_id,
646
+            $parent_invoice_id
647
+        )
648
+    );
649 649
 
650
-	$count = 0;
650
+    $count = 0;
651 651
 
652
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
652
+    foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
653 653
 
654
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
655
-			$count ++;
656
-			continue;
657
-		}
654
+        if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
655
+            $count ++;
656
+            continue;
657
+        }
658 658
 }
659 659
 
660
-	return $count;
660
+    return $count;
661 661
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
     $args = wp_parse_args(
58 58
         $args,
59 59
         array(
60
-			'status'     => array( 'publish' ),
61
-			'limit'      => get_option( 'posts_per_page' ),
62
-			'page'       => 1,
63
-			'exclude'    => array(),
64
-			'orderby'    => 'date',
65
-			'order'      => 'DESC',
66
-			'type'       => wpinv_item_types(),
67
-			'meta_query' => array(),
68
-			'return'     => 'objects',
69
-			'paginate'   => false,
60
+            'status'     => array( 'publish' ),
61
+            'limit'      => get_option( 'posts_per_page' ),
62
+            'page'       => 1,
63
+            'exclude'    => array(),
64
+            'orderby'    => 'date',
65
+            'order'      => 'DESC',
66
+            'type'       => wpinv_item_types(),
67
+            'meta_query' => array(),
68
+            'return'     => 'objects',
69
+            'paginate'   => false,
70 70
         )
71 71
     );
72 72
 
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 
207 207
 function wpinv_get_item_types() {
208 208
     $item_types = array(
209
-		'custom' => __( 'Standard', 'invoicing' ),
210
-		'fee'    => __( 'Fee', 'invoicing' ),
211
-	);
209
+        'custom' => __( 'Standard', 'invoicing' ),
210
+        'fee'    => __( 'Fee', 'invoicing' ),
211
+    );
212 212
     return apply_filters( 'wpinv_get_item_types', $item_types );
213 213
 }
214 214
 
@@ -249,17 +249,17 @@  discard block
 block discarded – undo
249 249
 function wpinv_get_random_items( $num = 3, $post_ids = true ) {
250 250
     if ( $post_ids ) {
251 251
         $args = array(
252
-			'post_type'  => 'wpi_item',
253
-			'orderby'    => 'rand',
254
-			'post_count' => $num,
255
-			'fields'     => 'ids',
256
-		);
252
+            'post_type'  => 'wpi_item',
253
+            'orderby'    => 'rand',
254
+            'post_count' => $num,
255
+            'fields'     => 'ids',
256
+        );
257 257
     } else {
258 258
         $args = array(
259
-			'post_type'  => 'wpi_item',
260
-			'orderby'    => 'rand',
261
-			'post_count' => $num,
262
-		);
259
+            'post_type'  => 'wpi_item',
260
+            'orderby'    => 'rand',
261
+            'post_count' => $num,
262
+        );
263 263
     }
264 264
 
265 265
     $args  = apply_filters( 'wpinv_get_random_items', $args );
@@ -427,10 +427,10 @@  discard block
 block discarded – undo
427 427
     $bill_times_less = $bill_times - 1;
428 428
 
429 429
     if ( ! empty( $bill_times ) ) {
430
-		$bill_times = $item->get_recurring_interval() * $bill_times;
430
+        $bill_times = $item->get_recurring_interval() * $bill_times;
431 431
         $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() );
432
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
433
-	}
432
+        $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
433
+    }
434 434
 
435 435
     if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
436 436
         $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
Please login to merge, or discard this patch.
templates/payment-forms/elements/date.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -12,59 +12,59 @@
 block discarded – undo
12 12
 $label       = empty( $label ) ? '' : wp_kses_post( $label );
13 13
 $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
14 14
 if ( ! empty( $required ) ) {
15
-	$label .= "<span class='text-danger'> *</span>";
15
+    $label .= "<span class='text-danger'> *</span>";
16 16
 }
17 17
 
18 18
 $disable_dates = array();
19 19
 
20 20
 if ( ! empty( $disabled_dates ) ) {
21
-	$disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
-	$disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
-	$disabled_dates = array_filter( explode( ',', $disabled_dates ) );
21
+    $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
+    $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
+    $disabled_dates = array_filter( explode( ',', $disabled_dates ) );
24 24
 
25
-	foreach ( $disabled_dates as $disabled_date ) {
25
+    foreach ( $disabled_dates as $disabled_date ) {
26 26
 
27
-		$disabled_date = trim( $disabled_date );
27
+        $disabled_date = trim( $disabled_date );
28 28
 
29
-		if ( false === strpos( $disabled_date, '|' ) ) {
30
-			$disable_dates[] = $disabled_date;
31
-			continue;
32
-		}
29
+        if ( false === strpos( $disabled_date, '|' ) ) {
30
+            $disable_dates[] = $disabled_date;
31
+            continue;
32
+        }
33 33
 
34
-		$disabled_date   = explode( '|', $disabled_date );
35
-		$disable_dates[] = array(
36
-			'from' => trim( $disabled_date[0] ),
37
-			'to'   => trim( $disabled_date[1] ),
38
-		);
34
+        $disabled_date   = explode( '|', $disabled_date );
35
+        $disable_dates[] = array(
36
+            'from' => trim( $disabled_date[0] ),
37
+            'to'   => trim( $disabled_date[1] ),
38
+        );
39 39
 
40
-	}
40
+    }
41 41
 }
42 42
 
43 43
 $options = array(
44
-	'data-default-date'     => empty( $default_date ) ? false : $default_date,
45
-	'data-min-date'         => empty( $min_date ) ? false : $min_date,
46
-	'data-max-date'         => empty( $max_date ) ? false : $max_date,
47
-	'data-mode'             => empty( $mode ) ? 'single' : $mode,
48
-	'data-alt-format'       => get_option( 'date_format', 'F j, Y' ),
49
-	'data-date-format'      => 'Y-m-d',
50
-	'data-alt-input'        => 'true',
51
-	'data-disable_alt'      => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
52
-	'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
44
+    'data-default-date'     => empty( $default_date ) ? false : $default_date,
45
+    'data-min-date'         => empty( $min_date ) ? false : $min_date,
46
+    'data-max-date'         => empty( $max_date ) ? false : $max_date,
47
+    'data-mode'             => empty( $mode ) ? 'single' : $mode,
48
+    'data-alt-format'       => get_option( 'date_format', 'F j, Y' ),
49
+    'data-date-format'      => 'Y-m-d',
50
+    'data-alt-input'        => 'true',
51
+    'data-disable_alt'      => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
52
+    'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
53 53
 );
54 54
 
55 55
 aui()->input(
56
-	array(
57
-		'name'             => esc_attr( $id ),
58
-		'id'               => esc_attr( $element_id ),
59
-		'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
60
-		'required'         => ! empty( $required ),
61
-		'label'            => $label,
62
-		'label_type'       => 'vertical',
63
-		'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
64
-		'type'             => 'datepicker',
65
-		'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
66
-		'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
67
-		'value'            => $query_value,
68
-	),
69
-	true
56
+    array(
57
+        'name'             => esc_attr( $id ),
58
+        'id'               => esc_attr( $element_id ),
59
+        'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
60
+        'required'         => ! empty( $required ),
61
+        'label'            => $label,
62
+        'label_type'       => 'vertical',
63
+        'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
64
+        'type'             => 'datepicker',
65
+        'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
66
+        'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
67
+        'value'            => $query_value,
68
+    ),
69
+    true
70 70
 );
Please login to merge, or discard this patch.
includes/admin/class-getpaid-installer.php 1 patch
Indentation   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -20,237 +20,237 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	/**
24
-	 * Upgrades the install.
25
-	 *
26
-	 * @param string $upgrade_from The current invoicing version.
27
-	 */
28
-	public function upgrade_db( $upgrade_from ) {
29
-
30
-		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
32
-
33
-		// Setup the invoice Custom Post Type.
34
-		GetPaid_Post_Types::register_post_types();
35
-
36
-		// Clear the permalinks
37
-		flush_rewrite_rules();
38
-
39
-		// Maybe create new/missing pages.
40
-		$this->create_pages();
41
-
42
-		// Maybe re(add) admin capabilities.
43
-		$this->add_capabilities();
44
-
45
-		// Maybe create the default payment form.
46
-		wpinv_get_default_payment_form();
47
-
48
-		// Create any missing database tables.
49
-		$method = "upgrade_from_$upgrade_from";
50
-
51
-		$installed = get_option( 'gepaid_installed_on' );
52
-
53
-		if ( empty( $installed ) ) {
54
-			update_option( 'gepaid_installed_on', time() );
55
-		}
56
-
57
-		if ( method_exists( $this, $method ) ) {
58
-			$this->$method();
59
-		}
60
-
61
-	}
62
-
63
-	/**
64
-	 * Do a fresh install.
65
-	 *
66
-	 */
67
-	public function upgrade_from_0() {
68
-		$this->create_subscriptions_table();
69
-		$this->create_invoices_table();
70
-		$this->create_invoice_items_table();
71
-
72
-		// Save default tax rates.
73
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
-	}
75
-
76
-	/**
77
-	 * Upgrade to 0.0.5
78
-	 *
79
-	 */
80
-	public function upgrade_from_004() {
81
-		global $wpdb;
82
-
83
-		// Invoices.
84
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
-		if ( ! empty( $results ) ) {
86
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
-
88
-			// Clean post cache
89
-			foreach ( $results as $row ) {
90
-				clean_post_cache( $row->ID );
91
-			}
92
-		}
93
-
94
-		// Item meta key changes
95
-		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
-		$results = $wpdb->get_results( $query );
97
-
98
-		if ( ! empty( $results ) ) {
99
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
-
103
-			foreach ( $results as $row ) {
104
-				clean_post_cache( $row->post_id );
105
-			}
106
-		}
107
-
108
-		$this->upgrade_from_102();
109
-	}
110
-
111
-	/**
112
-	 * Upgrade to 1.0.3
113
-	 *
114
-	 */
115
-	public function upgrade_from_102() {
116
-		$this->create_subscriptions_table();
117
-		$this->upgrade_from_118();
118
-	}
119
-
120
-	/**
121
-	 * Upgrade to version 2.0.0.
122
-	 *
123
-	 */
124
-	public function upgrade_from_118() {
125
-		$this->create_invoices_table();
126
-		$this->create_invoice_items_table();
127
-		$this->migrate_old_invoices();
128
-	}
129
-
130
-	/**
131
-	 * Upgrade to version 2.0.8.
132
-	 *
133
-	 */
134
-	public function upgrade_from_207() {
135
-		global $wpdb;
136
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
137
-		$this->upgrade_from_2615();
138
-	}
139
-
140
-	/**
141
-	 * Upgrade to version 2.6.16.
142
-	 *
143
-	 */
144
-	public function upgrade_from_2615() {
145
-		global $wpdb;
146
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" );
147
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" );
148
-	}
149
-
150
-	/**
151
-	 * Give administrators the capability to manage GetPaid.
152
-	 *
153
-	 */
154
-	public function add_capabilities() {
155
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
156
-	}
157
-
158
-	/**
159
-	 * Retreives GetPaid pages.
160
-	 *
161
-	 */
162
-	public static function get_pages() {
163
-
164
-		return apply_filters(
165
-			'wpinv_create_pages',
166
-			array(
167
-
168
-				// Checkout page.
169
-				'checkout_page'             => array(
170
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
171
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
172
-					'content' => '
23
+    /**
24
+     * Upgrades the install.
25
+     *
26
+     * @param string $upgrade_from The current invoicing version.
27
+     */
28
+    public function upgrade_db( $upgrade_from ) {
29
+
30
+        // Save the current invoicing version.
31
+        update_option( 'wpinv_version', WPINV_VERSION );
32
+
33
+        // Setup the invoice Custom Post Type.
34
+        GetPaid_Post_Types::register_post_types();
35
+
36
+        // Clear the permalinks
37
+        flush_rewrite_rules();
38
+
39
+        // Maybe create new/missing pages.
40
+        $this->create_pages();
41
+
42
+        // Maybe re(add) admin capabilities.
43
+        $this->add_capabilities();
44
+
45
+        // Maybe create the default payment form.
46
+        wpinv_get_default_payment_form();
47
+
48
+        // Create any missing database tables.
49
+        $method = "upgrade_from_$upgrade_from";
50
+
51
+        $installed = get_option( 'gepaid_installed_on' );
52
+
53
+        if ( empty( $installed ) ) {
54
+            update_option( 'gepaid_installed_on', time() );
55
+        }
56
+
57
+        if ( method_exists( $this, $method ) ) {
58
+            $this->$method();
59
+        }
60
+
61
+    }
62
+
63
+    /**
64
+     * Do a fresh install.
65
+     *
66
+     */
67
+    public function upgrade_from_0() {
68
+        $this->create_subscriptions_table();
69
+        $this->create_invoices_table();
70
+        $this->create_invoice_items_table();
71
+
72
+        // Save default tax rates.
73
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
+    }
75
+
76
+    /**
77
+     * Upgrade to 0.0.5
78
+     *
79
+     */
80
+    public function upgrade_from_004() {
81
+        global $wpdb;
82
+
83
+        // Invoices.
84
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
+        if ( ! empty( $results ) ) {
86
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
+
88
+            // Clean post cache
89
+            foreach ( $results as $row ) {
90
+                clean_post_cache( $row->ID );
91
+            }
92
+        }
93
+
94
+        // Item meta key changes
95
+        $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
+        $results = $wpdb->get_results( $query );
97
+
98
+        if ( ! empty( $results ) ) {
99
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
+
103
+            foreach ( $results as $row ) {
104
+                clean_post_cache( $row->post_id );
105
+            }
106
+        }
107
+
108
+        $this->upgrade_from_102();
109
+    }
110
+
111
+    /**
112
+     * Upgrade to 1.0.3
113
+     *
114
+     */
115
+    public function upgrade_from_102() {
116
+        $this->create_subscriptions_table();
117
+        $this->upgrade_from_118();
118
+    }
119
+
120
+    /**
121
+     * Upgrade to version 2.0.0.
122
+     *
123
+     */
124
+    public function upgrade_from_118() {
125
+        $this->create_invoices_table();
126
+        $this->create_invoice_items_table();
127
+        $this->migrate_old_invoices();
128
+    }
129
+
130
+    /**
131
+     * Upgrade to version 2.0.8.
132
+     *
133
+     */
134
+    public function upgrade_from_207() {
135
+        global $wpdb;
136
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
137
+        $this->upgrade_from_2615();
138
+    }
139
+
140
+    /**
141
+     * Upgrade to version 2.6.16.
142
+     *
143
+     */
144
+    public function upgrade_from_2615() {
145
+        global $wpdb;
146
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" );
147
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" );
148
+    }
149
+
150
+    /**
151
+     * Give administrators the capability to manage GetPaid.
152
+     *
153
+     */
154
+    public function add_capabilities() {
155
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
156
+    }
157
+
158
+    /**
159
+     * Retreives GetPaid pages.
160
+     *
161
+     */
162
+    public static function get_pages() {
163
+
164
+        return apply_filters(
165
+            'wpinv_create_pages',
166
+            array(
167
+
168
+                // Checkout page.
169
+                'checkout_page'             => array(
170
+                    'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
171
+                    'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
172
+                    'content' => '
173 173
 						<!-- wp:shortcode -->
174 174
 						[wpinv_checkout]
175 175
 						<!-- /wp:shortcode -->
176 176
 					',
177
-					'parent'  => '',
178
-				),
179
-
180
-				// Invoice history page.
181
-				'invoice_history_page'      => array(
182
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
183
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
184
-					'content' => '
177
+                    'parent'  => '',
178
+                ),
179
+
180
+                // Invoice history page.
181
+                'invoice_history_page'      => array(
182
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
183
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
184
+                    'content' => '
185 185
 					<!-- wp:shortcode -->
186 186
 					[wpinv_history]
187 187
 					<!-- /wp:shortcode -->
188 188
 				',
189
-					'parent'  => '',
190
-				),
191
-
192
-				// Success page content.
193
-				'success_page'              => array(
194
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
195
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
196
-					'content' => '
189
+                    'parent'  => '',
190
+                ),
191
+
192
+                // Success page content.
193
+                'success_page'              => array(
194
+                    'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
195
+                    'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
196
+                    'content' => '
197 197
 					<!-- wp:shortcode -->
198 198
 					[wpinv_receipt]
199 199
 					<!-- /wp:shortcode -->
200 200
 				',
201
-					'parent'  => 'gp-checkout',
202
-				),
203
-
204
-				// Failure page content.
205
-				'failure_page'              => array(
206
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
207
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
208
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
209
-					'parent'  => 'gp-checkout',
210
-				),
211
-
212
-				// Subscriptions history page.
213
-				'invoice_subscription_page' => array(
214
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
215
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
216
-					'content' => '
201
+                    'parent'  => 'gp-checkout',
202
+                ),
203
+
204
+                // Failure page content.
205
+                'failure_page'              => array(
206
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
207
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
208
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
209
+                    'parent'  => 'gp-checkout',
210
+                ),
211
+
212
+                // Subscriptions history page.
213
+                'invoice_subscription_page' => array(
214
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
215
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
216
+                    'content' => '
217 217
 					<!-- wp:shortcode -->
218 218
 					[wpinv_subscriptions]
219 219
 					<!-- /wp:shortcode -->
220 220
 				',
221
-					'parent'  => '',
222
-				),
221
+                    'parent'  => '',
222
+                ),
223 223
 
224
-			)
225
-		);
224
+            )
225
+        );
226 226
 
227
-	}
227
+    }
228 228
 
229
-	/**
230
-	 * Re-create GetPaid pages.
231
-	 *
232
-	 */
233
-	public function create_pages() {
229
+    /**
230
+     * Re-create GetPaid pages.
231
+     *
232
+     */
233
+    public function create_pages() {
234 234
 
235
-		foreach ( self::get_pages() as $key => $page ) {
236
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
237
-		}
235
+        foreach ( self::get_pages() as $key => $page ) {
236
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
237
+        }
238 238
 
239
-	}
239
+    }
240 240
 
241
-	/**
242
-	 * Create subscriptions table.
243
-	 *
244
-	 */
245
-	public function create_subscriptions_table() {
241
+    /**
242
+     * Create subscriptions table.
243
+     *
244
+     */
245
+    public function create_subscriptions_table() {
246 246
 
247
-		global $wpdb;
247
+        global $wpdb;
248 248
 
249
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
249
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
250 250
 
251
-		// Create tables.
252
-		$charset_collate = $wpdb->get_charset_collate();
253
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
251
+        // Create tables.
252
+        $charset_collate = $wpdb->get_charset_collate();
253
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
254 254
 			id bigint(20) unsigned NOT NULL auto_increment,
255 255
 			customer_id bigint(20) NOT NULL,
256 256
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -273,22 +273,22 @@  discard block
 block discarded – undo
273 273
 			KEY customer_and_status (customer_id, status)
274 274
 		  ) $charset_collate;";
275 275
 
276
-		dbDelta( $sql );
276
+        dbDelta( $sql );
277 277
 
278
-	}
278
+    }
279 279
 
280
-	/**
281
-	 * Create invoices table.
282
-	 *
283
-	 */
284
-	public function create_invoices_table() {
285
-		global $wpdb;
280
+    /**
281
+     * Create invoices table.
282
+     *
283
+     */
284
+    public function create_invoices_table() {
285
+        global $wpdb;
286 286
 
287
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
287
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
288 288
 
289
-		// Create tables.
290
-		$charset_collate = $wpdb->get_charset_collate();
291
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
289
+        // Create tables.
290
+        $charset_collate = $wpdb->get_charset_collate();
291
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
292 292
 			post_id BIGINT(20) NOT NULL,
293 293
             `number` VARCHAR(100),
294 294
             `key` VARCHAR(100),
@@ -324,22 +324,22 @@  discard block
 block discarded – undo
324 324
 			KEY `key` (`key`)
325 325
 		  ) $charset_collate;";
326 326
 
327
-		dbDelta( $sql );
327
+        dbDelta( $sql );
328 328
 
329
-	}
329
+    }
330 330
 
331
-	/**
332
-	 * Create invoice items table.
333
-	 *
334
-	 */
335
-	public function create_invoice_items_table() {
336
-		global $wpdb;
331
+    /**
332
+     * Create invoice items table.
333
+     *
334
+     */
335
+    public function create_invoice_items_table() {
336
+        global $wpdb;
337 337
 
338
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
338
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
339 339
 
340
-		// Create tables.
341
-		$charset_collate = $wpdb->get_charset_collate();
342
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
340
+        // Create tables.
341
+        $charset_collate = $wpdb->get_charset_collate();
342
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
343 343
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
344 344
             post_id BIGINT(20) NOT NULL,
345 345
             item_id BIGINT(20) NOT NULL,
@@ -361,159 +361,159 @@  discard block
 block discarded – undo
361 361
 			KEY post_id (post_id)
362 362
 		  ) $charset_collate;";
363 363
 
364
-		dbDelta( $sql );
365
-
366
-	}
367
-
368
-	/**
369
-	 * Migrates old invoices to new invoices.
370
-	 *
371
-	 */
372
-	public function migrate_old_invoices() {
373
-		global $wpdb;
374
-
375
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
376
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
377
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
378
-		$invoices            = array_unique(
379
-			get_posts(
380
-				array(
381
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
382
-					'posts_per_page' => -1,
383
-					'fields'         => 'ids',
384
-					'post_status'    => array_keys( get_post_stati() ),
385
-					'exclude'        => (array) $migrated,
386
-				)
387
-			)
388
-		);
389
-
390
-		// Abort if we do not have any invoices.
391
-		if ( empty( $invoices ) ) {
392
-			return;
393
-		}
394
-
395
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
396
-
397
-		$invoice_rows = array();
398
-		foreach ( $invoices as $invoice ) {
399
-
400
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
401
-
402
-			if ( empty( $invoice->ID ) ) {
403
-				return;
404
-			}
405
-
406
-			$fields = array(
407
-				'post_id'            => $invoice->ID,
408
-				'number'             => $invoice->get_number(),
409
-				'key'                => $invoice->get_key(),
410
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
411
-				'mode'               => $invoice->mode,
412
-				'user_ip'            => $invoice->get_ip(),
413
-				'first_name'         => $invoice->get_first_name(),
414
-				'last_name'          => $invoice->get_last_name(),
415
-				'address'            => $invoice->get_address(),
416
-				'city'               => $invoice->city,
417
-				'state'              => $invoice->state,
418
-				'country'            => $invoice->country,
419
-				'zip'                => $invoice->zip,
420
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
421
-				'gateway'            => $invoice->get_gateway(),
422
-				'transaction_id'     => $invoice->get_transaction_id(),
423
-				'currency'           => $invoice->get_currency(),
424
-				'subtotal'           => $invoice->get_subtotal(),
425
-				'tax'                => $invoice->get_tax(),
426
-				'fees_total'         => $invoice->get_fees_total(),
427
-				'total'              => $invoice->get_total(),
428
-				'discount'           => $invoice->get_discount(),
429
-				'discount_code'      => $invoice->get_discount_code(),
430
-				'disable_taxes'      => $invoice->disable_taxes,
431
-				'due_date'           => $invoice->get_due_date(),
432
-				'completed_date'     => $invoice->get_completed_date(),
433
-				'company'            => $invoice->company,
434
-				'vat_number'         => $invoice->vat_number,
435
-				'vat_rate'           => $invoice->vat_rate,
436
-				'custom_meta'        => $invoice->payment_meta,
437
-			);
438
-
439
-			foreach ( $fields as $key => $val ) {
440
-				if ( is_null( $val ) ) {
441
-					$val = '';
442
-				}
443
-				$val = maybe_serialize( $val );
444
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
445
-			}
446
-
447
-			$fields = implode( ', ', $fields );
448
-			$invoice_rows[] = "($fields)";
449
-
450
-			$item_rows    = array();
451
-			$item_columns = array();
452
-			foreach ( $invoice->get_cart_details() as $details ) {
453
-				$fields = array(
454
-					'post_id'          => $invoice->ID,
455
-					'item_id'          => $details['id'],
456
-					'item_name'        => $details['name'],
457
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
458
-					'vat_rate'         => $details['vat_rate'],
459
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
460
-					'tax'              => $details['tax'],
461
-					'item_price'       => $details['item_price'],
462
-					'custom_price'     => $details['custom_price'],
463
-					'quantity'         => $details['quantity'],
464
-					'discount'         => $details['discount'],
465
-					'subtotal'         => $details['subtotal'],
466
-					'price'            => $details['price'],
467
-					'meta'             => $details['meta'],
468
-					'fees'             => $details['fees'],
469
-				);
470
-
471
-				$item_columns = array_keys( $fields );
472
-
473
-				foreach ( $fields as $key => $val ) {
474
-					if ( is_null( $val ) ) {
475
-						$val = '';
476
-					}
477
-					$val = maybe_serialize( $val );
478
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
479
-				}
480
-
481
-				$fields = implode( ', ', $fields );
482
-				$item_rows[] = "($fields)";
483
-			}
484
-
485
-			$item_rows    = implode( ', ', $item_rows );
486
-			$item_columns = implode( ', ', $item_columns );
487
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
488
-		}
489
-
490
-		if ( empty( $invoice_rows ) ) {
491
-			return;
492
-		}
493
-
494
-		$invoice_rows = implode( ', ', $invoice_rows );
495
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
496
-
497
-	}
498
-
499
-	/**
500
-	 * Migrates old invoices to new invoices.
501
-	 *
502
-	 */
503
-	public static function rename_gateways_label() {
504
-		global $wpdb;
505
-
506
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
507
-
508
-			$wpdb->update(
509
-				$wpdb->prefix . 'getpaid_invoices',
510
-				array( 'gateway' => $gateway ),
511
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
512
-				'%s',
513
-				'%s'
514
-			);
515
-
516
-		}
517
-	}
364
+        dbDelta( $sql );
365
+
366
+    }
367
+
368
+    /**
369
+     * Migrates old invoices to new invoices.
370
+     *
371
+     */
372
+    public function migrate_old_invoices() {
373
+        global $wpdb;
374
+
375
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
376
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
377
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
378
+        $invoices            = array_unique(
379
+            get_posts(
380
+                array(
381
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
382
+                    'posts_per_page' => -1,
383
+                    'fields'         => 'ids',
384
+                    'post_status'    => array_keys( get_post_stati() ),
385
+                    'exclude'        => (array) $migrated,
386
+                )
387
+            )
388
+        );
389
+
390
+        // Abort if we do not have any invoices.
391
+        if ( empty( $invoices ) ) {
392
+            return;
393
+        }
394
+
395
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
396
+
397
+        $invoice_rows = array();
398
+        foreach ( $invoices as $invoice ) {
399
+
400
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
401
+
402
+            if ( empty( $invoice->ID ) ) {
403
+                return;
404
+            }
405
+
406
+            $fields = array(
407
+                'post_id'            => $invoice->ID,
408
+                'number'             => $invoice->get_number(),
409
+                'key'                => $invoice->get_key(),
410
+                'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
411
+                'mode'               => $invoice->mode,
412
+                'user_ip'            => $invoice->get_ip(),
413
+                'first_name'         => $invoice->get_first_name(),
414
+                'last_name'          => $invoice->get_last_name(),
415
+                'address'            => $invoice->get_address(),
416
+                'city'               => $invoice->city,
417
+                'state'              => $invoice->state,
418
+                'country'            => $invoice->country,
419
+                'zip'                => $invoice->zip,
420
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
421
+                'gateway'            => $invoice->get_gateway(),
422
+                'transaction_id'     => $invoice->get_transaction_id(),
423
+                'currency'           => $invoice->get_currency(),
424
+                'subtotal'           => $invoice->get_subtotal(),
425
+                'tax'                => $invoice->get_tax(),
426
+                'fees_total'         => $invoice->get_fees_total(),
427
+                'total'              => $invoice->get_total(),
428
+                'discount'           => $invoice->get_discount(),
429
+                'discount_code'      => $invoice->get_discount_code(),
430
+                'disable_taxes'      => $invoice->disable_taxes,
431
+                'due_date'           => $invoice->get_due_date(),
432
+                'completed_date'     => $invoice->get_completed_date(),
433
+                'company'            => $invoice->company,
434
+                'vat_number'         => $invoice->vat_number,
435
+                'vat_rate'           => $invoice->vat_rate,
436
+                'custom_meta'        => $invoice->payment_meta,
437
+            );
438
+
439
+            foreach ( $fields as $key => $val ) {
440
+                if ( is_null( $val ) ) {
441
+                    $val = '';
442
+                }
443
+                $val = maybe_serialize( $val );
444
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
445
+            }
446
+
447
+            $fields = implode( ', ', $fields );
448
+            $invoice_rows[] = "($fields)";
449
+
450
+            $item_rows    = array();
451
+            $item_columns = array();
452
+            foreach ( $invoice->get_cart_details() as $details ) {
453
+                $fields = array(
454
+                    'post_id'          => $invoice->ID,
455
+                    'item_id'          => $details['id'],
456
+                    'item_name'        => $details['name'],
457
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
458
+                    'vat_rate'         => $details['vat_rate'],
459
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
460
+                    'tax'              => $details['tax'],
461
+                    'item_price'       => $details['item_price'],
462
+                    'custom_price'     => $details['custom_price'],
463
+                    'quantity'         => $details['quantity'],
464
+                    'discount'         => $details['discount'],
465
+                    'subtotal'         => $details['subtotal'],
466
+                    'price'            => $details['price'],
467
+                    'meta'             => $details['meta'],
468
+                    'fees'             => $details['fees'],
469
+                );
470
+
471
+                $item_columns = array_keys( $fields );
472
+
473
+                foreach ( $fields as $key => $val ) {
474
+                    if ( is_null( $val ) ) {
475
+                        $val = '';
476
+                    }
477
+                    $val = maybe_serialize( $val );
478
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
479
+                }
480
+
481
+                $fields = implode( ', ', $fields );
482
+                $item_rows[] = "($fields)";
483
+            }
484
+
485
+            $item_rows    = implode( ', ', $item_rows );
486
+            $item_columns = implode( ', ', $item_columns );
487
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
488
+        }
489
+
490
+        if ( empty( $invoice_rows ) ) {
491
+            return;
492
+        }
493
+
494
+        $invoice_rows = implode( ', ', $invoice_rows );
495
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
496
+
497
+    }
498
+
499
+    /**
500
+     * Migrates old invoices to new invoices.
501
+     *
502
+     */
503
+    public static function rename_gateways_label() {
504
+        global $wpdb;
505
+
506
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
507
+
508
+            $wpdb->update(
509
+                $wpdb->prefix . 'getpaid_invoices',
510
+                array( 'gateway' => $gateway ),
511
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
512
+                '%s',
513
+                '%s'
514
+            );
515
+
516
+        }
517
+    }
518 518
 
519 519
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-export.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -12,47 +12,47 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Export {
14 14
 
15
-	/**
16
-	 * Displays the reports tab.
17
-	 *
18
-	 */
19
-	public function display() {
20
-
21
-		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
24
-		}
25
-		$this->display_subscription_export();
26
-		echo '</div>';
27
-
28
-	}
29
-
30
-	/**
31
-	 * Retrieves the download url.
32
-	 *
33
-	 */
34
-	public function get_download_url( $post_type ) {
35
-
36
-		return wp_nonce_url(
37
-			add_query_arg(
38
-				array(
39
-					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
41
-				)
42
-			),
43
-			'getpaid-nonce',
44
-			'getpaid-nonce'
45
-		);
46
-
47
-	}
48
-
49
-	/**
50
-	 * Displays a single post type export card.
51
-	 *
52
-	 */
53
-	public function display_post_type_export( $post_type ) {
54
-
55
-		?>
15
+    /**
16
+     * Displays the reports tab.
17
+     *
18
+     */
19
+    public function display() {
20
+
21
+        echo "<div class='row mt-4' style='max-width: 920px;' >";
22
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
+            $this->display_post_type_export( $post_type );
24
+        }
25
+        $this->display_subscription_export();
26
+        echo '</div>';
27
+
28
+    }
29
+
30
+    /**
31
+     * Retrieves the download url.
32
+     *
33
+     */
34
+    public function get_download_url( $post_type ) {
35
+
36
+        return wp_nonce_url(
37
+            add_query_arg(
38
+                array(
39
+                    'getpaid-admin-action' => 'export_invoices',
40
+                    'post_type'            => urlencode( $post_type ),
41
+                )
42
+            ),
43
+            'getpaid-nonce',
44
+            'getpaid-nonce'
45
+        );
46
+
47
+    }
48
+
49
+    /**
50
+     * Displays a single post type export card.
51
+     *
52
+     */
53
+    public function display_post_type_export( $post_type ) {
54
+
55
+        ?>
56 56
 
57 57
 		<div class="col-12 col-md-6">
58 58
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 				<div class="card-header">
61 61
 					<strong>
62 62
 						<?php
63
-							printf(
64
-								esc_html__( 'Export %s', 'invoicing' ),
65
-								esc_html( getpaid_get_post_type_label( $post_type ) )
66
-							);
67
-						?>
63
+                            printf(
64
+                                esc_html__( 'Export %s', 'invoicing' ),
65
+                                esc_html( getpaid_get_post_type_label( $post_type ) )
66
+                            );
67
+                        ?>
68 68
 					</strong>
69 69
 				</div>
70 70
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
74 74
 
75 75
 						<?php
76
-							$this->generate_from_date( $post_type );
77
-							$this->generate_to_date( $post_type );
78
-							$this->generate_post_status_select( $post_type );
79
-							$this->generate_file_type_select( $post_type );
80
-							submit_button( __( 'Download', 'invoicing' ) );
81
-						?>
76
+                            $this->generate_from_date( $post_type );
77
+                            $this->generate_to_date( $post_type );
78
+                            $this->generate_post_status_select( $post_type );
79
+                            $this->generate_file_type_select( $post_type );
80
+                            submit_button( __( 'Download', 'invoicing' ) );
81
+                        ?>
82 82
 
83 83
 					</form>
84 84
 
@@ -89,135 +89,135 @@  discard block
 block discarded – undo
89 89
 
90 90
 		<?php
91 91
 
92
-	}
93
-
94
-	/**
95
-	 * Generates the from date input field.
96
-	 *
97
-	 */
98
-	public function generate_from_date( $post_type ) {
99
-
100
-		aui()->input(
101
-			array(
102
-				'type'             => 'datepicker',
103
-				'id'               => esc_attr( "$post_type-from_date" ),
104
-				'name'             => 'from_date',
105
-				'label'            => __( 'From Date', 'invoicing' ),
106
-				'label_type'       => 'vertical',
107
-				'placeholder'      => 'YYYY-MM-DD',
108
-				'extra_attributes' => array(
109
-					'data-enable-time' => 'false',
110
-					'data-allow-input' => 'true',
111
-				),
112
-			),
113
-			true
114
-		);
115
-
116
-	}
117
-
118
-	/**
119
-	 * Generates the to date input field.
120
-	 *
121
-	 */
122
-	public function generate_to_date( $post_type ) {
123
-
124
-		aui()->input(
125
-			array(
126
-				'type'             => 'datepicker',
127
-				'id'               => esc_attr( "$post_type-to_date" ),
128
-				'name'             => 'to_date',
129
-				'label'            => __( 'To Date', 'invoicing' ),
130
-				'label_type'       => 'vertical',
131
-				'placeholder'      => 'YYYY-MM-DD',
132
-				'extra_attributes' => array(
133
-					'data-enable-time' => 'false',
134
-					'data-allow-input' => 'true',
135
-				),
136
-			),
137
-			true
138
-		);
139
-	}
140
-
141
-	/**
142
-	 * Generates the to post status select field.
143
-	 *
144
-	 */
145
-	public function generate_post_status_select( $post_type ) {
146
-
147
-		if ( 'subscriptions' === $post_type ) {
148
-			$options = getpaid_get_subscription_statuses();
149
-		} else {
150
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
151
-		}
152
-
153
-		aui()->select(
154
-			array(
155
-				'name'        => 'status',
156
-				'id'          => esc_attr( "$post_type-status" ),
157
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
158
-				'label'       => __( 'Status', 'invoicing' ),
159
-				'label_type'  => 'vertical',
160
-				'label_class' => 'd-block',
161
-				'options'     => $options,
162
-			),
163
-			true
164
-		);
165
-
166
-	}
167
-
168
-	/**
169
-	 * Generates the to file type select field.
170
-	 *
171
-	 */
172
-	public function generate_file_type_select( $post_type ) {
173
-
174
-		aui()->select(
175
-			array(
176
-				'name'        => 'file_type',
177
-				'id'          => esc_attr( "$post_type-file_type" ),
178
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
179
-				'label'       => __( 'Export File', 'invoicing' ),
180
-				'label_type'  => 'vertical',
181
-				'label_class' => 'd-block',
182
-				'value'       => 'csv',
183
-				'options'     => array(
184
-					'csv'  => __( 'CSV', 'invoicing' ),
185
-					'xml'  => __( 'XML', 'invoicing' ),
186
-					'json' => __( 'JSON', 'invoicing' ),
187
-				),
188
-			),
189
-			true
190
-		);
191
-
192
-	}
193
-
194
-	/**
195
-	 * Displays a field's markup.
196
-	 *
197
-	 */
198
-	public function display_markup( $markup ) {
199
-
200
-		echo wp_kses(
201
-			str_replace(
202
-				array(
203
-					'form-control',
204
-					'custom-select',
205
-				),
206
-				'regular-text',
207
-				$markup
208
-			),
209
-			getpaid_allowed_html()
210
-		);
211
-
212
-	}
213
-
214
-	/**
215
-	 * Displays a subscription export card.
216
-	 *
217
-	 */
218
-	public function display_subscription_export() {
219
-
220
-		?>
92
+    }
93
+
94
+    /**
95
+     * Generates the from date input field.
96
+     *
97
+     */
98
+    public function generate_from_date( $post_type ) {
99
+
100
+        aui()->input(
101
+            array(
102
+                'type'             => 'datepicker',
103
+                'id'               => esc_attr( "$post_type-from_date" ),
104
+                'name'             => 'from_date',
105
+                'label'            => __( 'From Date', 'invoicing' ),
106
+                'label_type'       => 'vertical',
107
+                'placeholder'      => 'YYYY-MM-DD',
108
+                'extra_attributes' => array(
109
+                    'data-enable-time' => 'false',
110
+                    'data-allow-input' => 'true',
111
+                ),
112
+            ),
113
+            true
114
+        );
115
+
116
+    }
117
+
118
+    /**
119
+     * Generates the to date input field.
120
+     *
121
+     */
122
+    public function generate_to_date( $post_type ) {
123
+
124
+        aui()->input(
125
+            array(
126
+                'type'             => 'datepicker',
127
+                'id'               => esc_attr( "$post_type-to_date" ),
128
+                'name'             => 'to_date',
129
+                'label'            => __( 'To Date', 'invoicing' ),
130
+                'label_type'       => 'vertical',
131
+                'placeholder'      => 'YYYY-MM-DD',
132
+                'extra_attributes' => array(
133
+                    'data-enable-time' => 'false',
134
+                    'data-allow-input' => 'true',
135
+                ),
136
+            ),
137
+            true
138
+        );
139
+    }
140
+
141
+    /**
142
+     * Generates the to post status select field.
143
+     *
144
+     */
145
+    public function generate_post_status_select( $post_type ) {
146
+
147
+        if ( 'subscriptions' === $post_type ) {
148
+            $options = getpaid_get_subscription_statuses();
149
+        } else {
150
+            $options = wpinv_get_invoice_statuses( true, false, $post_type );
151
+        }
152
+
153
+        aui()->select(
154
+            array(
155
+                'name'        => 'status',
156
+                'id'          => esc_attr( "$post_type-status" ),
157
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
158
+                'label'       => __( 'Status', 'invoicing' ),
159
+                'label_type'  => 'vertical',
160
+                'label_class' => 'd-block',
161
+                'options'     => $options,
162
+            ),
163
+            true
164
+        );
165
+
166
+    }
167
+
168
+    /**
169
+     * Generates the to file type select field.
170
+     *
171
+     */
172
+    public function generate_file_type_select( $post_type ) {
173
+
174
+        aui()->select(
175
+            array(
176
+                'name'        => 'file_type',
177
+                'id'          => esc_attr( "$post_type-file_type" ),
178
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
179
+                'label'       => __( 'Export File', 'invoicing' ),
180
+                'label_type'  => 'vertical',
181
+                'label_class' => 'd-block',
182
+                'value'       => 'csv',
183
+                'options'     => array(
184
+                    'csv'  => __( 'CSV', 'invoicing' ),
185
+                    'xml'  => __( 'XML', 'invoicing' ),
186
+                    'json' => __( 'JSON', 'invoicing' ),
187
+                ),
188
+            ),
189
+            true
190
+        );
191
+
192
+    }
193
+
194
+    /**
195
+     * Displays a field's markup.
196
+     *
197
+     */
198
+    public function display_markup( $markup ) {
199
+
200
+        echo wp_kses(
201
+            str_replace(
202
+                array(
203
+                    'form-control',
204
+                    'custom-select',
205
+                ),
206
+                'regular-text',
207
+                $markup
208
+            ),
209
+            getpaid_allowed_html()
210
+        );
211
+
212
+    }
213
+
214
+    /**
215
+     * Displays a subscription export card.
216
+     *
217
+     */
218
+    public function display_subscription_export() {
219
+
220
+        ?>
221 221
 
222 222
 		<div class="col-12 col-md-6">
223 223
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
234 234
 
235 235
 						<?php
236
-							$this->generate_from_date( 'subscriptions' );
237
-							$this->generate_to_date( 'subscriptions' );
238
-							$this->generate_post_status_select( 'subscriptions' );
239
-							$this->generate_file_type_select( 'subscriptions' );
240
-							submit_button( __( 'Download', 'invoicing' ) );
241
-						?>
236
+                            $this->generate_from_date( 'subscriptions' );
237
+                            $this->generate_to_date( 'subscriptions' );
238
+                            $this->generate_post_status_select( 'subscriptions' );
239
+                            $this->generate_file_type_select( 'subscriptions' );
240
+                            submit_button( __( 'Download', 'invoicing' ) );
241
+                        ?>
242 242
 
243 243
 					</form>
244 244
 
@@ -249,6 +249,6 @@  discard block
 block discarded – undo
249 249
 
250 250
 		<?php
251 251
 
252
-	}
252
+    }
253 253
 
254 254
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 1 patch
Indentation   +762 added lines, -762 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,361 +21,361 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 * @since 1.0.10 Now able to pass wp.org theme check.
29
-	 * @since 1.0.11 Font Awesome Pro now supported.
30
-	 * @since 1.0.11 Font Awesome Kits now supported.
31
-	 * @since 1.0.13 RTL language support added.
32
-	 * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed.
33
-	 * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend.
34
-	 * @since 1.1.0 Option added to load FontAwesome locally.
35
-	 * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED.
36
-	 * @ver 1.0.15
37
-	 * @todo decide how to implement textdomain
38
-	 */
39
-	class WP_Font_Awesome_Settings {
40
-
41
-		/**
42
-		 * Class version version.
43
-		 *
44
-		 * @var string
45
-		 */
46
-		public $version = '1.1.1';
47
-
48
-		/**
49
-		 * Class textdomain.
50
-		 *
51
-		 * @var string
52
-		 */
53
-		public $textdomain = 'font-awesome-settings';
54
-
55
-		/**
56
-		 * Latest version of Font Awesome at time of publish published.
57
-		 *
58
-		 * @var string
59
-		 */
60
-		public $latest = "5.8.2";
61
-
62
-		/**
63
-		 * The title.
64
-		 *
65
-		 * @var string
66
-		 */
67
-		public $name = 'Font Awesome';
68
-
69
-		/**
70
-		 * Holds the settings values.
71
-		 *
72
-		 * @var array
73
-		 */
74
-		private $settings;
75
-
76
-		/**
77
-		 * WP_Font_Awesome_Settings instance.
78
-		 *
79
-		 * @access private
80
-		 * @since  1.0.0
81
-		 * @var    WP_Font_Awesome_Settings There can be only one!
82
-		 */
83
-		private static $instance = null;
84
-
85
-		/**
86
-		 * Main WP_Font_Awesome_Settings Instance.
87
-		 *
88
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
89
-		 *
90
-		 * @since 1.0.0
91
-		 * @static
92
-		 * @return WP_Font_Awesome_Settings - Main instance.
93
-		 */
94
-		public static function instance() {
95
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
96
-				self::$instance = new WP_Font_Awesome_Settings;
97
-
98
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
99
-
100
-				if ( is_admin() ) {
101
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
102
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
103
-					add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
104
-				}
105
-
106
-				do_action( 'wp_font_awesome_settings_loaded' );
107
-			}
108
-
109
-			return self::$instance;
110
-		}
111
-
112
-		/**
113
-		 * Initiate the settings and add the required action hooks.
114
-		 *
115
-		 * @since 1.0.8 Settings name wrong - FIXED
116
-		 */
117
-		public function init() {
118
-			// Download fontawesome locally.
119
-			add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
120
-			add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
121
-
122
-			$this->settings = $this->get_settings();
123
-
124
-			// check if the official plugin is active and use that instead if so.
125
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
126
-
127
-				if ( $this->settings['type'] == 'CSS' ) {
128
-
129
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
130
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
131
-					}
132
-
133
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
134
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
135
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
136
-					}
137
-
138
-				} else {
139
-
140
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
141
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
142
-					}
143
-
144
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
145
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
146
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
147
-					}
148
-				}
149
-
150
-				// remove font awesome if set to do so
151
-				if ( $this->settings['dequeue'] == '1' ) {
152
-					add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
153
-				}
154
-			}
155
-
156
-		}
157
-
158
-		/**
159
-		 * Add FA to the FSE.
160
-		 *
161
-		 * @param $editor_settings
162
-		 * @param $block_editor_context
163
-		 *
164
-		 * @return array
165
-		 */
166
-		public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
167
-
168
-			if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
169
-				$url = $this->get_url();
170
-				$editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
171
-			}
172
-
173
-			return $editor_settings;
174
-		}
175
-
176
-		/**
177
-		 * Add FA to the FSE.
178
-		 *
179
-		 * @param $editor_settings
180
-		 * @param $block_editor_context
181
-		 *
182
-		 * @return array
183
-		 */
184
-		public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
185
-
186
-			$url = $this->get_url();
187
-			$editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
188
-
189
-			return $editor_settings;
190
-		}
191
-
192
-		/**
193
-		 * Adds the Font Awesome styles.
194
-		 */
195
-		public function enqueue_style() {
196
-			// build url
197
-			$url = $this->get_url();
198
-			$version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
199
-
200
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
201
-			wp_register_style( 'font-awesome', $url, array(), $version );
202
-			wp_enqueue_style( 'font-awesome' );
203
-
204
-			// RTL language support CSS.
205
-			if ( is_rtl() ) {
206
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
207
-			}
208
-
209
-			if ( $this->settings['shims'] ) {
210
-				$url = $this->get_url( true );
211
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
212
-				wp_register_style( 'font-awesome-shims', $url, array(), $version );
213
-				wp_enqueue_style( 'font-awesome-shims' );
214
-			}
215
-		}
216
-
217
-		/**
218
-		 * Adds the Font Awesome JS.
219
-		 */
220
-		public function enqueue_scripts() {
221
-			// build url
222
-			$url = $this->get_url();
223
-
224
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
225
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
226
-			wp_register_script( 'font-awesome', $url, array(), null );
227
-			wp_enqueue_script( 'font-awesome' );
228
-
229
-			if ( $this->settings['shims'] ) {
230
-				$url = $this->get_url( true );
231
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
232
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
233
-				wp_enqueue_script( 'font-awesome-shims' );
234
-			}
235
-		}
236
-
237
-		/**
238
-		 * Get the url of the Font Awesome files.
239
-		 *
240
-		 * @param bool $shims If this is a shim file or not.
241
-		 * @param bool $local Load locally if allowed.
242
-		 *
243
-		 * @return string The url to the file.
244
-		 */
245
-		public function get_url( $shims = false, $local = true ) {
246
-			$script  = $shims ? 'v4-shims' : 'all';
247
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
248
-			$type    = $this->settings['type'];
249
-			$version = $this->settings['version'];
250
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
251
-			$url     = '';
252
-
253
-			if ( $type == 'KIT' && $kit_url ) {
254
-				if ( $shims ) {
255
-					// if its a kit then we don't add shims here
256
-					return '';
257
-				}
258
-				$url .= $kit_url; // CDN
259
-				$url .= "?wpfas=true"; // set our var so our version is not removed
260
-			} else {
261
-				$v = '';
262
-				// Check and load locally.
263
-				if ( $local && $this->has_local() ) {
264
-					$script .= ".min";
265
-					$v .= '&ver=' . strip_tags( $this->settings['local_version'] );
266
-					$url .= $this->get_fonts_url(); // Local fonts url.
267
-				} else {
268
-					$url .= "https://$sub.fontawesome.com/releases/"; // CDN
269
-					$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
270
-				}
271
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
272
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
273
-				$url .= "?wpfas=true" . $v; // set our var so our version is not removed
274
-			}
275
-
276
-			return $url;
277
-		}
278
-
279
-		/**
280
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
281
-		 *
282
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
283
-		 *
284
-		 * @param $url
285
-		 * @param $original_url
286
-		 * @param $_context
287
-		 *
288
-		 * @return string The filtered url.
289
-		 */
290
-		public function remove_font_awesome( $url, $original_url, $_context ) {
291
-
292
-			if ( $_context == 'display'
293
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
294
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
295
-			) {// it's a font-awesome-url (probably)
296
-
297
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
298
-					if ( $this->settings['type'] == 'JS' ) {
299
-						if ( $this->settings['js-pseudo'] ) {
300
-							$url .= "' data-search-pseudo-elements defer='defer";
301
-						} else {
302
-							$url .= "' defer='defer";
303
-						}
304
-					}
305
-				} else {
306
-					$url = ''; // removing the url removes the file
307
-				}
308
-
309
-			}
310
-
311
-			return $url;
312
-		}
313
-
314
-		/**
315
-		 * Register the database settings with WordPress.
316
-		 */
317
-		public function register_settings() {
318
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
319
-		}
320
-
321
-		/**
322
-		 * Add the WordPress settings menu item.
323
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
324
-		 */
325
-		public function menu_item() {
326
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
327
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
328
-				$this,
329
-				'settings_page'
330
-			) );
331
-		}
332
-
333
-		/**
334
-		 * Get the current Font Awesome output settings.
335
-		 *
336
-		 * @return array The array of settings.
337
-		 */
338
-		public function get_settings() {
339
-			$db_settings = get_option( 'wp-font-awesome-settings' );
340
-
341
-			$defaults = array(
342
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
343
-				'version'   => '', // latest
344
-				'enqueue'   => '', // front and backend
345
-				'shims'     => '0', // default OFF now in 2020
346
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
347
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
348
-				'pro'       => '0', // if pro CDN url should be used
349
-				'local'     => '0', // Store fonts locally.
350
-				'local_version' => '', // Local fonts version.
351
-				'kit-url'   => '', // the kit url
352
-			);
353
-
354
-			$settings = wp_parse_args( $db_settings, $defaults );
355
-
356
-			/**
357
-			 * Filter the Font Awesome settings.
358
-			 *
359
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
360
-			 */
361
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
362
-		}
363
-
364
-		/**
365
-		 * The settings page html output.
366
-		 */
367
-		public function settings_page() {
368
-			if ( ! current_user_can( 'manage_options' ) ) {
369
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
370
-			}
371
-
372
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
373
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
374
-				$this->get_latest_version( $force_api = true );
375
-			}
376
-
377
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
378
-				?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @since 1.0.10 Now able to pass wp.org theme check.
29
+     * @since 1.0.11 Font Awesome Pro now supported.
30
+     * @since 1.0.11 Font Awesome Kits now supported.
31
+     * @since 1.0.13 RTL language support added.
32
+     * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed.
33
+     * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend.
34
+     * @since 1.1.0 Option added to load FontAwesome locally.
35
+     * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED.
36
+     * @ver 1.0.15
37
+     * @todo decide how to implement textdomain
38
+     */
39
+    class WP_Font_Awesome_Settings {
40
+
41
+        /**
42
+         * Class version version.
43
+         *
44
+         * @var string
45
+         */
46
+        public $version = '1.1.1';
47
+
48
+        /**
49
+         * Class textdomain.
50
+         *
51
+         * @var string
52
+         */
53
+        public $textdomain = 'font-awesome-settings';
54
+
55
+        /**
56
+         * Latest version of Font Awesome at time of publish published.
57
+         *
58
+         * @var string
59
+         */
60
+        public $latest = "5.8.2";
61
+
62
+        /**
63
+         * The title.
64
+         *
65
+         * @var string
66
+         */
67
+        public $name = 'Font Awesome';
68
+
69
+        /**
70
+         * Holds the settings values.
71
+         *
72
+         * @var array
73
+         */
74
+        private $settings;
75
+
76
+        /**
77
+         * WP_Font_Awesome_Settings instance.
78
+         *
79
+         * @access private
80
+         * @since  1.0.0
81
+         * @var    WP_Font_Awesome_Settings There can be only one!
82
+         */
83
+        private static $instance = null;
84
+
85
+        /**
86
+         * Main WP_Font_Awesome_Settings Instance.
87
+         *
88
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
89
+         *
90
+         * @since 1.0.0
91
+         * @static
92
+         * @return WP_Font_Awesome_Settings - Main instance.
93
+         */
94
+        public static function instance() {
95
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
96
+                self::$instance = new WP_Font_Awesome_Settings;
97
+
98
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
99
+
100
+                if ( is_admin() ) {
101
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
102
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
103
+                    add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
104
+                }
105
+
106
+                do_action( 'wp_font_awesome_settings_loaded' );
107
+            }
108
+
109
+            return self::$instance;
110
+        }
111
+
112
+        /**
113
+         * Initiate the settings and add the required action hooks.
114
+         *
115
+         * @since 1.0.8 Settings name wrong - FIXED
116
+         */
117
+        public function init() {
118
+            // Download fontawesome locally.
119
+            add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
120
+            add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
121
+
122
+            $this->settings = $this->get_settings();
123
+
124
+            // check if the official plugin is active and use that instead if so.
125
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
126
+
127
+                if ( $this->settings['type'] == 'CSS' ) {
128
+
129
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
130
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
131
+                    }
132
+
133
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
134
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
135
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
136
+                    }
137
+
138
+                } else {
139
+
140
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
141
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
142
+                    }
143
+
144
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
145
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
146
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
147
+                    }
148
+                }
149
+
150
+                // remove font awesome if set to do so
151
+                if ( $this->settings['dequeue'] == '1' ) {
152
+                    add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
153
+                }
154
+            }
155
+
156
+        }
157
+
158
+        /**
159
+         * Add FA to the FSE.
160
+         *
161
+         * @param $editor_settings
162
+         * @param $block_editor_context
163
+         *
164
+         * @return array
165
+         */
166
+        public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
167
+
168
+            if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
169
+                $url = $this->get_url();
170
+                $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
171
+            }
172
+
173
+            return $editor_settings;
174
+        }
175
+
176
+        /**
177
+         * Add FA to the FSE.
178
+         *
179
+         * @param $editor_settings
180
+         * @param $block_editor_context
181
+         *
182
+         * @return array
183
+         */
184
+        public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
185
+
186
+            $url = $this->get_url();
187
+            $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
188
+
189
+            return $editor_settings;
190
+        }
191
+
192
+        /**
193
+         * Adds the Font Awesome styles.
194
+         */
195
+        public function enqueue_style() {
196
+            // build url
197
+            $url = $this->get_url();
198
+            $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
199
+
200
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
201
+            wp_register_style( 'font-awesome', $url, array(), $version );
202
+            wp_enqueue_style( 'font-awesome' );
203
+
204
+            // RTL language support CSS.
205
+            if ( is_rtl() ) {
206
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
207
+            }
208
+
209
+            if ( $this->settings['shims'] ) {
210
+                $url = $this->get_url( true );
211
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
212
+                wp_register_style( 'font-awesome-shims', $url, array(), $version );
213
+                wp_enqueue_style( 'font-awesome-shims' );
214
+            }
215
+        }
216
+
217
+        /**
218
+         * Adds the Font Awesome JS.
219
+         */
220
+        public function enqueue_scripts() {
221
+            // build url
222
+            $url = $this->get_url();
223
+
224
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
225
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
226
+            wp_register_script( 'font-awesome', $url, array(), null );
227
+            wp_enqueue_script( 'font-awesome' );
228
+
229
+            if ( $this->settings['shims'] ) {
230
+                $url = $this->get_url( true );
231
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
232
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
233
+                wp_enqueue_script( 'font-awesome-shims' );
234
+            }
235
+        }
236
+
237
+        /**
238
+         * Get the url of the Font Awesome files.
239
+         *
240
+         * @param bool $shims If this is a shim file or not.
241
+         * @param bool $local Load locally if allowed.
242
+         *
243
+         * @return string The url to the file.
244
+         */
245
+        public function get_url( $shims = false, $local = true ) {
246
+            $script  = $shims ? 'v4-shims' : 'all';
247
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
248
+            $type    = $this->settings['type'];
249
+            $version = $this->settings['version'];
250
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
251
+            $url     = '';
252
+
253
+            if ( $type == 'KIT' && $kit_url ) {
254
+                if ( $shims ) {
255
+                    // if its a kit then we don't add shims here
256
+                    return '';
257
+                }
258
+                $url .= $kit_url; // CDN
259
+                $url .= "?wpfas=true"; // set our var so our version is not removed
260
+            } else {
261
+                $v = '';
262
+                // Check and load locally.
263
+                if ( $local && $this->has_local() ) {
264
+                    $script .= ".min";
265
+                    $v .= '&ver=' . strip_tags( $this->settings['local_version'] );
266
+                    $url .= $this->get_fonts_url(); // Local fonts url.
267
+                } else {
268
+                    $url .= "https://$sub.fontawesome.com/releases/"; // CDN
269
+                    $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
270
+                }
271
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
272
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
273
+                $url .= "?wpfas=true" . $v; // set our var so our version is not removed
274
+            }
275
+
276
+            return $url;
277
+        }
278
+
279
+        /**
280
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
281
+         *
282
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
283
+         *
284
+         * @param $url
285
+         * @param $original_url
286
+         * @param $_context
287
+         *
288
+         * @return string The filtered url.
289
+         */
290
+        public function remove_font_awesome( $url, $original_url, $_context ) {
291
+
292
+            if ( $_context == 'display'
293
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
294
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
295
+            ) {// it's a font-awesome-url (probably)
296
+
297
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
298
+                    if ( $this->settings['type'] == 'JS' ) {
299
+                        if ( $this->settings['js-pseudo'] ) {
300
+                            $url .= "' data-search-pseudo-elements defer='defer";
301
+                        } else {
302
+                            $url .= "' defer='defer";
303
+                        }
304
+                    }
305
+                } else {
306
+                    $url = ''; // removing the url removes the file
307
+                }
308
+
309
+            }
310
+
311
+            return $url;
312
+        }
313
+
314
+        /**
315
+         * Register the database settings with WordPress.
316
+         */
317
+        public function register_settings() {
318
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
319
+        }
320
+
321
+        /**
322
+         * Add the WordPress settings menu item.
323
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
324
+         */
325
+        public function menu_item() {
326
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
327
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
328
+                $this,
329
+                'settings_page'
330
+            ) );
331
+        }
332
+
333
+        /**
334
+         * Get the current Font Awesome output settings.
335
+         *
336
+         * @return array The array of settings.
337
+         */
338
+        public function get_settings() {
339
+            $db_settings = get_option( 'wp-font-awesome-settings' );
340
+
341
+            $defaults = array(
342
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
343
+                'version'   => '', // latest
344
+                'enqueue'   => '', // front and backend
345
+                'shims'     => '0', // default OFF now in 2020
346
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
347
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
348
+                'pro'       => '0', // if pro CDN url should be used
349
+                'local'     => '0', // Store fonts locally.
350
+                'local_version' => '', // Local fonts version.
351
+                'kit-url'   => '', // the kit url
352
+            );
353
+
354
+            $settings = wp_parse_args( $db_settings, $defaults );
355
+
356
+            /**
357
+             * Filter the Font Awesome settings.
358
+             *
359
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
360
+             */
361
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
362
+        }
363
+
364
+        /**
365
+         * The settings page html output.
366
+         */
367
+        public function settings_page() {
368
+            if ( ! current_user_can( 'manage_options' ) ) {
369
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
370
+            }
371
+
372
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
373
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
374
+                $this->get_latest_version( $force_api = true );
375
+            }
376
+
377
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
378
+                ?>
379 379
                 <style>
380 380
                     .wpfas-kit-show {
381 381
                         display: none;
@@ -401,16 +401,16 @@  discard block
 block discarded – undo
401 401
                     <h1><?php echo $this->name; ?></h1>
402 402
                     <form method="post" action="options.php" class="fas-settings-form">
403 403
 						<?php
404
-						settings_fields( 'wp-font-awesome-settings' );
405
-						do_settings_sections( 'wp-font-awesome-settings' );
406
-						$table_class = '';
407
-						if ( $this->settings['type'] ) {
408
-							$table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
409
-						}
410
-						if ( ! empty( $this->settings['pro'] ) ) {
411
-							$table_class .= ' wpfas-has-pro';
412
-						}
413
-						?>
404
+                        settings_fields( 'wp-font-awesome-settings' );
405
+                        do_settings_sections( 'wp-font-awesome-settings' );
406
+                        $table_class = '';
407
+                        if ( $this->settings['type'] ) {
408
+                            $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
409
+                        }
410
+                        if ( ! empty( $this->settings['pro'] ) ) {
411
+                            $table_class .= ' wpfas-has-pro';
412
+                        }
413
+                        ?>
414 414
 						<?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?>
415 415
 							<?php if ( $this->has_local() ) { ?>
416 416
 							<div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'font-awesome-settings' ); ?></strong></p></div>
@@ -435,12 +435,12 @@  discard block
 block discarded – undo
435 435
                                 <td>
436 436
                                     <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
437 437
                                     <span><?php
438
-										echo sprintf(
439
-											__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
440
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
441
-											'</a>'
442
-										);
443
-										?></span>
438
+                                        echo sprintf(
439
+                                            __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
440
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
441
+                                            '</a>'
442
+                                        );
443
+                                        ?></span>
444 444
                                 </td>
445 445
                             </tr>
446 446
 
@@ -481,14 +481,14 @@  discard block
 block discarded – undo
481 481
                                     <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/>
482 482
                                     <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/>
483 483
                                     <span><?php
484
-										echo wp_sprintf(
485
-											__( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'font-awesome-settings' ),
486
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
487
-											' <i class="fas fa-external-link-alt"></i></a>',
488
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
489
-											' <i class="fas fa-external-link-alt"></i></a>'
490
-										);
491
-										?></span>
484
+                                        echo wp_sprintf(
485
+                                            __( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'font-awesome-settings' ),
486
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
487
+                                            ' <i class="fas fa-external-link-alt"></i></a>',
488
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
489
+                                            ' <i class="fas fa-external-link-alt"></i></a>'
490
+                                        );
491
+                                        ?></span>
492 492
                                 </td>
493 493
                             </tr>
494 494
 
@@ -542,8 +542,8 @@  discard block
 block discarded – undo
542 542
                         </table>
543 543
                         <div class="fas-buttons">
544 544
 							<?php
545
-							submit_button();
546
-							?>
545
+                            submit_button();
546
+                            ?>
547 547
                             <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p>
548 548
 
549 549
                         </div>
@@ -552,392 +552,392 @@  discard block
 block discarded – undo
552 552
                     <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div>
553 553
                 </div>
554 554
 				<?php
555
-			}
556
-		}
557
-
558
-		/**
559
-		 * Check a version number is valid and if so return it or else return an empty string.
560
-		 *
561
-		 * @param $version string The version number to check.
562
-		 *
563
-		 * @since 1.0.6
564
-		 *
565
-		 * @return string Either a valid version number or an empty string.
566
-		 */
567
-		public function validate_version_number( $version ) {
568
-
569
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
570
-				// valid
571
-			} else {
572
-				$version = '';// not validated
573
-			}
574
-
575
-			return $version;
576
-		}
577
-
578
-
579
-		/**
580
-		 * Get the latest version of Font Awesome.
581
-		 *
582
-		 * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
583
-		 *
584
-		 * @since 1.0.7
585
-		 * @return mixed|string The latest version number found.
586
-		 */
587
-		public function get_latest_version( $force_api = false ) {
588
-			$latest_version = $this->latest;
589
-
590
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
591
-
592
-			if ( $cache === false || $force_api ) { // its not set
593
-				$api_ver = $this->get_latest_version_from_api();
594
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
595
-					$latest_version = $api_ver;
596
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
597
-				}
598
-			} elseif ( $this->validate_version_number( $cache ) ) {
599
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
600
-					$latest_version = $cache;
601
-				}
602
-			}
603
-
604
-			// Check and auto download fonts locally.
605
-			if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
606
-				if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
607
-					$this->download_package( $latest_version );
608
-				}
609
-			}
610
-
611
-			return $latest_version;
612
-		}
613
-
614
-		/**
615
-		 * Get the latest Font Awesome version from the github API.
616
-		 *
617
-		 * @since 1.0.7
618
-		 * @return string The latest version number or `0` on API fail.
619
-		 */
620
-		public function get_latest_version_from_api() {
621
-			$version  = "0";
622
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
623
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
624
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
625
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
626
-					$version = $api_response['tag_name'];
627
-				}
628
-			}
629
-
630
-			return $version;
631
-		}
632
-
633
-		/**
634
-		 * Inline CSS for RTL language support.
635
-		 *
636
-		 * @since 1.0.13
637
-		 * @return string Inline CSS.
638
-		 */
639
-		public function rtl_inline_css() {
640
-			$inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
641
-
642
-			return $inline_css;
643
-		}
644
-
645
-		/**
646
-		 * Show any warnings as an admin notice.
647
-		 *
648
-		 * @return void
649
-		 */
650
-		public function admin_notices() {
651
-			$settings = $this->settings;
652
-
653
-			if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
654
-				if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
655
-					?>
555
+            }
556
+        }
557
+
558
+        /**
559
+         * Check a version number is valid and if so return it or else return an empty string.
560
+         *
561
+         * @param $version string The version number to check.
562
+         *
563
+         * @since 1.0.6
564
+         *
565
+         * @return string Either a valid version number or an empty string.
566
+         */
567
+        public function validate_version_number( $version ) {
568
+
569
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
570
+                // valid
571
+            } else {
572
+                $version = '';// not validated
573
+            }
574
+
575
+            return $version;
576
+        }
577
+
578
+
579
+        /**
580
+         * Get the latest version of Font Awesome.
581
+         *
582
+         * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
583
+         *
584
+         * @since 1.0.7
585
+         * @return mixed|string The latest version number found.
586
+         */
587
+        public function get_latest_version( $force_api = false ) {
588
+            $latest_version = $this->latest;
589
+
590
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
591
+
592
+            if ( $cache === false || $force_api ) { // its not set
593
+                $api_ver = $this->get_latest_version_from_api();
594
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
595
+                    $latest_version = $api_ver;
596
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
597
+                }
598
+            } elseif ( $this->validate_version_number( $cache ) ) {
599
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
600
+                    $latest_version = $cache;
601
+                }
602
+            }
603
+
604
+            // Check and auto download fonts locally.
605
+            if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
606
+                if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
607
+                    $this->download_package( $latest_version );
608
+                }
609
+            }
610
+
611
+            return $latest_version;
612
+        }
613
+
614
+        /**
615
+         * Get the latest Font Awesome version from the github API.
616
+         *
617
+         * @since 1.0.7
618
+         * @return string The latest version number or `0` on API fail.
619
+         */
620
+        public function get_latest_version_from_api() {
621
+            $version  = "0";
622
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
623
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
624
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
625
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
626
+                    $version = $api_response['tag_name'];
627
+                }
628
+            }
629
+
630
+            return $version;
631
+        }
632
+
633
+        /**
634
+         * Inline CSS for RTL language support.
635
+         *
636
+         * @since 1.0.13
637
+         * @return string Inline CSS.
638
+         */
639
+        public function rtl_inline_css() {
640
+            $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
641
+
642
+            return $inline_css;
643
+        }
644
+
645
+        /**
646
+         * Show any warnings as an admin notice.
647
+         *
648
+         * @return void
649
+         */
650
+        public function admin_notices() {
651
+            $settings = $this->settings;
652
+
653
+            if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
654
+                if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
655
+                    ?>
656 656
                     <div class="notice  notice-error is-dismissible">
657 657
                         <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p>
658 658
                     </div>
659 659
 					<?php
660
-				}
661
-			} else {
662
-				if ( ! empty( $settings ) ) {
663
-					if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
664
-						$link = admin_url('options-general.php?page=wp-font-awesome-settings');
665
-						?>
660
+                }
661
+            } else {
662
+                if ( ! empty( $settings ) ) {
663
+                    if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
664
+                        $link = admin_url('options-general.php?page=wp-font-awesome-settings');
665
+                        ?>
666 666
                         <div class="notice  notice-error is-dismissible">
667 667
                             <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p>
668 668
                         </div>
669 669
 						<?php
670
-					}
671
-				}
672
-			}
673
-		}
674
-
675
-		/**
676
-		 * Handle fontawesome add settings to download fontawesome to store locally.
677
-		 *
678
-		 * @since 1.1.1
679
-		 *
680
-		 * @param string $option The option name.
681
-		 * @param mixed  $value  The option value.
682
-		 */
683
-		public function add_option_wp_font_awesome_settings( $option, $value ) {
684
-			// Do nothing if WordPress is being installed.
685
-			if ( wp_installing() ) {
686
-				return;
687
-			}
688
-
689
-			if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
690
-				$version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
691
-
692
-				if ( ! empty( $version ) ) {
693
-					$response = $this->download_package( $version, $value );
694
-
695
-					if ( is_wp_error( $response ) ) {
696
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
697
-					}
698
-				}
699
-			}
700
-		}
701
-
702
-		/**
703
-		 * Handle fontawesome update settings to download fontawesome to store locally.
704
-		 *
705
-		 * @since 1.1.0
706
-		 *
707
-		 * @param mixed $old_value The old option value.
708
-		 * @param mixed $value     The new option value.
709
-		 */
710
-		public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
711
-			// Do nothing if WordPress is being installed.
712
-			if ( wp_installing() ) {
713
-				return;
714
-			}
715
-
716
-			if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
717
-				// Old values
718
-				$old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
719
-				$old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
720
-
721
-				// New values
722
-				$new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
723
-
724
-				if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
725
-					$response = $this->download_package( $new_version, $new_value );
726
-
727
-					if ( is_wp_error( $response ) ) {
728
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
729
-					}
730
-				}
731
-			}
732
-		}
733
-
734
-		/**
735
-		 * Get the fonts directory local path.
736
-		 *
737
-		 * @since 1.1.0
738
-		 *
739
-		 * @param string Fonts directory local path.
740
-		 */
741
-		public function get_fonts_dir() {
742
-			$upload_dir = wp_upload_dir( null, false );
743
-
744
-			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
745
-		}
746
-
747
-		/**
748
-		 * Get the fonts directory local url.
749
-		 *
750
-		 * @since 1.1.0
751
-		 *
752
-		 * @param string Fonts directory local url.
753
-		 */
754
-		public function get_fonts_url() {
755
-			$upload_dir = wp_upload_dir( null, false );
756
-
757
-			return $upload_dir['baseurl'] .  '/ayefonts/fa/';
758
-		}
759
-
760
-		/**
761
-		 * Check whether load locally active.
762
-		 *
763
-		 * @since 1.1.0
764
-		 *
765
-		 * @return bool True if active else false.
766
-		 */
767
-		public function has_local() {
768
-			if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
769
-				return true;
770
-			}
771
-
772
-			return false;
773
-		}
774
-
775
-		/**
776
-		 * Get the WP Filesystem access.
777
-		 *
778
-		 * @since 1.1.0
779
-		 *
780
-		 * @return object The WP Filesystem.
781
-		 */
782
-		public function get_wp_filesystem() {
783
-			if ( ! function_exists( 'get_filesystem_method' ) ) {
784
-				require_once( ABSPATH . "/wp-admin/includes/file.php" );
785
-			}
786
-
787
-			$access_type = get_filesystem_method();
788
-
789
-			if ( $access_type === 'direct' ) {
790
-				/* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
791
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
792
-
793
-				/* Initialize the API */
794
-				if ( ! WP_Filesystem( $creds ) ) {
795
-					/* Any problems and we exit */
796
-					return false;
797
-				}
798
-
799
-				global $wp_filesystem;
800
-
801
-				return $wp_filesystem;
802
-				/* Do our file manipulations below */
803
-			} else if ( defined( 'FTP_USER' ) ) {
804
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
805
-
806
-				/* Initialize the API */
807
-				if ( ! WP_Filesystem( $creds ) ) {
808
-					/* Any problems and we exit */
809
-					return false;
810
-				}
811
-
812
-				global $wp_filesystem;
813
-
814
-				return $wp_filesystem;
815
-			} else {
816
-				/* Don't have direct write access. Prompt user with our notice */
817
-				return false;
818
-			}
819
-		}
820
-
821
-		/**
822
-		 * Download the fontawesome package file.
823
-		 *
824
-		 * @since 1.1.0
825
-		 *
826
-		 * @param mixed $version The font awesome.
827
-		 * @param array $option Fontawesome settings.
828
-		 * @return WP_ERROR|bool Error on fail and true on success.
829
-		 */
830
-		public function download_package( $version, $option = array() ) {
831
-			$filename = 'fontawesome-free-' . $version . '-web';
832
-			$url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
833
-
834
-			if ( ! function_exists( 'wp_handle_upload' ) ) {
835
-				require_once ABSPATH . 'wp-admin/includes/file.php';
836
-			}
837
-
838
-			$download_file = download_url( esc_url_raw( $url ) );
839
-
840
-			if ( is_wp_error( $download_file ) ) {
841
-				return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) );
842
-			} else if ( empty( $download_file ) ) {
843
-				return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) );
844
-			}
845
-
846
-			$response = $this->extract_package( $download_file, $filename, true );
847
-
848
-			// Update local version.
849
-			if ( is_wp_error( $response ) ) {
850
-				return $response;
851
-			} else if ( $response ) {
852
-				if ( empty( $option ) ) {
853
-					$option = get_option( 'wp-font-awesome-settings' );
854
-				}
855
-
856
-				$option['local_version'] = $version;
857
-
858
-				// Remove action to prevent looping.
859
-				remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
860
-
861
-				update_option( 'wp-font-awesome-settings', $option );
862
-
863
-				return true;
864
-			}
865
-
866
-			return false;
867
-		}
868
-
869
-		/**
870
-		 * Extract the fontawesome package file.
871
-		 *
872
-		 * @since 1.1.0
873
-		 *
874
-		 * @param string $package The package file path.
875
-		 * @param string $dirname Package file name.
876
-		 * @param bool   $delete_package Delete temp file or not.
877
-		 * @return WP_Error|bool True on success WP_Error on fail.
878
-		 */
879
-		public function extract_package( $package, $dirname = '', $delete_package = false ) {
880
-			global $wp_filesystem;
881
-
882
-			$wp_filesystem = $this->get_wp_filesystem();
883
-
884
-			if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
885
-				return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) );
886
-			} else if ( empty( $wp_filesystem ) ) {
887
-				return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) );
888
-			}
889
-
890
-			$fonts_dir = $this->get_fonts_dir();
891
-			$fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
892
-
893
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
894
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
895
-			}
896
-
897
-			// Unzip package to working directory.
898
-			$result = unzip_file( $package, $fonts_tmp_dir );
899
-
900
-			if ( is_wp_error( $result ) ) {
901
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
902
-
903
-				if ( 'incompatible_archive' === $result->get_error_code() ) {
904
-					return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) );
905
-				}
906
-
907
-				return $result;
908
-			}
909
-
910
-			if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
911
-				$wp_filesystem->delete( $fonts_dir, true );
912
-			}
913
-
914
-			$extract_dir = $fonts_tmp_dir;
915
-
916
-			if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
917
-				$extract_dir .= $dirname . DIRECTORY_SEPARATOR;
918
-			}
919
-
920
-			try {
921
-				$return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
922
-			} catch ( Exception $e ) {
923
-				$return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) );
924
-			}
925
-
926
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
927
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
928
-			}
929
-
930
-			// Once extracted, delete the package if required.
931
-			if ( $delete_package ) {
932
-				unlink( $package );
933
-			}
934
-
935
-			return $return;
936
-		}
937
-	}
938
-
939
-	/**
940
-	 * Run the class if found.
941
-	 */
942
-	WP_Font_Awesome_Settings::instance();
670
+                    }
671
+                }
672
+            }
673
+        }
674
+
675
+        /**
676
+         * Handle fontawesome add settings to download fontawesome to store locally.
677
+         *
678
+         * @since 1.1.1
679
+         *
680
+         * @param string $option The option name.
681
+         * @param mixed  $value  The option value.
682
+         */
683
+        public function add_option_wp_font_awesome_settings( $option, $value ) {
684
+            // Do nothing if WordPress is being installed.
685
+            if ( wp_installing() ) {
686
+                return;
687
+            }
688
+
689
+            if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
690
+                $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
691
+
692
+                if ( ! empty( $version ) ) {
693
+                    $response = $this->download_package( $version, $value );
694
+
695
+                    if ( is_wp_error( $response ) ) {
696
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
697
+                    }
698
+                }
699
+            }
700
+        }
701
+
702
+        /**
703
+         * Handle fontawesome update settings to download fontawesome to store locally.
704
+         *
705
+         * @since 1.1.0
706
+         *
707
+         * @param mixed $old_value The old option value.
708
+         * @param mixed $value     The new option value.
709
+         */
710
+        public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
711
+            // Do nothing if WordPress is being installed.
712
+            if ( wp_installing() ) {
713
+                return;
714
+            }
715
+
716
+            if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
717
+                // Old values
718
+                $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
719
+                $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
720
+
721
+                // New values
722
+                $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
723
+
724
+                if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
725
+                    $response = $this->download_package( $new_version, $new_value );
726
+
727
+                    if ( is_wp_error( $response ) ) {
728
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
729
+                    }
730
+                }
731
+            }
732
+        }
733
+
734
+        /**
735
+         * Get the fonts directory local path.
736
+         *
737
+         * @since 1.1.0
738
+         *
739
+         * @param string Fonts directory local path.
740
+         */
741
+        public function get_fonts_dir() {
742
+            $upload_dir = wp_upload_dir( null, false );
743
+
744
+            return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
745
+        }
746
+
747
+        /**
748
+         * Get the fonts directory local url.
749
+         *
750
+         * @since 1.1.0
751
+         *
752
+         * @param string Fonts directory local url.
753
+         */
754
+        public function get_fonts_url() {
755
+            $upload_dir = wp_upload_dir( null, false );
756
+
757
+            return $upload_dir['baseurl'] .  '/ayefonts/fa/';
758
+        }
759
+
760
+        /**
761
+         * Check whether load locally active.
762
+         *
763
+         * @since 1.1.0
764
+         *
765
+         * @return bool True if active else false.
766
+         */
767
+        public function has_local() {
768
+            if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
769
+                return true;
770
+            }
771
+
772
+            return false;
773
+        }
774
+
775
+        /**
776
+         * Get the WP Filesystem access.
777
+         *
778
+         * @since 1.1.0
779
+         *
780
+         * @return object The WP Filesystem.
781
+         */
782
+        public function get_wp_filesystem() {
783
+            if ( ! function_exists( 'get_filesystem_method' ) ) {
784
+                require_once( ABSPATH . "/wp-admin/includes/file.php" );
785
+            }
786
+
787
+            $access_type = get_filesystem_method();
788
+
789
+            if ( $access_type === 'direct' ) {
790
+                /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
791
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
792
+
793
+                /* Initialize the API */
794
+                if ( ! WP_Filesystem( $creds ) ) {
795
+                    /* Any problems and we exit */
796
+                    return false;
797
+                }
798
+
799
+                global $wp_filesystem;
800
+
801
+                return $wp_filesystem;
802
+                /* Do our file manipulations below */
803
+            } else if ( defined( 'FTP_USER' ) ) {
804
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
805
+
806
+                /* Initialize the API */
807
+                if ( ! WP_Filesystem( $creds ) ) {
808
+                    /* Any problems and we exit */
809
+                    return false;
810
+                }
811
+
812
+                global $wp_filesystem;
813
+
814
+                return $wp_filesystem;
815
+            } else {
816
+                /* Don't have direct write access. Prompt user with our notice */
817
+                return false;
818
+            }
819
+        }
820
+
821
+        /**
822
+         * Download the fontawesome package file.
823
+         *
824
+         * @since 1.1.0
825
+         *
826
+         * @param mixed $version The font awesome.
827
+         * @param array $option Fontawesome settings.
828
+         * @return WP_ERROR|bool Error on fail and true on success.
829
+         */
830
+        public function download_package( $version, $option = array() ) {
831
+            $filename = 'fontawesome-free-' . $version . '-web';
832
+            $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
833
+
834
+            if ( ! function_exists( 'wp_handle_upload' ) ) {
835
+                require_once ABSPATH . 'wp-admin/includes/file.php';
836
+            }
837
+
838
+            $download_file = download_url( esc_url_raw( $url ) );
839
+
840
+            if ( is_wp_error( $download_file ) ) {
841
+                return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) );
842
+            } else if ( empty( $download_file ) ) {
843
+                return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) );
844
+            }
845
+
846
+            $response = $this->extract_package( $download_file, $filename, true );
847
+
848
+            // Update local version.
849
+            if ( is_wp_error( $response ) ) {
850
+                return $response;
851
+            } else if ( $response ) {
852
+                if ( empty( $option ) ) {
853
+                    $option = get_option( 'wp-font-awesome-settings' );
854
+                }
855
+
856
+                $option['local_version'] = $version;
857
+
858
+                // Remove action to prevent looping.
859
+                remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
860
+
861
+                update_option( 'wp-font-awesome-settings', $option );
862
+
863
+                return true;
864
+            }
865
+
866
+            return false;
867
+        }
868
+
869
+        /**
870
+         * Extract the fontawesome package file.
871
+         *
872
+         * @since 1.1.0
873
+         *
874
+         * @param string $package The package file path.
875
+         * @param string $dirname Package file name.
876
+         * @param bool   $delete_package Delete temp file or not.
877
+         * @return WP_Error|bool True on success WP_Error on fail.
878
+         */
879
+        public function extract_package( $package, $dirname = '', $delete_package = false ) {
880
+            global $wp_filesystem;
881
+
882
+            $wp_filesystem = $this->get_wp_filesystem();
883
+
884
+            if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
885
+                return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) );
886
+            } else if ( empty( $wp_filesystem ) ) {
887
+                return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) );
888
+            }
889
+
890
+            $fonts_dir = $this->get_fonts_dir();
891
+            $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
892
+
893
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
894
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
895
+            }
896
+
897
+            // Unzip package to working directory.
898
+            $result = unzip_file( $package, $fonts_tmp_dir );
899
+
900
+            if ( is_wp_error( $result ) ) {
901
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
902
+
903
+                if ( 'incompatible_archive' === $result->get_error_code() ) {
904
+                    return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) );
905
+                }
906
+
907
+                return $result;
908
+            }
909
+
910
+            if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
911
+                $wp_filesystem->delete( $fonts_dir, true );
912
+            }
913
+
914
+            $extract_dir = $fonts_tmp_dir;
915
+
916
+            if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
917
+                $extract_dir .= $dirname . DIRECTORY_SEPARATOR;
918
+            }
919
+
920
+            try {
921
+                $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
922
+            } catch ( Exception $e ) {
923
+                $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) );
924
+            }
925
+
926
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
927
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
928
+            }
929
+
930
+            // Once extracted, delete the package if required.
931
+            if ( $delete_package ) {
932
+                unlink( $package );
933
+            }
934
+
935
+            return $return;
936
+        }
937
+    }
938
+
939
+    /**
940
+     * Run the class if found.
941
+     */
942
+    WP_Font_Awesome_Settings::instance();
943 943
 }
Please login to merge, or discard this patch.
includes/class-getpaid-subscriptions-query.php 1 patch
Indentation   +505 added lines, -505 removed lines patch added patch discarded remove patch
@@ -16,512 +16,512 @@
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Subscriptions_Query {
18 18
 
19
-	/**
20
-	 * Query vars, after parsing
21
-	 *
22
-	 * @since 1.0.19
23
-	 * @var array
24
-	 */
25
-	public $query_vars = array();
26
-
27
-	/**
28
-	 * List of found subscriptions.
29
-	 *
30
-	 * @since 1.0.19
31
-	 * @var array
32
-	 */
33
-	private $results;
34
-
35
-	/**
36
-	 * Total number of found subscriptions for the current query
37
-	 *
38
-	 * @since 1.0.19
39
-	 * @var int
40
-	 */
41
-	private $total_subscriptions = 0;
42
-
43
-	/**
44
-	 * The SQL query used to fetch matching subscriptions.
45
-	 *
46
-	 * @since 1.0.19
47
-	 * @var string
48
-	 */
49
-	public $request;
50
-
51
-	// SQL clauses
52
-
53
-	/**
54
-	 * Contains the 'FIELDS' sql clause
55
-	 *
56
-	 * @since 1.0.19
57
-	 * @var string
58
-	 */
59
-	public $query_fields;
60
-
61
-	/**
62
-	 * Contains the 'FROM' sql clause
63
-	 *
64
-	 * @since 1.0.19
65
-	 * @var string
66
-	 */
67
-	public $query_from;
68
-
69
-	/**
70
-	 * Contains the 'WHERE' sql clause
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $query_where;
76
-
77
-	/**
78
-	 * Contains the 'ORDER BY' sql clause
79
-	 *
80
-	 * @since 1.0.19
81
-	 * @var string
82
-	 */
83
-	public $query_orderby;
84
-
85
-	/**
86
-	 * Contains the 'LIMIT' sql clause
87
-	 *
88
-	 * @since 1.0.19
89
-	 * @var string
90
-	 */
91
-	public $query_limit;
92
-
93
-	/**
94
-	 * Class constructor.
95
-	 *
96
-	 * @since 1.0.19
97
-	 *
98
-	 * @param null|string|array $query Optional. The query variables.
99
-	 */
100
-	public function __construct( $query = null ) {
101
-		if ( ! is_null( $query ) ) {
102
-			$this->prepare_query( $query );
103
-			$this->query();
104
-		}
105
-	}
106
-
107
-	/**
108
-	 * Fills in missing query variables with default values.
109
-	 *
110
-	 * @since 1.0.19
111
-	 *
112
-	 * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113
-	 * @return array Complete query variables with undefined ones filled in with defaults.
114
-	 */
115
-	public static function fill_query_vars( $args ) {
116
-		$defaults = array(
117
-			'status'          => 'all',
118
-			'customer_in'     => array(),
119
-			'customer_not_in' => array(),
120
-			'product_in'      => array(),
121
-			'product_not_in'  => array(),
122
-			'include'         => array(),
123
-			'exclude'         => array(),
124
-			'orderby'         => 'id',
125
-			'order'           => 'DESC',
126
-			'offset'          => '',
127
-			'number'          => 10,
128
-			'paged'           => 1,
129
-			'count_total'     => true,
130
-			'fields'          => 'all',
131
-		);
132
-
133
-		return wp_parse_args( $args, $defaults );
134
-	}
135
-
136
-	/**
137
-	 * Prepare the query variables.
138
-	 *
139
-	 * @since 1.0.19
140
-	 *
141
-	 * @global wpdb $wpdb WordPress database abstraction object.
142
-	 *
143
-	 * @param string|array $query {
144
-	 *     Optional. Array or string of Query parameters.
145
-	 *
146
-	 *     @type string|array $status              The subscription status to filter by. Can either be a single status or an array of statuses.
147
-	 *                                             Default is all.
148
-	 *     @type int[]        $customer_in         An array of customer ids to filter by.
149
-	 *     @type int[]        $customer_not_in     An array of customer ids whose subscriptions should be excluded.
150
-	 *     @type int[]        $invoice_in          An array of invoice ids to filter by.
151
-	 *     @type int[]        $invoice_not_in      An array of invoice ids whose subscriptions should be excluded.
152
-	 *     @type int[]        $product_in          An array of product ids to filter by.
153
-	 *     @type int[]        $product_not_in      An array of product ids whose subscriptions should be excluded.
154
-	 *     @type array        $date_created_query  A WP_Date_Query compatible array use to filter subscriptions by their date of creation.
155
-	 *     @type array        $date_expires_query  A WP_Date_Query compatible array use to filter subscriptions by their expiration date.
156
-	 *     @type array        $include             An array of subscription IDs to include. Default empty array.
157
-	 *     @type array        $exclude             An array of subscription IDs to exclude. Default empty array.
158
-	 *     @type string|array $orderby             Field(s) to sort the retrieved subscription by. May be a single value,
159
-	 *                                             an array of values, or a multi-dimensional array with fields as
160
-	 *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
161
-	 *                                             'id', 'customer_id', 'frequency', 'period', 'initial_amount,
162
-	 *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
163
-	 *                                             'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ).
164
-	 *     @type string       $order               Designates ascending or descending order of subscriptions. Order values
165
-	 *                                             passed as part of an `$orderby` array take precedence over this
166
-	 *                                             parameter. Accepts 'ASC', 'DESC'. Default 'DESC'.
167
-	 *     @type int          $offset              Number of subscriptions to offset in retrieved results. Can be used in
168
-	 *                                             conjunction with pagination. Default 0.
169
-	 *     @type int          $number              Number of subscriptions to limit the query for. Can be used in
170
-	 *                                             conjunction with pagination. Value -1 (all) is supported, but
171
-	 *                                             should be used with caution on larger sites.
172
-	 *                                             Default 10.
173
-	 *     @type int          $paged               When used with number, defines the page of results to return.
174
-	 *                                             Default 1.
175
-	 *     @type bool         $count_total         Whether to count the total number of subscriptions found. If pagination
176
-	 *                                             is not needed, setting this to false can improve performance.
177
-	 *                                             Default true.
178
-	 *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
179
-	 *                                             of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount,
180
-	 *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
181
-	 *                                             'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'.
182
-	 *                                             Use 'all' for all fields. Default 'all'.
183
-	 * }
184
-	 */
185
-	public function prepare_query( $query = array() ) {
186
-		global $wpdb;
187
-
188
-		if ( empty( $this->query_vars ) || ! empty( $query ) ) {
189
-			$this->query_limit = null;
190
-			$this->query_vars  = $this->fill_query_vars( $query );
191
-		}
192
-
193
-		if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
194
-			$this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
195
-		}
196
-
197
-		do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
198
-
199
-		// Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
200
-		$qv                =& $this->query_vars;
201
-		$qv                = $this->fill_query_vars( $qv );
202
-		$table             = $wpdb->prefix . 'wpinv_subscriptions';
203
-		$this->query_from  = "FROM $table";
204
-
205
-		// Prepare query fields.
206
-		$this->prepare_query_fields( $qv, $table );
207
-
208
-		// Prepare query where.
209
-		$this->prepare_query_where( $qv, $table );
210
-
211
-		// Prepare query order.
212
-		$this->prepare_query_order( $qv, $table );
213
-
214
-		// limit
215
-		if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
216
-			if ( $qv['offset'] ) {
217
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
218
-			} else {
219
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
220
-			}
221
-		}
222
-
223
-		do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
224
-	}
225
-
226
-	/**
227
-	 * Prepares the query fields.
228
-	 *
229
-	 * @since 1.0.19
230
-	 *
231
-	 * @param array $qv Query vars.
232
-	 * @param string $table Table name.
233
-	 */
234
-	protected function prepare_query_fields( &$qv, $table ) {
235
-
236
-		if ( is_array( $qv['fields'] ) ) {
237
-			$qv['fields'] = array_unique( $qv['fields'] );
238
-
239
-			$query_fields = array();
240
-			foreach ( $qv['fields'] as $field ) {
241
-				$field          = sanitize_key( $field );
242
-				$query_fields[] = "$table.`$field`";
243
-			}
244
-			$this->query_fields = implode( ',', $query_fields );
245
-		} else {
246
-			$this->query_fields = "$table.*";
247
-		}
248
-
249
-		if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
250
-			$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
251
-		}
252
-
253
-	}
254
-
255
-	/**
256
-	 * Prepares the query where.
257
-	 *
258
-	 * @since 1.0.19
259
-	 *
260
-	 * @param array $qv Query vars.
261
-	 * @param string $table Table name.
262
-	 */
263
-	protected function prepare_query_where( &$qv, $table ) {
264
-		global $wpdb;
265
-		$this->query_where = 'WHERE 1=1';
266
-
267
-		// Status.
268
-		if ( 'all' !== $qv['status'] ) {
269
-			$statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
270
-			$prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
271
-			$this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
272
-		}
273
-
274
-		if ( ! empty( $qv['customer_in'] ) ) {
275
-			$customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
276
-			$this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
277
-		} elseif ( ! empty( $qv['customer_not_in'] ) ) {
278
-			$customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
279
-			$this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
280
-		}
281
-
282
-		if ( ! empty( $qv['product_in'] ) ) {
283
-			$product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
284
-			$this->query_where .= " AND $table.`product_id` IN ($product_in)";
285
-		} elseif ( ! empty( $qv['product_not_in'] ) ) {
286
-			$product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
287
-			$this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
288
-		}
289
-
290
-		if ( ! empty( $qv['invoice_in'] ) ) {
291
-			$invoice_in         = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) );
292
-			$this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)";
293
-		} elseif ( ! empty( $qv['invoice_not_in'] ) ) {
294
-			$invoice_not_in     = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) );
295
-			$this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)";
296
-		}
297
-
298
-		if ( ! empty( $qv['include'] ) ) {
299
-			$include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
300
-			$this->query_where .= " AND $table.`id` IN ($include)";
301
-		} elseif ( ! empty( $qv['exclude'] ) ) {
302
-			$exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
303
-			$this->query_where .= " AND $table.`id` NOT IN ($exclude)";
304
-		}
305
-
306
-		// Date queries are allowed for the subscription creation date.
307
-		if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
308
-			$date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
309
-			$this->query_where .= $date_created_query->get_sql();
310
-		}
311
-
312
-		// Date queries are also allowed for the subscription expiration date.
313
-		if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
314
-			$date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
315
-			$this->query_where .= $date_expires_query->get_sql();
316
-		}
317
-
318
-	}
319
-
320
-	/**
321
-	 * Prepares the query order.
322
-	 *
323
-	 * @since 1.0.19
324
-	 *
325
-	 * @param array $qv Query vars.
326
-	 * @param string $table Table name.
327
-	 */
328
-	protected function prepare_query_order( &$qv, $table ) {
329
-
330
-		// sorting.
331
-		$qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
332
-		$order       = $this->parse_order( $qv['order'] );
333
-
334
-		// Default order is by 'id' (latest subscriptions).
335
-		if ( empty( $qv['orderby'] ) ) {
336
-			$qv['orderby'] = array( 'id' );
337
-		}
338
-
339
-		// 'orderby' values may be an array, comma- or space-separated list.
340
-		$ordersby      = array_filter( wpinv_parse_list( $qv['orderby'] ) );
341
-
342
-		$orderby_array = array();
343
-		foreach ( $ordersby as $_key => $_value ) {
344
-
345
-			if ( is_int( $_key ) ) {
346
-				// Integer key means this is a flat array of 'orderby' fields.
347
-				$_orderby = $_value;
348
-				$_order   = $order;
349
-			} else {
350
-				// Non-integer key means that the key is the field and the value is ASC/DESC.
351
-				$_orderby = $_key;
352
-				$_order   = $_value;
353
-			}
354
-
355
-			$parsed = $this->parse_orderby( $_orderby, $table );
356
-
357
-			if ( $parsed ) {
358
-				$orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
359
-			}
19
+    /**
20
+     * Query vars, after parsing
21
+     *
22
+     * @since 1.0.19
23
+     * @var array
24
+     */
25
+    public $query_vars = array();
26
+
27
+    /**
28
+     * List of found subscriptions.
29
+     *
30
+     * @since 1.0.19
31
+     * @var array
32
+     */
33
+    private $results;
34
+
35
+    /**
36
+     * Total number of found subscriptions for the current query
37
+     *
38
+     * @since 1.0.19
39
+     * @var int
40
+     */
41
+    private $total_subscriptions = 0;
42
+
43
+    /**
44
+     * The SQL query used to fetch matching subscriptions.
45
+     *
46
+     * @since 1.0.19
47
+     * @var string
48
+     */
49
+    public $request;
50
+
51
+    // SQL clauses
52
+
53
+    /**
54
+     * Contains the 'FIELDS' sql clause
55
+     *
56
+     * @since 1.0.19
57
+     * @var string
58
+     */
59
+    public $query_fields;
60
+
61
+    /**
62
+     * Contains the 'FROM' sql clause
63
+     *
64
+     * @since 1.0.19
65
+     * @var string
66
+     */
67
+    public $query_from;
68
+
69
+    /**
70
+     * Contains the 'WHERE' sql clause
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $query_where;
76
+
77
+    /**
78
+     * Contains the 'ORDER BY' sql clause
79
+     *
80
+     * @since 1.0.19
81
+     * @var string
82
+     */
83
+    public $query_orderby;
84
+
85
+    /**
86
+     * Contains the 'LIMIT' sql clause
87
+     *
88
+     * @since 1.0.19
89
+     * @var string
90
+     */
91
+    public $query_limit;
92
+
93
+    /**
94
+     * Class constructor.
95
+     *
96
+     * @since 1.0.19
97
+     *
98
+     * @param null|string|array $query Optional. The query variables.
99
+     */
100
+    public function __construct( $query = null ) {
101
+        if ( ! is_null( $query ) ) {
102
+            $this->prepare_query( $query );
103
+            $this->query();
104
+        }
105
+    }
106
+
107
+    /**
108
+     * Fills in missing query variables with default values.
109
+     *
110
+     * @since 1.0.19
111
+     *
112
+     * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113
+     * @return array Complete query variables with undefined ones filled in with defaults.
114
+     */
115
+    public static function fill_query_vars( $args ) {
116
+        $defaults = array(
117
+            'status'          => 'all',
118
+            'customer_in'     => array(),
119
+            'customer_not_in' => array(),
120
+            'product_in'      => array(),
121
+            'product_not_in'  => array(),
122
+            'include'         => array(),
123
+            'exclude'         => array(),
124
+            'orderby'         => 'id',
125
+            'order'           => 'DESC',
126
+            'offset'          => '',
127
+            'number'          => 10,
128
+            'paged'           => 1,
129
+            'count_total'     => true,
130
+            'fields'          => 'all',
131
+        );
132
+
133
+        return wp_parse_args( $args, $defaults );
134
+    }
135
+
136
+    /**
137
+     * Prepare the query variables.
138
+     *
139
+     * @since 1.0.19
140
+     *
141
+     * @global wpdb $wpdb WordPress database abstraction object.
142
+     *
143
+     * @param string|array $query {
144
+     *     Optional. Array or string of Query parameters.
145
+     *
146
+     *     @type string|array $status              The subscription status to filter by. Can either be a single status or an array of statuses.
147
+     *                                             Default is all.
148
+     *     @type int[]        $customer_in         An array of customer ids to filter by.
149
+     *     @type int[]        $customer_not_in     An array of customer ids whose subscriptions should be excluded.
150
+     *     @type int[]        $invoice_in          An array of invoice ids to filter by.
151
+     *     @type int[]        $invoice_not_in      An array of invoice ids whose subscriptions should be excluded.
152
+     *     @type int[]        $product_in          An array of product ids to filter by.
153
+     *     @type int[]        $product_not_in      An array of product ids whose subscriptions should be excluded.
154
+     *     @type array        $date_created_query  A WP_Date_Query compatible array use to filter subscriptions by their date of creation.
155
+     *     @type array        $date_expires_query  A WP_Date_Query compatible array use to filter subscriptions by their expiration date.
156
+     *     @type array        $include             An array of subscription IDs to include. Default empty array.
157
+     *     @type array        $exclude             An array of subscription IDs to exclude. Default empty array.
158
+     *     @type string|array $orderby             Field(s) to sort the retrieved subscription by. May be a single value,
159
+     *                                             an array of values, or a multi-dimensional array with fields as
160
+     *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
161
+     *                                             'id', 'customer_id', 'frequency', 'period', 'initial_amount,
162
+     *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
163
+     *                                             'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ).
164
+     *     @type string       $order               Designates ascending or descending order of subscriptions. Order values
165
+     *                                             passed as part of an `$orderby` array take precedence over this
166
+     *                                             parameter. Accepts 'ASC', 'DESC'. Default 'DESC'.
167
+     *     @type int          $offset              Number of subscriptions to offset in retrieved results. Can be used in
168
+     *                                             conjunction with pagination. Default 0.
169
+     *     @type int          $number              Number of subscriptions to limit the query for. Can be used in
170
+     *                                             conjunction with pagination. Value -1 (all) is supported, but
171
+     *                                             should be used with caution on larger sites.
172
+     *                                             Default 10.
173
+     *     @type int          $paged               When used with number, defines the page of results to return.
174
+     *                                             Default 1.
175
+     *     @type bool         $count_total         Whether to count the total number of subscriptions found. If pagination
176
+     *                                             is not needed, setting this to false can improve performance.
177
+     *                                             Default true.
178
+     *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
179
+     *                                             of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount,
180
+     *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
181
+     *                                             'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'.
182
+     *                                             Use 'all' for all fields. Default 'all'.
183
+     * }
184
+     */
185
+    public function prepare_query( $query = array() ) {
186
+        global $wpdb;
187
+
188
+        if ( empty( $this->query_vars ) || ! empty( $query ) ) {
189
+            $this->query_limit = null;
190
+            $this->query_vars  = $this->fill_query_vars( $query );
191
+        }
192
+
193
+        if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
194
+            $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
195
+        }
196
+
197
+        do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
198
+
199
+        // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
200
+        $qv                =& $this->query_vars;
201
+        $qv                = $this->fill_query_vars( $qv );
202
+        $table             = $wpdb->prefix . 'wpinv_subscriptions';
203
+        $this->query_from  = "FROM $table";
204
+
205
+        // Prepare query fields.
206
+        $this->prepare_query_fields( $qv, $table );
207
+
208
+        // Prepare query where.
209
+        $this->prepare_query_where( $qv, $table );
210
+
211
+        // Prepare query order.
212
+        $this->prepare_query_order( $qv, $table );
213
+
214
+        // limit
215
+        if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
216
+            if ( $qv['offset'] ) {
217
+                $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
218
+            } else {
219
+                $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
220
+            }
221
+        }
222
+
223
+        do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
224
+    }
225
+
226
+    /**
227
+     * Prepares the query fields.
228
+     *
229
+     * @since 1.0.19
230
+     *
231
+     * @param array $qv Query vars.
232
+     * @param string $table Table name.
233
+     */
234
+    protected function prepare_query_fields( &$qv, $table ) {
235
+
236
+        if ( is_array( $qv['fields'] ) ) {
237
+            $qv['fields'] = array_unique( $qv['fields'] );
238
+
239
+            $query_fields = array();
240
+            foreach ( $qv['fields'] as $field ) {
241
+                $field          = sanitize_key( $field );
242
+                $query_fields[] = "$table.`$field`";
243
+            }
244
+            $this->query_fields = implode( ',', $query_fields );
245
+        } else {
246
+            $this->query_fields = "$table.*";
247
+        }
248
+
249
+        if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
250
+            $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
251
+        }
252
+
253
+    }
254
+
255
+    /**
256
+     * Prepares the query where.
257
+     *
258
+     * @since 1.0.19
259
+     *
260
+     * @param array $qv Query vars.
261
+     * @param string $table Table name.
262
+     */
263
+    protected function prepare_query_where( &$qv, $table ) {
264
+        global $wpdb;
265
+        $this->query_where = 'WHERE 1=1';
266
+
267
+        // Status.
268
+        if ( 'all' !== $qv['status'] ) {
269
+            $statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
270
+            $prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
271
+            $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
272
+        }
273
+
274
+        if ( ! empty( $qv['customer_in'] ) ) {
275
+            $customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
276
+            $this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
277
+        } elseif ( ! empty( $qv['customer_not_in'] ) ) {
278
+            $customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
279
+            $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
280
+        }
281
+
282
+        if ( ! empty( $qv['product_in'] ) ) {
283
+            $product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
284
+            $this->query_where .= " AND $table.`product_id` IN ($product_in)";
285
+        } elseif ( ! empty( $qv['product_not_in'] ) ) {
286
+            $product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
287
+            $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
288
+        }
289
+
290
+        if ( ! empty( $qv['invoice_in'] ) ) {
291
+            $invoice_in         = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) );
292
+            $this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)";
293
+        } elseif ( ! empty( $qv['invoice_not_in'] ) ) {
294
+            $invoice_not_in     = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) );
295
+            $this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)";
296
+        }
297
+
298
+        if ( ! empty( $qv['include'] ) ) {
299
+            $include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
300
+            $this->query_where .= " AND $table.`id` IN ($include)";
301
+        } elseif ( ! empty( $qv['exclude'] ) ) {
302
+            $exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
303
+            $this->query_where .= " AND $table.`id` NOT IN ($exclude)";
304
+        }
305
+
306
+        // Date queries are allowed for the subscription creation date.
307
+        if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
308
+            $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
309
+            $this->query_where .= $date_created_query->get_sql();
310
+        }
311
+
312
+        // Date queries are also allowed for the subscription expiration date.
313
+        if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
314
+            $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
315
+            $this->query_where .= $date_expires_query->get_sql();
316
+        }
317
+
318
+    }
319
+
320
+    /**
321
+     * Prepares the query order.
322
+     *
323
+     * @since 1.0.19
324
+     *
325
+     * @param array $qv Query vars.
326
+     * @param string $table Table name.
327
+     */
328
+    protected function prepare_query_order( &$qv, $table ) {
329
+
330
+        // sorting.
331
+        $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
332
+        $order       = $this->parse_order( $qv['order'] );
333
+
334
+        // Default order is by 'id' (latest subscriptions).
335
+        if ( empty( $qv['orderby'] ) ) {
336
+            $qv['orderby'] = array( 'id' );
337
+        }
338
+
339
+        // 'orderby' values may be an array, comma- or space-separated list.
340
+        $ordersby      = array_filter( wpinv_parse_list( $qv['orderby'] ) );
341
+
342
+        $orderby_array = array();
343
+        foreach ( $ordersby as $_key => $_value ) {
344
+
345
+            if ( is_int( $_key ) ) {
346
+                // Integer key means this is a flat array of 'orderby' fields.
347
+                $_orderby = $_value;
348
+                $_order   = $order;
349
+            } else {
350
+                // Non-integer key means that the key is the field and the value is ASC/DESC.
351
+                $_orderby = $_key;
352
+                $_order   = $_value;
353
+            }
354
+
355
+            $parsed = $this->parse_orderby( $_orderby, $table );
356
+
357
+            if ( $parsed ) {
358
+                $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
359
+            }
360 360
 }
361 361
 
362
-		// If no valid clauses were found, order by id.
363
-		if ( empty( $orderby_array ) ) {
364
-			$orderby_array[] = "id $order";
365
-		}
366
-
367
-		$this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
368
-
369
-	}
370
-
371
-	/**
372
-	 * Execute the query, with the current variables.
373
-	 *
374
-	 * @since 1.0.19
375
-	 *
376
-	 * @global wpdb $wpdb WordPress database abstraction object.
377
-	 */
378
-	public function query() {
379
-		global $wpdb;
380
-
381
-		$qv =& $this->query_vars;
382
-
383
-		// Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
384
-		// total_subscriptions property.
385
-		$this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
386
-
387
-		if ( null === $this->results ) {
388
-			$this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
389
-
390
-			if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
391
-				$this->results = $wpdb->get_results( $this->request );
392
-			} else {
393
-				$this->results = $wpdb->get_col( $this->request );
394
-			}
395
-
396
-			if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
397
-				$found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
398
-				$this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
399
-			}
400
-		}
401
-
402
-		if ( 'all' == $qv['fields'] ) {
403
-			foreach ( $this->results as $key => $subscription ) {
404
-				$this->set_cache( $subscription->id, $subscription, 'getpaid_subscriptions' );
405
-				$this->set_cache( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' );
406
-				$this->set_cache( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
407
-				$this->set_cache( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
408
-				$this->results[ $key ] = new WPInv_Subscription( $subscription );
409
-			}
410
-		}
411
-
412
-	}
413
-
414
-	/**
415
-	 * Set cache
416
-	 *
417
-	 * @param string  $id
418
-	 * @param mixed   $data
419
-	 * @param string  $group
420
-	 * @param integer $expire
421
-	 * @return boolean
422
-	 */
423
-	public function set_cache( $key, $data, $group = '', $expire = 0 ) {
424
-
425
-		if ( empty( $key ) ) {
426
-			return false;
427
-		}
428
-
429
-		wp_cache_set( $key, $data, $group, $expire );
430
-	}
431
-
432
-	/**
433
-	 * Retrieve query variable.
434
-	 *
435
-	 * @since 1.0.19
436
-	 *
437
-	 * @param string $query_var Query variable key.
438
-	 * @return mixed
439
-	 */
440
-	public function get( $query_var ) {
441
-		if ( isset( $this->query_vars[ $query_var ] ) ) {
442
-			return $this->query_vars[ $query_var ];
443
-		}
444
-
445
-		return null;
446
-	}
447
-
448
-	/**
449
-	 * Set query variable.
450
-	 *
451
-	 * @since 1.0.19
452
-	 *
453
-	 * @param string $query_var Query variable key.
454
-	 * @param mixed $value Query variable value.
455
-	 */
456
-	public function set( $query_var, $value ) {
457
-		$this->query_vars[ $query_var ] = $value;
458
-	}
459
-
460
-	/**
461
-	 * Return the list of subscriptions.
462
-	 *
463
-	 * @since 1.0.19
464
-	 *
465
-	 * @return WPInv_Subscription[]|array Found subscriptions.
466
-	 */
467
-	public function get_results() {
468
-		return $this->results;
469
-	}
470
-
471
-	/**
472
-	 * Return the total number of subscriptions for the current query.
473
-	 *
474
-	 * @since 1.0.19
475
-	 *
476
-	 * @return int Number of total subscriptions.
477
-	 */
478
-	public function get_total() {
479
-		return $this->total_subscriptions;
480
-	}
481
-
482
-	/**
483
-	 * Parse and sanitize 'orderby' keys passed to the subscriptions query.
484
-	 *
485
-	 * @since 1.0.19
486
-	 *
487
-	 * @param string $orderby Alias for the field to order by.
488
-	 *  @param string $table The current table.
489
-	 * @return string Value to use in the ORDER clause, if `$orderby` is valid.
490
-	 */
491
-	protected function parse_orderby( $orderby, $table ) {
492
-
493
-		$_orderby = '';
494
-		if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) {
495
-			$_orderby = "$table.`$orderby`";
496
-		} elseif ( 'id' === strtolower( $orderby ) ) {
497
-			$_orderby = "$table.id";
498
-		} elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
499
-			$include     = wp_parse_id_list( $this->query_vars['include'] );
500
-			$include_sql = implode( ',', $include );
501
-			$_orderby    = "FIELD( $table.id, $include_sql )";
502
-		}
503
-
504
-		return $_orderby;
505
-	}
506
-
507
-	/**
508
-	 * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
509
-	 *
510
-	 * @since 1.0.19
511
-	 *
512
-	 * @param string $order The 'order' query variable.
513
-	 * @return string The sanitized 'order' query variable.
514
-	 */
515
-	protected function parse_order( $order ) {
516
-		if ( ! is_string( $order ) || empty( $order ) ) {
517
-			return 'DESC';
518
-		}
519
-
520
-		if ( 'ASC' === strtoupper( $order ) ) {
521
-			return 'ASC';
522
-		} else {
523
-			return 'DESC';
524
-		}
525
-	}
362
+        // If no valid clauses were found, order by id.
363
+        if ( empty( $orderby_array ) ) {
364
+            $orderby_array[] = "id $order";
365
+        }
366
+
367
+        $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
368
+
369
+    }
370
+
371
+    /**
372
+     * Execute the query, with the current variables.
373
+     *
374
+     * @since 1.0.19
375
+     *
376
+     * @global wpdb $wpdb WordPress database abstraction object.
377
+     */
378
+    public function query() {
379
+        global $wpdb;
380
+
381
+        $qv =& $this->query_vars;
382
+
383
+        // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
384
+        // total_subscriptions property.
385
+        $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
386
+
387
+        if ( null === $this->results ) {
388
+            $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
389
+
390
+            if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
391
+                $this->results = $wpdb->get_results( $this->request );
392
+            } else {
393
+                $this->results = $wpdb->get_col( $this->request );
394
+            }
395
+
396
+            if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
397
+                $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
398
+                $this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
399
+            }
400
+        }
401
+
402
+        if ( 'all' == $qv['fields'] ) {
403
+            foreach ( $this->results as $key => $subscription ) {
404
+                $this->set_cache( $subscription->id, $subscription, 'getpaid_subscriptions' );
405
+                $this->set_cache( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' );
406
+                $this->set_cache( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
407
+                $this->set_cache( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
408
+                $this->results[ $key ] = new WPInv_Subscription( $subscription );
409
+            }
410
+        }
411
+
412
+    }
413
+
414
+    /**
415
+     * Set cache
416
+     *
417
+     * @param string  $id
418
+     * @param mixed   $data
419
+     * @param string  $group
420
+     * @param integer $expire
421
+     * @return boolean
422
+     */
423
+    public function set_cache( $key, $data, $group = '', $expire = 0 ) {
424
+
425
+        if ( empty( $key ) ) {
426
+            return false;
427
+        }
428
+
429
+        wp_cache_set( $key, $data, $group, $expire );
430
+    }
431
+
432
+    /**
433
+     * Retrieve query variable.
434
+     *
435
+     * @since 1.0.19
436
+     *
437
+     * @param string $query_var Query variable key.
438
+     * @return mixed
439
+     */
440
+    public function get( $query_var ) {
441
+        if ( isset( $this->query_vars[ $query_var ] ) ) {
442
+            return $this->query_vars[ $query_var ];
443
+        }
444
+
445
+        return null;
446
+    }
447
+
448
+    /**
449
+     * Set query variable.
450
+     *
451
+     * @since 1.0.19
452
+     *
453
+     * @param string $query_var Query variable key.
454
+     * @param mixed $value Query variable value.
455
+     */
456
+    public function set( $query_var, $value ) {
457
+        $this->query_vars[ $query_var ] = $value;
458
+    }
459
+
460
+    /**
461
+     * Return the list of subscriptions.
462
+     *
463
+     * @since 1.0.19
464
+     *
465
+     * @return WPInv_Subscription[]|array Found subscriptions.
466
+     */
467
+    public function get_results() {
468
+        return $this->results;
469
+    }
470
+
471
+    /**
472
+     * Return the total number of subscriptions for the current query.
473
+     *
474
+     * @since 1.0.19
475
+     *
476
+     * @return int Number of total subscriptions.
477
+     */
478
+    public function get_total() {
479
+        return $this->total_subscriptions;
480
+    }
481
+
482
+    /**
483
+     * Parse and sanitize 'orderby' keys passed to the subscriptions query.
484
+     *
485
+     * @since 1.0.19
486
+     *
487
+     * @param string $orderby Alias for the field to order by.
488
+     *  @param string $table The current table.
489
+     * @return string Value to use in the ORDER clause, if `$orderby` is valid.
490
+     */
491
+    protected function parse_orderby( $orderby, $table ) {
492
+
493
+        $_orderby = '';
494
+        if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) {
495
+            $_orderby = "$table.`$orderby`";
496
+        } elseif ( 'id' === strtolower( $orderby ) ) {
497
+            $_orderby = "$table.id";
498
+        } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
499
+            $include     = wp_parse_id_list( $this->query_vars['include'] );
500
+            $include_sql = implode( ',', $include );
501
+            $_orderby    = "FIELD( $table.id, $include_sql )";
502
+        }
503
+
504
+        return $_orderby;
505
+    }
506
+
507
+    /**
508
+     * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
509
+     *
510
+     * @since 1.0.19
511
+     *
512
+     * @param string $order The 'order' query variable.
513
+     * @return string The sanitized 'order' query variable.
514
+     */
515
+    protected function parse_order( $order ) {
516
+        if ( ! is_string( $order ) || empty( $order ) ) {
517
+            return 'DESC';
518
+        }
519
+
520
+        if ( 'ASC' === strtoupper( $order ) ) {
521
+            return 'ASC';
522
+        } else {
523
+            return 'DESC';
524
+        }
525
+    }
526 526
 
527 527
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-bank-transfer-gateway.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'bank_transfer';
21 21
 
22
-	/**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
27
-	protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
22
+    /**
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27
+    protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 8;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 8;
35 35
 
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title                = __( 'Direct bank transfer', 'invoicing' );
@@ -44,24 +44,24 @@  discard block
 block discarded – undo
44 44
         $this->checkout_button_text = __( 'Proceed', 'invoicing' );
45 45
         $this->instructions         = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) );
46 46
 
47
-		add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
48
-		add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
49
-		add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
50
-		add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
51
-		add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
52
-		add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
47
+        add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
48
+        add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
49
+        add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
50
+        add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
51
+        add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
52
+        add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
53 53
 
54 54
     }
55 55
 
56 56
     /**
57
-	 * Process Payment.
58
-	 *
59
-	 * @param WPInv_Invoice $invoice Invoice.
60
-	 * @param array $submission_data Posted checkout fields.
61
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62
-	 * @return array
63
-	 */
64
-	public function process_payment( $invoice, $submission_data, $submission ) {
57
+     * Process Payment.
58
+     *
59
+     * @param WPInv_Invoice $invoice Invoice.
60
+     * @param array $submission_data Posted checkout fields.
61
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62
+     * @return array
63
+     */
64
+    public function process_payment( $invoice, $submission_data, $submission ) {
65 65
 
66 66
         // Add a transaction id.
67 67
         $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) );
@@ -82,66 +82,66 @@  discard block
 block discarded – undo
82 82
     }
83 83
 
84 84
     /**
85
-	 * Output for the order received page.
86
-	 *
87
-	 * @param WPInv_Invoice $invoice Invoice.
88
-	 */
89
-	public function thankyou_page( $invoice ) {
85
+     * Output for the order received page.
86
+     *
87
+     * @param WPInv_Invoice $invoice Invoice.
88
+     */
89
+    public function thankyou_page( $invoice ) {
90 90
 
91 91
         if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
92 92
 
93
-			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
93
+            echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
94 94
 
95 95
             if ( ! empty( $this->instructions ) ) {
96 96
                 echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
97
-			}
97
+            }
98 98
 
99
-			$this->bank_details( $invoice );
99
+            $this->bank_details( $invoice );
100 100
 
101
-			echo '</div>';
101
+            echo '</div>';
102 102
 
103 103
         }
104 104
 
105
-	}
105
+    }
106 106
 
107 107
     /**
108
-	 * Add content to the WPI emails.
109
-	 *
110
-	 * @param WPInv_Invoice $invoice Invoice.
111
-	 * @param string     $email_type Email format: plain text or HTML.
112
-	 * @param bool     $sent_to_admin Sent to admin.
113
-	 */
114
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
108
+     * Add content to the WPI emails.
109
+     *
110
+     * @param WPInv_Invoice $invoice Invoice.
111
+     * @param string     $email_type Email format: plain text or HTML.
112
+     * @param bool     $sent_to_admin Sent to admin.
113
+     */
114
+    public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
115 115
 
116
-		if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
116
+        if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
117 117
 
118
-			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
118
+            echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
119 119
 
120
-			if ( $this->instructions ) {
121
-				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
120
+            if ( $this->instructions ) {
121
+                echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
122 122
             }
123 123
 
124
-			$this->bank_details( $invoice );
124
+            $this->bank_details( $invoice );
125 125
 
126
-			echo '</div>';
126
+            echo '</div>';
127 127
 
128
-		}
128
+        }
129 129
 
130 130
     }
131 131
 
132 132
     /**
133
-	 * Get bank details and place into a list format.
134
-	 *
135
-	 * @param WPInv_Invoice $invoice Invoice.
136
-	 */
137
-	protected function bank_details( $invoice ) {
133
+     * Get bank details and place into a list format.
134
+     *
135
+     * @param WPInv_Invoice $invoice Invoice.
136
+     */
137
+    protected function bank_details( $invoice ) {
138 138
 
139
-		// Get the invoice country and country $locale.
140
-		$country = $invoice->get_country();
141
-		$locale  = $this->get_country_locale();
139
+        // Get the invoice country and country $locale.
140
+        $country = $invoice->get_country();
141
+        $locale  = $this->get_country_locale();
142 142
 
143
-		// Get sortcode label in the $locale array and use appropriate one.
144
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
143
+        // Get sortcode label in the $locale array and use appropriate one.
144
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
145 145
 
146 146
         $bank_fields = array(
147 147
             'ac_name'   => __( 'Account Name', 'invoicing' ),
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 
161 161
             if ( ! empty( $value ) ) {
162 162
                 $bank_info[ $field ] = array(
163
-					'label' => $label,
164
-					'value' => $value,
165
-				);
163
+                    'label' => $label,
164
+                    'value' => $value,
165
+                );
166 166
             }
167
-		}
167
+        }
168 168
 
169 169
         $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice );
170 170
 
@@ -172,139 +172,139 @@  discard block
 block discarded – undo
172 172
             return;
173 173
         }
174 174
 
175
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
175
+        echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
176
+
177
+        echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
178
+
179
+        foreach ( $bank_info as $key => $data ) {
180
+            echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
181
+        }
182
+
183
+        echo '</table>';
176 184
 
177
-		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
185
+    }
178 186
 
179
-		foreach ( $bank_info as $key => $data ) {
180
-			echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
181
-		}
187
+    /**
188
+     * Get country locale if localized.
189
+     *
190
+     * @return array
191
+     */
192
+    public function get_country_locale() {
193
+
194
+        if ( empty( $this->locale ) ) {
195
+
196
+            // Locale information to be used - only those that are not 'Sort Code'.
197
+            $this->locale = apply_filters(
198
+                'getpaid_get_bank_transfer_locale',
199
+                array(
200
+                    'AU' => array(
201
+                        'sortcode' => array(
202
+                            'label' => __( 'BSB', 'invoicing' ),
203
+                        ),
204
+                    ),
205
+                    'CA' => array(
206
+                        'sortcode' => array(
207
+                            'label' => __( 'Bank transit number', 'invoicing' ),
208
+                        ),
209
+                    ),
210
+                    'IN' => array(
211
+                        'sortcode' => array(
212
+                            'label' => __( 'IFSC', 'invoicing' ),
213
+                        ),
214
+                    ),
215
+                    'IT' => array(
216
+                        'sortcode' => array(
217
+                            'label' => __( 'Branch sort', 'invoicing' ),
218
+                        ),
219
+                    ),
220
+                    'NZ' => array(
221
+                        'sortcode' => array(
222
+                            'label' => __( 'Bank code', 'invoicing' ),
223
+                        ),
224
+                    ),
225
+                    'SE' => array(
226
+                        'sortcode' => array(
227
+                            'label' => __( 'Bank code', 'invoicing' ),
228
+                        ),
229
+                    ),
230
+                    'US' => array(
231
+                        'sortcode' => array(
232
+                            'label' => __( 'Routing number', 'invoicing' ),
233
+                        ),
234
+                    ),
235
+                    'ZA' => array(
236
+                        'sortcode' => array(
237
+                            'label' => __( 'Branch code', 'invoicing' ),
238
+                        ),
239
+                    ),
240
+                )
241
+            );
182 242
 
183
-		echo '</table>';
243
+        }
244
+
245
+        return $this->locale;
184 246
 
185 247
     }
186 248
 
187 249
     /**
188
-	 * Get country locale if localized.
189
-	 *
190
-	 * @return array
191
-	 */
192
-	public function get_country_locale() {
193
-
194
-		if ( empty( $this->locale ) ) {
195
-
196
-			// Locale information to be used - only those that are not 'Sort Code'.
197
-			$this->locale = apply_filters(
198
-				'getpaid_get_bank_transfer_locale',
199
-				array(
200
-					'AU' => array(
201
-						'sortcode' => array(
202
-							'label' => __( 'BSB', 'invoicing' ),
203
-						),
204
-					),
205
-					'CA' => array(
206
-						'sortcode' => array(
207
-							'label' => __( 'Bank transit number', 'invoicing' ),
208
-						),
209
-					),
210
-					'IN' => array(
211
-						'sortcode' => array(
212
-							'label' => __( 'IFSC', 'invoicing' ),
213
-						),
214
-					),
215
-					'IT' => array(
216
-						'sortcode' => array(
217
-							'label' => __( 'Branch sort', 'invoicing' ),
218
-						),
219
-					),
220
-					'NZ' => array(
221
-						'sortcode' => array(
222
-							'label' => __( 'Bank code', 'invoicing' ),
223
-						),
224
-					),
225
-					'SE' => array(
226
-						'sortcode' => array(
227
-							'label' => __( 'Bank code', 'invoicing' ),
228
-						),
229
-					),
230
-					'US' => array(
231
-						'sortcode' => array(
232
-							'label' => __( 'Routing number', 'invoicing' ),
233
-						),
234
-					),
235
-					'ZA' => array(
236
-						'sortcode' => array(
237
-							'label' => __( 'Branch code', 'invoicing' ),
238
-						),
239
-					),
240
-				)
241
-			);
242
-
243
-		}
244
-
245
-		return $this->locale;
246
-
247
-	}
248
-
249
-	/**
250
-	 * Filters the gateway settings.
251
-	 *
252
-	 * @param array $admin_settings
253
-	 */
254
-	public function admin_settings( $admin_settings ) {
250
+     * Filters the gateway settings.
251
+     *
252
+     * @param array $admin_settings
253
+     */
254
+    public function admin_settings( $admin_settings ) {
255 255
 
256 256
         $admin_settings['bank_transfer_desc']['std']    = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' );
257
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
257
+        $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
258 258
 
259
-		$locale  = $this->get_country_locale();
259
+        $locale  = $this->get_country_locale();
260 260
 
261
-		// Get sortcode label in the $locale array and use appropriate one.
262
-		$country  = wpinv_default_billing_country();
263
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
261
+        // Get sortcode label in the $locale array and use appropriate one.
262
+        $country  = wpinv_default_billing_country();
263
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
264 264
 
265
-		$admin_settings['bank_transfer_ac_name'] = array(
265
+        $admin_settings['bank_transfer_ac_name'] = array(
266 266
             'type' => 'text',
267 267
             'id'   => 'bank_transfer_ac_name',
268 268
             'name' => __( 'Account Name', 'invoicing' ),
269
-		);
269
+        );
270 270
 
271
-		$admin_settings['bank_transfer_ac_no'] = array(
271
+        $admin_settings['bank_transfer_ac_no'] = array(
272 272
             'type' => 'text',
273 273
             'id'   => 'bank_transfer_ac_no',
274 274
             'name' => __( 'Account Number', 'invoicing' ),
275
-		);
275
+        );
276 276
 
277
-		$admin_settings['bank_transfer_bank_name'] = array(
277
+        $admin_settings['bank_transfer_bank_name'] = array(
278 278
             'type' => 'text',
279 279
             'id'   => 'bank_transfer_bank_name',
280 280
             'name' => __( 'Bank Name', 'invoicing' ),
281
-		);
281
+        );
282 282
 
283
-		$admin_settings['bank_transfer_ifsc'] = array(
283
+        $admin_settings['bank_transfer_ifsc'] = array(
284 284
             'type' => 'text',
285 285
             'id'   => 'bank_transfer_ifsc',
286 286
             'name' => __( 'IFSC Code', 'invoicing' ),
287
-		);
287
+        );
288 288
 
289
-		$admin_settings['bank_transfer_iban'] = array(
289
+        $admin_settings['bank_transfer_iban'] = array(
290 290
             'type' => 'text',
291 291
             'id'   => 'bank_transfer_iban',
292 292
             'name' => __( 'IBAN', 'invoicing' ),
293
-		);
293
+        );
294 294
 
295
-		$admin_settings['bank_transfer_bic'] = array(
295
+        $admin_settings['bank_transfer_bic'] = array(
296 296
             'type' => 'text',
297 297
             'id'   => 'bank_transfer_bic',
298 298
             'name' => __( 'BIC/Swift Code', 'invoicing' ),
299
-		);
299
+        );
300 300
 
301
-		$admin_settings['bank_transfer_sort_code'] = array(
302
-			'type' => 'text',
303
-			'id'   => 'bank_transfer_sort_code',
304
-			'name' => $sortcode,
305
-		);
301
+        $admin_settings['bank_transfer_sort_code'] = array(
302
+            'type' => 'text',
303
+            'id'   => 'bank_transfer_sort_code',
304
+            'name' => $sortcode,
305
+        );
306 306
 
307
-		$admin_settings['bank_transfer_info'] = array(
307
+        $admin_settings['bank_transfer_info'] = array(
308 308
             'id'   => 'bank_transfer_info',
309 309
             'name' => __( 'Instructions', 'invoicing' ),
310 310
             'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
@@ -314,17 +314,17 @@  discard block
 block discarded – undo
314 314
             'rows' => 5,
315 315
         );
316 316
 
317
-		return $admin_settings;
318
-	}
317
+        return $admin_settings;
318
+    }
319 319
 
320
-	/**
321
-	 * Processes invoice addons.
322
-	 *
323
-	 * @param WPInv_Invoice $invoice
324
-	 * @param GetPaid_Form_Item[] $items
325
-	 * @return WPInv_Invoice
326
-	 */
327
-	public function process_addons( $invoice, $items ) {
320
+    /**
321
+     * Processes invoice addons.
322
+     *
323
+     * @param WPInv_Invoice $invoice
324
+     * @param GetPaid_Form_Item[] $items
325
+     * @return WPInv_Invoice
326
+     */
327
+    public function process_addons( $invoice, $items ) {
328 328
 
329 329
         foreach ( $items as $item ) {
330 330
             $invoice->add_item( $item );
@@ -332,66 +332,66 @@  discard block
 block discarded – undo
332 332
 
333 333
         $invoice->recalculate_total();
334 334
         $invoice->save();
335
-	}
335
+    }
336 336
 
337
-	/**
338
-	 * (Maybe) renews a bank transfer subscription profile.
339
-	 *
340
-	 *
337
+    /**
338
+     * (Maybe) renews a bank transfer subscription profile.
339
+     *
340
+     *
341 341
      * @param WPInv_Subscription $subscription
342
-	 */
343
-	public function maybe_renew_subscription( $subscription ) {
342
+     */
343
+    public function maybe_renew_subscription( $subscription ) {
344 344
 
345 345
         // Ensure its our subscription && it's active.
346 346
         if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
347
-			$subscription->create_payment();
347
+            $subscription->create_payment();
348 348
         }
349 349
 
350 350
     }
351 351
 
352
-	/**
353
-	 * Process a bank transfer payment.
354
-	 *
355
-	 *
352
+    /**
353
+     * Process a bank transfer payment.
354
+     *
355
+     *
356 356
      * @param WPInv_Invoice $invoice
357
-	 */
358
-	public function invoice_paid( $invoice ) {
359
-
360
-		// Abort if not paid by bank transfer.
361
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
362
-			return;
363
-		}
364
-
365
-		// Is it a parent payment?
366
-		if ( 0 == $invoice->get_parent_id() ) {
367
-
368
-			// (Maybe) activate subscriptions.
369
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
370
-
371
-			if ( ! empty( $subscriptions ) ) {
372
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
373
-
374
-				foreach ( $subscriptions as $subscription ) {
375
-					if ( $subscription->exists() ) {
376
-						$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
377
-						$expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
378
-
379
-						$subscription->set_next_renewal_date( $expiry );
380
-						$subscription->set_date_created( current_time( 'mysql' ) );
381
-						$subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
382
-						$subscription->activate();
383
-					}
384
-				}
357
+     */
358
+    public function invoice_paid( $invoice ) {
359
+
360
+        // Abort if not paid by bank transfer.
361
+        if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
362
+            return;
363
+        }
364
+
365
+        // Is it a parent payment?
366
+        if ( 0 == $invoice->get_parent_id() ) {
367
+
368
+            // (Maybe) activate subscriptions.
369
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
370
+
371
+            if ( ! empty( $subscriptions ) ) {
372
+                $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
373
+
374
+                foreach ( $subscriptions as $subscription ) {
375
+                    if ( $subscription->exists() ) {
376
+                        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
377
+                        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
378
+
379
+                        $subscription->set_next_renewal_date( $expiry );
380
+                        $subscription->set_date_created( current_time( 'mysql' ) );
381
+                        $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
382
+                        $subscription->activate();
383
+                    }
384
+                }
385 385
 }
386 386
 } else {
387 387
 
388
-			$subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
388
+            $subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
389 389
 
390
-			// Renew the subscription.
391
-			if ( $subscription && $subscription->exists() ) {
392
-				$subscription->add_payment( array(), $invoice );
393
-				$subscription->renew( strtotime( $invoice->get_date_created() ) );
394
-					}
390
+            // Renew the subscription.
391
+            if ( $subscription && $subscription->exists() ) {
392
+                $subscription->add_payment( array(), $invoice );
393
+                $subscription->renew( strtotime( $invoice->get_date_created() ) );
394
+                    }
395 395
 }
396 396
 
397 397
     }
Please login to merge, or discard this patch.