Completed
Push — master ( 9b8253...a465f2 )
by Brian
29s queued 14s
created
includes/class-getpaid-subscription-notification-emails.php 2 patches
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -13,282 +13,282 @@
 block discarded – undo
13 13
 class GetPaid_Subscription_Notification_Emails {
14 14
 
15 15
     /**
16
-	 * The array of subscription email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $subscription_actions;
16
+     * The array of subscription email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $subscription_actions;
21 21
 
22 22
     /**
23
-	 * Class constructor
23
+     * Class constructor
24 24
      *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->subscription_actions = apply_filters(
29
-			'getpaid_notification_email_subscription_triggers',
30
-			array(
31
-				'getpaid_subscription_trialling' => 'subscription_trial',
32
-				'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
-				'getpaid_subscription_expired'   => 'subscription_expired',
34
-				'getpaid_subscription_completed' => 'subscription_complete',
35
-				'getpaid_daily_maintenance'      => 'renewal_reminder',
36
-			)
37
-		);
38
-
39
-		$this->init_hooks();
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->subscription_actions = apply_filters(
29
+            'getpaid_notification_email_subscription_triggers',
30
+            array(
31
+                'getpaid_subscription_trialling' => 'subscription_trial',
32
+                'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
+                'getpaid_subscription_expired'   => 'subscription_expired',
34
+                'getpaid_subscription_completed' => 'subscription_complete',
35
+                'getpaid_daily_maintenance'      => 'renewal_reminder',
36
+            )
37
+        );
38
+
39
+        $this->init_hooks();
40 40
 
41 41
     }
42 42
 
43 43
     /**
44
-	 * Registers email hooks.
45
-	 */
46
-	public function init_hooks() {
47
-
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
50
-
51
-			$email = new GetPaid_Notification_Email( $email_type );
52
-
53
-			if ( ! $email->is_active() ) {
54
-				continue;
55
-			}
56
-
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
59
-				continue;
60
-			}
61
-
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
-
64
-		}
65
-
66
-	}
67
-
68
-	/**
69
-	 * Filters subscription merge tags.
70
-	 *
71
-	 * @param array $merge_tags
72
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
-	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
75
-
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
-			$merge_tags = array_merge(
78
-				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
80
-			);
81
-		}
82
-
83
-		return $merge_tags;
84
-
85
-	}
86
-
87
-	/**
88
-	 * Generates subscription merge tags.
89
-	 *
90
-	 * @param WPInv_Subscription $subscription
91
-	 * @return array
92
-	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
94
-
95
-		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
97
-			return array();
98
-		}
99
-
100
-		$invoice    = $subscription->get_parent_invoice();
101
-		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
108
-			'{subscription_initial_amount}'   => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
-			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
-		);
113
-
114
-	}
115
-
116
-	/**
117
-	 * Checks if we should send a notification for a subscription.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return bool
121
-	 */
122
-	public function should_send_notification( $invoice ) {
123
-		return 0 != $invoice->get_id();
124
-	}
125
-
126
-	/**
127
-	 * Returns notification recipients.
128
-	 *
129
-	 * @param WPInv_Invoice $invoice
130
-	 * @return array
131
-	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
134
-
135
-		$cc = $invoice->get_email_cc();
136
-
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
-		}
141
-
142
-		return $recipients;
143
-	}
144
-
145
-	/**
146
-	 * Helper function to send an email.
147
-	 *
148
-	 * @param WPInv_Subscription $subscription
149
-	 * @param GetPaid_Notification_Email $email
150
-	 * @param string $type
151
-	 * @param array $extra_args Extra template args.
152
-	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
-
155
-		// Abort in case the parent invoice does not exist.
156
-		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
158
-			return;
159
-		}
160
-
161
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
162
-
163
-		$recipients  = $this->get_recipients( $invoice );
164
-		$mailer      = new GetPaid_Notification_Email_Sender();
165
-		$merge_tags  = $email->get_merge_tags();
166
-		$content     = $email->get_content( $merge_tags, $extra_args );
167
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
168
-		$attachments = $email->get_attachments();
169
-
170
-		$result = $mailer->send(
171
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
172
-			$subject,
173
-			$content,
174
-			$attachments
175
-		);
176
-
177
-		// Maybe send a copy to the admin.
178
-		if ( $email->include_admin_bcc() ) {
179
-			$mailer->send(
180
-				wpinv_get_admin_email(),
181
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
182
-				$content,
183
-				$attachments
184
-			);
185
-		}
186
-
187
-		if ( ! $result ) {
188
-			$subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
189
-		}
190
-
191
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
192
-
193
-	}
44
+     * Registers email hooks.
45
+     */
46
+    public function init_hooks() {
47
+
48
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
+        foreach ( $this->subscription_actions as $hook => $email_type ) {
50
+
51
+            $email = new GetPaid_Notification_Email( $email_type );
52
+
53
+            if ( ! $email->is_active() ) {
54
+                continue;
55
+            }
56
+
57
+            if ( method_exists( $this, $email_type ) ) {
58
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
59
+                continue;
60
+            }
61
+
62
+            do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
+
64
+        }
65
+
66
+    }
194 67
 
195 68
     /**
196
-	 * Sends a new trial notification.
197
-	 *
198
-	 * @param WPInv_Subscription $subscription
199
-	 */
200
-	public function subscription_trial( $subscription ) {
69
+     * Filters subscription merge tags.
70
+     *
71
+     * @param array $merge_tags
72
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
+     */
74
+    public function subscription_merge_tags( $merge_tags, $object ) {
201 75
 
202
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
-		$this->send_email( $subscription, $email, __FUNCTION__ );
76
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
+            $merge_tags = array_merge(
78
+                $merge_tags,
79
+                $this->get_subscription_merge_tags( $object )
80
+            );
81
+        }
204 82
 
205
-	}
83
+        return $merge_tags;
206 84
 
207
-	/**
208
-	 * Sends a cancelled subscription notification.
209
-	 *
210
-	 * @param WPInv_Subscription $subscription
211
-	 */
212
-	public function subscription_cancelled( $subscription ) {
85
+    }
213 86
 
214
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
-		$this->send_email( $subscription, $email, __FUNCTION__ );
87
+    /**
88
+     * Generates subscription merge tags.
89
+     *
90
+     * @param WPInv_Subscription $subscription
91
+     * @return array
92
+     */
93
+    public function get_subscription_merge_tags( $subscription ) {
94
+
95
+        // Abort if it does not exist.
96
+        if ( ! $subscription->get_id() ) {
97
+            return array();
98
+        }
99
+
100
+        $invoice    = $subscription->get_parent_invoice();
101
+        return array(
102
+            '{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
+            '{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
+            '{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
+            '{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
+            '{subscription_id}'               => absint( $subscription->get_id() ),
107
+            '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
108
+            '{subscription_initial_amount}'   => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ),
109
+            '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
+            '{subscription_bill_times}'       => $subscription->get_bill_times(),
111
+            '{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
+        );
216 113
 
217
-	}
114
+    }
218 115
 
219
-	/**
220
-	 * Sends a subscription expired notification.
221
-	 *
222
-	 * @param WPInv_Subscription $subscription
223
-	 */
224
-	public function subscription_expired( $subscription ) {
116
+    /**
117
+     * Checks if we should send a notification for a subscription.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return bool
121
+     */
122
+    public function should_send_notification( $invoice ) {
123
+        return 0 != $invoice->get_id();
124
+    }
225 125
 
226
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
-		$this->send_email( $subscription, $email, __FUNCTION__ );
126
+    /**
127
+     * Returns notification recipients.
128
+     *
129
+     * @param WPInv_Invoice $invoice
130
+     * @return array
131
+     */
132
+    public function get_recipients( $invoice ) {
133
+        $recipients = array( $invoice->get_email() );
228 134
 
229
-	}
135
+        $cc = $invoice->get_email_cc();
230 136
 
231
-	/**
232
-	 * Sends a completed subscription notification.
233
-	 *
234
-	 * @param WPInv_Subscription $subscription
235
-	 */
236
-	public function subscription_complete( $subscription ) {
137
+        if ( ! empty( $cc ) ) {
138
+            $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
+            $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
+        }
237 141
 
238
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
-		$this->send_email( $subscription, $email, __FUNCTION__ );
142
+        return $recipients;
143
+    }
240 144
 
241
-	}
145
+    /**
146
+     * Helper function to send an email.
147
+     *
148
+     * @param WPInv_Subscription $subscription
149
+     * @param GetPaid_Notification_Email $email
150
+     * @param string $type
151
+     * @param array $extra_args Extra template args.
152
+     */
153
+    public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
+
155
+        // Abort in case the parent invoice does not exist.
156
+        $invoice = $subscription->get_parent_invoice();
157
+        if ( ! $this->should_send_notification( $invoice ) ) {
158
+            return;
159
+        }
160
+
161
+        do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
162
+
163
+        $recipients  = $this->get_recipients( $invoice );
164
+        $mailer      = new GetPaid_Notification_Email_Sender();
165
+        $merge_tags  = $email->get_merge_tags();
166
+        $content     = $email->get_content( $merge_tags, $extra_args );
167
+        $subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
168
+        $attachments = $email->get_attachments();
169
+
170
+        $result = $mailer->send(
171
+            apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
172
+            $subject,
173
+            $content,
174
+            $attachments
175
+        );
176
+
177
+        // Maybe send a copy to the admin.
178
+        if ( $email->include_admin_bcc() ) {
179
+            $mailer->send(
180
+                wpinv_get_admin_email(),
181
+                $subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
182
+                $content,
183
+                $attachments
184
+            );
185
+        }
186
+
187
+        if ( ! $result ) {
188
+            $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
189
+        }
190
+
191
+        do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
242 192
 
243
-	/**
244
-	 * Sends a subscription renewal reminder notification.
245
-	 *
246
-	 */
247
-	public function renewal_reminder() {
193
+    }
248 194
 
249
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
195
+    /**
196
+     * Sends a new trial notification.
197
+     *
198
+     * @param WPInv_Subscription $subscription
199
+     */
200
+    public function subscription_trial( $subscription ) {
250 201
 
251
-		// Fetch reminder days.
252
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
202
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
+        $this->send_email( $subscription, $email, __FUNCTION__ );
253 204
 
254
-		// Abort if non is set.
255
-		if ( empty( $reminder_days ) ) {
256
-			return;
257
-		}
205
+    }
258 206
 
259
-		// Fetch matching subscriptions.
207
+    /**
208
+     * Sends a cancelled subscription notification.
209
+     *
210
+     * @param WPInv_Subscription $subscription
211
+     */
212
+    public function subscription_cancelled( $subscription ) {
213
+
214
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
+        $this->send_email( $subscription, $email, __FUNCTION__ );
216
+
217
+    }
218
+
219
+    /**
220
+     * Sends a subscription expired notification.
221
+     *
222
+     * @param WPInv_Subscription $subscription
223
+     */
224
+    public function subscription_expired( $subscription ) {
225
+
226
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
+        $this->send_email( $subscription, $email, __FUNCTION__ );
228
+
229
+    }
230
+
231
+    /**
232
+     * Sends a completed subscription notification.
233
+     *
234
+     * @param WPInv_Subscription $subscription
235
+     */
236
+    public function subscription_complete( $subscription ) {
237
+
238
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
+        $this->send_email( $subscription, $email, __FUNCTION__ );
240
+
241
+    }
242
+
243
+    /**
244
+     * Sends a subscription renewal reminder notification.
245
+     *
246
+     */
247
+    public function renewal_reminder() {
248
+
249
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
250
+
251
+        // Fetch reminder days.
252
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
253
+
254
+        // Abort if non is set.
255
+        if ( empty( $reminder_days ) ) {
256
+            return;
257
+        }
258
+
259
+        // Fetch matching subscriptions.
260 260
         $args  = array(
261 261
             'number'             => -1,
262
-			'count_total'        => false,
263
-			'status'             => 'trialling active',
262
+            'count_total'        => false,
263
+            'status'             => 'trialling active',
264 264
             'date_expires_query' => array(
265
-				'relation'  => 'OR'
265
+                'relation'  => 'OR'
266 266
             ),
267
-		);
267
+        );
268 268
 
269
-		foreach ( $reminder_days as $days ) {
270
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
269
+        foreach ( $reminder_days as $days ) {
270
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
271 271
 
272
-			$args['date_expires_query'][] = array(
273
-				'year'  => $date['year'],
274
-				'month' => $date['month'],
275
-				'day'   => $date['day'],
276
-			);
272
+            $args['date_expires_query'][] = array(
273
+                'year'  => $date['year'],
274
+                'month' => $date['month'],
275
+                'day'   => $date['day'],
276
+            );
277 277
 
278
-		}
278
+        }
279 279
 
280
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
280
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
281 281
 
282 282
         foreach ( $subscriptions as $subscription ) {
283 283
 
284
-			// Skip packages.
285
-			if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
286
-				$email->object = $subscription;
287
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
288
-			}
284
+            // Skip packages.
285
+            if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
286
+                $email->object = $subscription;
287
+                $this->send_email( $subscription, $email, __FUNCTION__ );
288
+            }
289 289
 
290
-		}
290
+        }
291 291
 
292
-	}
292
+    }
293 293
 
294 294
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles subscription notificaiton emails.
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	public function init_hooks() {
47 47
 
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
48
+		add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2);
49
+		foreach ($this->subscription_actions as $hook => $email_type) {
50 50
 
51
-			$email = new GetPaid_Notification_Email( $email_type );
51
+			$email = new GetPaid_Notification_Email($email_type);
52 52
 
53
-			if ( ! $email->is_active() ) {
53
+			if (!$email->is_active()) {
54 54
 				continue;
55 55
 			}
56 56
 
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
57
+			if (method_exists($this, $email_type)) {
58
+				add_action($hook, array($this, $email_type), 100, 2);
59 59
 				continue;
60 60
 			}
61 61
 
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
62
+			do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook);
63 63
 
64 64
 		}
65 65
 
@@ -71,12 +71,12 @@  discard block
 block discarded – undo
71 71
 	 * @param array $merge_tags
72 72
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73 73
 	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
74
+	public function subscription_merge_tags($merge_tags, $object) {
75 75
 
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
76
+		if (is_a($object, 'WPInv_Subscription')) {
77 77
 			$merge_tags = array_merge(
78 78
 				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
79
+				$this->get_subscription_merge_tags($object)
80 80
 			);
81 81
 		}
82 82
 
@@ -90,25 +90,25 @@  discard block
 block discarded – undo
90 90
 	 * @param WPInv_Subscription $subscription
91 91
 	 * @return array
92 92
 	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
93
+	public function get_subscription_merge_tags($subscription) {
94 94
 
95 95
 		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
96
+		if (!$subscription->get_id()) {
97 97
 			return array();
98 98
 		}
99 99
 
100
-		$invoice    = $subscription->get_parent_invoice();
100
+		$invoice = $subscription->get_parent_invoice();
101 101
 		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
108
-			'{subscription_initial_amount}'   => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
102
+			'{subscription_renewal_date}'     => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')),
103
+			'{subscription_created}'          => getpaid_format_date_value($subscription->get_date_created()),
104
+			'{subscription_status}'           => sanitize_text_field($subscription->get_status_label()),
105
+			'{subscription_profile_id}'       => sanitize_text_field($subscription->get_profile_id()),
106
+			'{subscription_id}'               => absint($subscription->get_id()),
107
+			'{subscription_recurring_amount}' => wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $invoice->get_currency()),
108
+			'{subscription_initial_amount}'   => wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $invoice->get_currency()),
109
+			'{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''),
110 110
 			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
111
+			'{subscription_url}'              => esc_url($subscription->get_view_url()),
112 112
 		);
113 113
 
114 114
 	}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return bool
121 121
 	 */
122
-	public function should_send_notification( $invoice ) {
122
+	public function should_send_notification($invoice) {
123 123
 		return 0 != $invoice->get_id();
124 124
 	}
125 125
 
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 	 * @param WPInv_Invoice $invoice
130 130
 	 * @return array
131 131
 	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
132
+	public function get_recipients($invoice) {
133
+		$recipients = array($invoice->get_email());
134 134
 
135 135
 		$cc = $invoice->get_email_cc();
136 136
 
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
137
+		if (!empty($cc)) {
138
+			$cc = array_map('sanitize_email', wpinv_parse_list($cc));
139
+			$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
140 140
 		}
141 141
 
142 142
 		return $recipients;
@@ -150,45 +150,45 @@  discard block
 block discarded – undo
150 150
 	 * @param string $type
151 151
 	 * @param array $extra_args Extra template args.
152 152
 	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
153
+	public function send_email($subscription, $email, $type, $extra_args = array()) {
154 154
 
155 155
 		// Abort in case the parent invoice does not exist.
156 156
 		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
157
+		if (!$this->should_send_notification($invoice)) {
158 158
 			return;
159 159
 		}
160 160
 
161
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
161
+		do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email);
162 162
 
163
-		$recipients  = $this->get_recipients( $invoice );
163
+		$recipients  = $this->get_recipients($invoice);
164 164
 		$mailer      = new GetPaid_Notification_Email_Sender();
165 165
 		$merge_tags  = $email->get_merge_tags();
166
-		$content     = $email->get_content( $merge_tags, $extra_args );
167
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
166
+		$content     = $email->get_content($merge_tags, $extra_args);
167
+		$subject     = $email->add_merge_tags($email->get_subject(), $merge_tags);
168 168
 		$attachments = $email->get_attachments();
169 169
 
170 170
 		$result = $mailer->send(
171
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
+			apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email),
172 172
 			$subject,
173 173
 			$content,
174 174
 			$attachments
175 175
 		);
176 176
 
177 177
 		// Maybe send a copy to the admin.
178
-		if ( $email->include_admin_bcc() ) {
178
+		if ($email->include_admin_bcc()) {
179 179
 			$mailer->send(
180 180
 				wpinv_get_admin_email(),
181
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
181
+				$subject . __(' - ADMIN BCC COPY', 'invoicing'),
182 182
 				$content,
183 183
 				$attachments
184 184
 			);
185 185
 		}
186 186
 
187
-		if ( ! $result ) {
188
-			$subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
187
+		if (!$result) {
188
+			$subscription->get_parent_invoice()->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
189 189
 		}
190 190
 
191
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
191
+		do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email);
192 192
 
193 193
 	}
194 194
 
@@ -197,10 +197,10 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @param WPInv_Subscription $subscription
199 199
 	 */
200
-	public function subscription_trial( $subscription ) {
200
+	public function subscription_trial($subscription) {
201 201
 
202
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
-		$this->send_email( $subscription, $email, __FUNCTION__ );
202
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
203
+		$this->send_email($subscription, $email, __FUNCTION__);
204 204
 
205 205
 	}
206 206
 
@@ -209,10 +209,10 @@  discard block
 block discarded – undo
209 209
 	 *
210 210
 	 * @param WPInv_Subscription $subscription
211 211
 	 */
212
-	public function subscription_cancelled( $subscription ) {
212
+	public function subscription_cancelled($subscription) {
213 213
 
214
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
-		$this->send_email( $subscription, $email, __FUNCTION__ );
214
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
215
+		$this->send_email($subscription, $email, __FUNCTION__);
216 216
 
217 217
 	}
218 218
 
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 	 *
222 222
 	 * @param WPInv_Subscription $subscription
223 223
 	 */
224
-	public function subscription_expired( $subscription ) {
224
+	public function subscription_expired($subscription) {
225 225
 
226
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
-		$this->send_email( $subscription, $email, __FUNCTION__ );
226
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
227
+		$this->send_email($subscription, $email, __FUNCTION__);
228 228
 
229 229
 	}
230 230
 
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
 	 *
234 234
 	 * @param WPInv_Subscription $subscription
235 235
 	 */
236
-	public function subscription_complete( $subscription ) {
236
+	public function subscription_complete($subscription) {
237 237
 
238
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
-		$this->send_email( $subscription, $email, __FUNCTION__ );
238
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
239
+		$this->send_email($subscription, $email, __FUNCTION__);
240 240
 
241 241
 	}
242 242
 
@@ -246,18 +246,18 @@  discard block
 block discarded – undo
246 246
 	 */
247 247
 	public function renewal_reminder() {
248 248
 
249
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
249
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
250 250
 
251 251
 		// Fetch reminder days.
252
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
252
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
253 253
 
254 254
 		// Abort if non is set.
255
-		if ( empty( $reminder_days ) ) {
255
+		if (empty($reminder_days)) {
256 256
 			return;
257 257
 		}
258 258
 
259 259
 		// Fetch matching subscriptions.
260
-        $args  = array(
260
+        $args = array(
261 261
             'number'             => -1,
262 262
 			'count_total'        => false,
263 263
 			'status'             => 'trialling active',
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
             ),
267 267
 		);
268 268
 
269
-		foreach ( $reminder_days as $days ) {
270
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
269
+		foreach ($reminder_days as $days) {
270
+			$date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp'))));
271 271
 
272 272
 			$args['date_expires_query'][] = array(
273 273
 				'year'  => $date['year'],
@@ -277,14 +277,14 @@  discard block
 block discarded – undo
277 277
 
278 278
 		}
279 279
 
280
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
280
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
281 281
 
282
-        foreach ( $subscriptions as $subscription ) {
282
+        foreach ($subscriptions as $subscription) {
283 283
 
284 284
 			// Skip packages.
285
-			if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
285
+			if (get_post_meta($subscription->get_product_id(), '_wpinv_type', true) != 'package') {
286 286
 				$email->object = $subscription;
287
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
287
+            	$this->send_email($subscription, $email, __FUNCTION__);
288 288
 			}
289 289
 
290 290
 		}
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
83 83
 
84
-	$invoice_statuses = array(
85
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
84
+    $invoice_statuses = array(
85
+        'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
86 86
         'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
87 87
         'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
88
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
89
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
90
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
88
+        'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
89
+        'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
90
+        'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
91 91
         'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
92 92
         'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
93 93
     );
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
         $invoice = $invoice->get_post_type();
105 105
     }
106 106
 
107
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
107
+    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
108 108
 }
109 109
 
110 110
 /**
@@ -222,25 +222,25 @@  discard block
 block discarded – undo
222 222
  * @return string
223 223
  */
224 224
 function getpaid_get_price_format() {
225
-	$currency_pos = wpinv_currency_position();
226
-	$format       = '%1$s%2$s';
225
+    $currency_pos = wpinv_currency_position();
226
+    $format       = '%1$s%2$s';
227 227
 
228
-	switch ( $currency_pos ) {
229
-		case 'left':
230
-			$format = '%1$s%2$s';
231
-			break;
232
-		case 'right':
233
-			$format = '%2$s%1$s';
234
-			break;
235
-		case 'left_space':
236
-			$format = '%1$s %2$s';
237
-			break;
238
-		case 'right_space':
239
-			$format = '%2$s %1$s';
240
-			break;
241
-	}
228
+    switch ( $currency_pos ) {
229
+        case 'left':
230
+            $format = '%1$s%2$s';
231
+            break;
232
+        case 'right':
233
+            $format = '%2$s%1$s';
234
+            break;
235
+        case 'left_space':
236
+            $format = '%1$s %2$s';
237
+            break;
238
+        case 'right_space':
239
+            $format = '%2$s %1$s';
240
+            break;
241
+    }
242 242
 
243
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
243
+    return apply_filters( 'getpaid_price_format', $format, $currency_pos );
244 244
 }
245 245
 
246 246
 /**
@@ -343,13 +343,13 @@  discard block
 block discarded – undo
343 343
  * @param mixed  $value Value.
344 344
  */
345 345
 function getpaid_maybe_define_constant( $name, $value ) {
346
-	if ( ! defined( $name ) ) {
347
-		define( $name, $value );
348
-	}
346
+    if ( ! defined( $name ) ) {
347
+        define( $name, $value );
348
+    }
349 349
 }
350 350
 
351 351
 function wpinv_get_php_arg_separator_output() {
352
-	return ini_get( 'arg_separator.output' );
352
+    return ini_get( 'arg_separator.output' );
353 353
 }
354 354
 
355 355
 function wpinv_rgb_from_hex( $color ) {
@@ -700,11 +700,11 @@  discard block
 block discarded – undo
700 700
         $list = array();
701 701
     }
702 702
 
703
-	if ( ! is_array( $list ) ) {
704
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
705
-	}
703
+    if ( ! is_array( $list ) ) {
704
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
705
+    }
706 706
 
707
-	return $list;
707
+    return $list;
708 708
 }
709 709
 
710 710
 /**
@@ -724,9 +724,9 @@  discard block
 block discarded – undo
724 724
     }
725 725
 
726 726
     $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
727
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
727
+    wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
728 728
 
729
-	return $data;
729
+    return $data;
730 730
 }
731 731
 
732 732
 /**
@@ -755,17 +755,17 @@  discard block
 block discarded – undo
755 755
  */
756 756
 function wpinv_clean( $var ) {
757 757
 
758
-	if ( is_array( $var ) ) {
759
-		return array_map( 'wpinv_clean', $var );
758
+    if ( is_array( $var ) ) {
759
+        return array_map( 'wpinv_clean', $var );
760 760
     }
761 761
 
762 762
     if ( is_object( $var ) ) {
763
-		$object_vars = get_object_vars( $var );
764
-		foreach ( $object_vars as $property_name => $property_value ) {
765
-			$var->$property_name = wpinv_clean( $property_value );
763
+        $object_vars = get_object_vars( $var );
764
+        foreach ( $object_vars as $property_name => $property_value ) {
765
+            $var->$property_name = wpinv_clean( $property_value );
766 766
         }
767 767
         return $var;
768
-	}
768
+    }
769 769
     
770 770
     return is_string( $var ) ? sanitize_text_field( $var ) : $var;
771 771
 }
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
  */
779 779
 function getpaid_convert_price_string_to_options( $str ) {
780 780
 
781
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
781
+    $raw_options = array_map( 'trim', explode( ',', $str ) );
782 782
     $options     = array();
783 783
 
784 784
     foreach ( $raw_options as $option ) {
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
  * @return string
857 857
  */
858 858
 function getpaid_date_format() {
859
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
859
+    return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
860 860
 }
861 861
 
862 862
 /**
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
  * @return string
866 866
  */
867 867
 function getpaid_time_format() {
868
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
868
+    return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
869 869
 }
870 870
 
871 871
 /**
@@ -878,15 +878,15 @@  discard block
 block discarded – undo
878 878
 function getpaid_limit_length( $string, $limit ) {
879 879
     $str_limit = $limit - 3;
880 880
 
881
-	if ( function_exists( 'mb_strimwidth' ) ) {
882
-		if ( mb_strlen( $string ) > $limit ) {
883
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
884
-		}
885
-	} else {
886
-		if ( strlen( $string ) > $limit ) {
887
-			$string = substr( $string, 0, $str_limit ) . '...';
888
-		}
889
-	}
881
+    if ( function_exists( 'mb_strimwidth' ) ) {
882
+        if ( mb_strlen( $string ) > $limit ) {
883
+            $string = mb_strimwidth( $string, 0, $str_limit ) . '...';
884
+        }
885
+    } else {
886
+        if ( strlen( $string ) > $limit ) {
887
+            $string = substr( $string, 0, $str_limit ) . '...';
888
+        }
889
+    }
890 890
     return $string;
891 891
 
892 892
 }
Please login to merge, or discard this patch.
Spacing   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Are we supporting item quantities?
@@ -21,25 +21,25 @@  discard block
 block discarded – undo
21 21
 function wpinv_get_ip() {
22 22
     $ip = $_SERVER['REMOTE_ADDR'];
23 23
 
24
-    if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
25 25
         //Check ip from share internet.
26 26
         $ip = $_SERVER['HTTP_CLIENT_IP'];
27
-    } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
27
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
28 28
         //Check ip is pass from proxy.
29 29
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
30 30
     }
31 31
 
32
-    return apply_filters( 'wpinv_get_ip', $ip );
32
+    return apply_filters('wpinv_get_ip', $ip);
33 33
 }
34 34
 
35 35
 function wpinv_get_user_agent() {
36
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
37
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
36
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
37
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
38 38
     } else {
39 39
         $user_agent = '';
40 40
     }
41 41
 
42
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
42
+    return apply_filters('wpinv_get_user_agent', $user_agent);
43 43
 }
44 44
 
45 45
 /**
@@ -47,27 +47,27 @@  discard block
 block discarded – undo
47 47
  * 
48 48
  * @param string $amount The amount to sanitize.
49 49
  */
50
-function wpinv_sanitize_amount( $amount ) {
50
+function wpinv_sanitize_amount($amount) {
51 51
 
52 52
     // Format decimals.
53
-    $amount = str_replace( wpinv_decimal_separator(), '.', $amount );
53
+    $amount = str_replace(wpinv_decimal_separator(), '.', $amount);
54 54
 
55 55
     // Remove thousands.
56
-    $amount = str_replace( wpinv_thousands_separator(), '', $amount );
56
+    $amount = str_replace(wpinv_thousands_separator(), '', $amount);
57 57
 
58 58
     // Cast the remaining to a float.
59
-    return (float) preg_replace( '/[^0-9\.\-]/', '', $amount );
59
+    return (float) preg_replace('/[^0-9\.\-]/', '', $amount);
60 60
 
61 61
 }
62 62
 
63
-function wpinv_round_amount( $amount, $decimals = NULL ) {
64
-    if ( $decimals === NULL ) {
63
+function wpinv_round_amount($amount, $decimals = NULL) {
64
+    if ($decimals === NULL) {
65 65
         $decimals = wpinv_decimals();
66 66
     }
67 67
     
68
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
68
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
69 69
 
70
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
70
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
71 71
 }
72 72
 
73 73
 /**
@@ -79,32 +79,32 @@  discard block
 block discarded – undo
79 79
  * @param string|WPInv_Invoice $invoice The invoice object|post type|type
80 80
  * @return array
81 81
  */
82
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
82
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
83 83
 
84 84
 	$invoice_statuses = array(
85
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
86
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
87
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
88
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
89
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
90
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
91
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
92
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
85
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
86
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
87
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
88
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
89
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
90
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
91
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
92
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
93 93
     );
94 94
 
95
-    if ( $draft ) {
96
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
95
+    if ($draft) {
96
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
97 97
     }
98 98
 
99
-    if ( $trashed ) {
100
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
99
+    if ($trashed) {
100
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
101 101
     }
102 102
 
103
-    if ( $invoice instanceof WPInv_Invoice ) {
103
+    if ($invoice instanceof WPInv_Invoice) {
104 104
         $invoice = $invoice->get_post_type();
105 105
     }
106 106
 
107
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
107
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
108 108
 }
109 109
 
110 110
 /**
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
  * @param string $status The raw status
114 114
  * @param string|WPInv_Invoice $invoice The invoice object|post type|type
115 115
  */
116
-function wpinv_status_nicename( $status, $invoice = false ) {
117
-    $statuses = wpinv_get_invoice_statuses( true, true, $invoice );
118
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : $status;
116
+function wpinv_status_nicename($status, $invoice = false) {
117
+    $statuses = wpinv_get_invoice_statuses(true, true, $invoice);
118
+    $status   = isset($statuses[$status]) ? $statuses[$status] : $status;
119 119
 
120
-    return sanitize_text_field( $status );
120
+    return sanitize_text_field($status);
121 121
 }
122 122
 
123 123
 /**
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
  * 
126 126
  * @param string $current
127 127
  */
128
-function wpinv_get_currency( $current = '' ) {
128
+function wpinv_get_currency($current = '') {
129 129
 
130
-    if ( empty( $current ) ) {
131
-        $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
130
+    if (empty($current)) {
131
+        $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
132 132
     }
133 133
 
134
-    return trim( strtoupper( $current ) );
134
+    return trim(strtoupper($current));
135 135
 }
136 136
 
137 137
 /**
@@ -139,25 +139,25 @@  discard block
 block discarded – undo
139 139
  * 
140 140
  * @param string|null $currency The currency code. Defaults to the default currency.
141 141
  */
142
-function wpinv_currency_symbol( $currency = null ) {
142
+function wpinv_currency_symbol($currency = null) {
143 143
 
144 144
     // Prepare the currency.
145
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
145
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
146 146
 
147 147
     // Fetch all symbols.
148 148
     $symbols = wpinv_get_currency_symbols();
149 149
 
150 150
     // Fetch this currencies symbol.
151
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
151
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
152 152
 
153 153
     // Filter the symbol.
154
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
154
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
155 155
 }
156 156
 
157 157
 function wpinv_currency_position() {
158
-    $position = wpinv_get_option( 'currency_position', 'left' );
158
+    $position = wpinv_get_option('currency_position', 'left');
159 159
     
160
-    return apply_filters( 'wpinv_currency_position', $position );
160
+    return apply_filters('wpinv_currency_position', $position);
161 161
 }
162 162
 
163 163
 /**
@@ -165,13 +165,13 @@  discard block
 block discarded – undo
165 165
  * 
166 166
  * @param $string|null $current
167 167
  */
168
-function wpinv_thousands_separator( $current = null ) {
168
+function wpinv_thousands_separator($current = null) {
169 169
 
170
-    if ( null == $current ) {
171
-        $current = wpinv_get_option( 'thousands_separator', '.' );
170
+    if (null == $current) {
171
+        $current = wpinv_get_option('thousands_separator', '.');
172 172
     }
173 173
 
174
-    return trim( $current );
174
+    return trim($current);
175 175
 }
176 176
 
177 177
 /**
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
  * 
180 180
  * @param $string|null $current
181 181
  */
182
-function wpinv_decimal_separator( $current = null ) {
182
+function wpinv_decimal_separator($current = null) {
183 183
 
184
-    if ( null == $current ) {
185
-        $current = wpinv_get_option( 'decimal_separator', '.' );
184
+    if (null == $current) {
185
+        $current = wpinv_get_option('decimal_separator', '.');
186 186
     }
187 187
     
188
-    return trim( $current );
188
+    return trim($current);
189 189
 }
190 190
 
191 191
 /**
@@ -193,27 +193,27 @@  discard block
 block discarded – undo
193 193
  * 
194 194
  * @param $string|null $current
195 195
  */
196
-function wpinv_decimals( $current = null ) {
196
+function wpinv_decimals($current = null) {
197 197
 
198
-    if ( null == $current ) {
199
-        $current = wpinv_get_option( 'decimals', 2 );
198
+    if (null == $current) {
199
+        $current = wpinv_get_option('decimals', 2);
200 200
     }
201 201
     
202
-    return absint( $current );
202
+    return absint($current);
203 203
 }
204 204
 
205 205
 /**
206 206
  * Retrieves a list of all supported currencies.
207 207
  */
208 208
 function wpinv_get_currencies() {
209
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
209
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
210 210
 }
211 211
 
212 212
 /**
213 213
  * Retrieves a list of all currency symbols.
214 214
  */
215 215
 function wpinv_get_currency_symbols() {
216
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
216
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
217 217
 }
218 218
 
219 219
 /**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	$currency_pos = wpinv_currency_position();
226 226
 	$format       = '%1$s%2$s';
227 227
 
228
-	switch ( $currency_pos ) {
228
+	switch ($currency_pos) {
229 229
 		case 'left':
230 230
 			$format = '%1$s%2$s';
231 231
 			break;
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 			break;
241 241
 	}
242 242
 
243
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
243
+	return apply_filters('getpaid_price_format', $format, $currency_pos);
244 244
 }
245 245
 
246 246
 /**
@@ -250,25 +250,25 @@  discard block
 block discarded – undo
250 250
  * @param  string $currency Currency.
251 251
  * @return string
252 252
  */
253
-function wpinv_price( $amount = 0, $currency = '' ) {
253
+function wpinv_price($amount = 0, $currency = '') {
254 254
 
255 255
     // Backwards compatibility.
256
-    $amount             = floatval( wpinv_sanitize_amount( $amount ) );
256
+    $amount             = floatval(wpinv_sanitize_amount($amount));
257 257
 
258 258
     // Prepare variables.
259
-    $currency           = wpinv_get_currency( $currency );
259
+    $currency           = wpinv_get_currency($currency);
260 260
     $amount             = (float) $amount;
261 261
     $unformatted_amount = $amount;
262 262
     $negative           = $amount < 0;
263
-    $amount             = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) );
264
-    $amount             = wpinv_format_amount( $amount );
263
+    $amount             = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount));
264
+    $amount             = wpinv_format_amount($amount);
265 265
 
266 266
     // Format the amount.
267 267
     $format             = getpaid_get_price_format();
268
-    $formatted_amount   = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount );
268
+    $formatted_amount   = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount);
269 269
 
270 270
     // Filter the formatting.
271
-    return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount );
271
+    return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount);
272 272
 }
273 273
 
274 274
 /**
@@ -279,33 +279,33 @@  discard block
 block discarded – undo
279 279
  * @param  bool     $calculate Whether or not to apply separators.
280 280
  * @return string
281 281
  */
282
-function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) {
282
+function wpinv_format_amount($amount, $decimals = null, $calculate = false) {
283 283
     $thousands_sep = wpinv_thousands_separator();
284 284
     $decimal_sep   = wpinv_decimal_separator();
285
-    $decimals      = wpinv_decimals( $decimals );
285
+    $decimals      = wpinv_decimals($decimals);
286 286
 
287 287
     // Format decimals.
288
-    $amount = str_replace( $decimal_sep, '.', $amount );
288
+    $amount = str_replace($decimal_sep, '.', $amount);
289 289
 
290 290
     // Remove thousands.
291
-    $amount = str_replace( $thousands_sep, '', $amount );
291
+    $amount = str_replace($thousands_sep, '', $amount);
292 292
 
293 293
     // Cast the remaining to a float.
294
-    $amount = floatval( $amount );
294
+    $amount = floatval($amount);
295 295
 
296
-    if ( $calculate ) {
296
+    if ($calculate) {
297 297
         return $amount;
298 298
     }
299 299
 
300 300
     // Fomart the amount.
301
-    return number_format( $amount, $decimals, $decimal_sep, $thousands_sep );
301
+    return number_format($amount, $decimals, $decimal_sep, $thousands_sep);
302 302
 }
303 303
 
304
-function wpinv_sanitize_key( $key ) {
304
+function wpinv_sanitize_key($key) {
305 305
     $raw_key = $key;
306
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
306
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
307 307
 
308
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
308
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
309 309
 }
310 310
 
311 311
 /**
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
  * 
314 314
  * @param $str the file whose extension should be retrieved.
315 315
  */
316
-function wpinv_get_file_extension( $str ) {
317
-    $filetype = wp_check_filetype( $str );
316
+function wpinv_get_file_extension($str) {
317
+    $filetype = wp_check_filetype($str);
318 318
     return $filetype['ext'];
319 319
 }
320 320
 
@@ -323,16 +323,16 @@  discard block
 block discarded – undo
323 323
  * 
324 324
  * @param string $string
325 325
  */
326
-function wpinv_string_is_image_url( $string ) {
327
-    $extension = strtolower( wpinv_get_file_extension( $string ) );
328
-    return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true );
326
+function wpinv_string_is_image_url($string) {
327
+    $extension = strtolower(wpinv_get_file_extension($string));
328
+    return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true);
329 329
 }
330 330
 
331 331
 /**
332 332
  * Returns the current URL.
333 333
  */
334 334
 function wpinv_get_current_page_url() {
335
-    return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
335
+    return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
336 336
 }
337 337
 
338 338
 /**
@@ -342,46 +342,46 @@  discard block
 block discarded – undo
342 342
  * @param string $name  Constant name.
343 343
  * @param mixed  $value Value.
344 344
  */
345
-function getpaid_maybe_define_constant( $name, $value ) {
346
-	if ( ! defined( $name ) ) {
347
-		define( $name, $value );
345
+function getpaid_maybe_define_constant($name, $value) {
346
+	if (!defined($name)) {
347
+		define($name, $value);
348 348
 	}
349 349
 }
350 350
 
351 351
 function wpinv_get_php_arg_separator_output() {
352
-	return ini_get( 'arg_separator.output' );
352
+	return ini_get('arg_separator.output');
353 353
 }
354 354
 
355
-function wpinv_rgb_from_hex( $color ) {
356
-    $color = str_replace( '#', '', $color );
355
+function wpinv_rgb_from_hex($color) {
356
+    $color = str_replace('#', '', $color);
357 357
 
358 358
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
359
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
360
-    if ( empty( $color ) ) {
359
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
360
+    if (empty($color)) {
361 361
         return NULL;
362 362
     }
363 363
 
364
-    $color = str_split( $color );
364
+    $color = str_split($color);
365 365
 
366 366
     $rgb      = array();
367
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
368
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
369
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
367
+    $rgb['R'] = hexdec($color[0] . $color[1]);
368
+    $rgb['G'] = hexdec($color[2] . $color[3]);
369
+    $rgb['B'] = hexdec($color[4] . $color[5]);
370 370
 
371 371
     return $rgb;
372 372
 }
373 373
 
374
-function wpinv_hex_darker( $color, $factor = 30 ) {
375
-    $base  = wpinv_rgb_from_hex( $color );
374
+function wpinv_hex_darker($color, $factor = 30) {
375
+    $base  = wpinv_rgb_from_hex($color);
376 376
     $color = '#';
377 377
 
378
-    foreach ( $base as $k => $v ) {
378
+    foreach ($base as $k => $v) {
379 379
         $amount      = $v / 100;
380
-        $amount      = round( $amount * $factor );
380
+        $amount      = round($amount * $factor);
381 381
         $new_decimal = $v - $amount;
382 382
 
383
-        $new_hex_component = dechex( $new_decimal );
384
-        if ( strlen( $new_hex_component ) < 2 ) {
383
+        $new_hex_component = dechex($new_decimal);
384
+        if (strlen($new_hex_component) < 2) {
385 385
             $new_hex_component = "0" . $new_hex_component;
386 386
         }
387 387
         $color .= $new_hex_component;
@@ -390,18 +390,18 @@  discard block
 block discarded – undo
390 390
     return $color;
391 391
 }
392 392
 
393
-function wpinv_hex_lighter( $color, $factor = 30 ) {
394
-    $base  = wpinv_rgb_from_hex( $color );
393
+function wpinv_hex_lighter($color, $factor = 30) {
394
+    $base  = wpinv_rgb_from_hex($color);
395 395
     $color = '#';
396 396
 
397
-    foreach ( $base as $k => $v ) {
397
+    foreach ($base as $k => $v) {
398 398
         $amount      = 255 - $v;
399 399
         $amount      = $amount / 100;
400
-        $amount      = round( $amount * $factor );
400
+        $amount      = round($amount * $factor);
401 401
         $new_decimal = $v + $amount;
402 402
 
403
-        $new_hex_component = dechex( $new_decimal );
404
-        if ( strlen( $new_hex_component ) < 2 ) {
403
+        $new_hex_component = dechex($new_decimal);
404
+        if (strlen($new_hex_component) < 2) {
405 405
             $new_hex_component = "0" . $new_hex_component;
406 406
         }
407 407
         $color .= $new_hex_component;
@@ -410,22 +410,22 @@  discard block
 block discarded – undo
410 410
     return $color;
411 411
 }
412 412
 
413
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
414
-    $hex = str_replace( '#', '', $color );
413
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
414
+    $hex = str_replace('#', '', $color);
415 415
 
416
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
417
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
418
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
416
+    $c_r = hexdec(substr($hex, 0, 2));
417
+    $c_g = hexdec(substr($hex, 2, 2));
418
+    $c_b = hexdec(substr($hex, 4, 2));
419 419
 
420
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
420
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
421 421
 
422 422
     return $brightness > 155 ? $dark : $light;
423 423
 }
424 424
 
425
-function wpinv_format_hex( $hex ) {
426
-    $hex = trim( str_replace( '#', '', $hex ) );
425
+function wpinv_format_hex($hex) {
426
+    $hex = trim(str_replace('#', '', $hex));
427 427
 
428
-    if ( strlen( $hex ) == 3 ) {
428
+    if (strlen($hex) == 3) {
429 429
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
430 430
     }
431 431
 
@@ -445,12 +445,12 @@  discard block
 block discarded – undo
445 445
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
446 446
  * @return string
447 447
  */
448
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
449
-    if ( function_exists( 'mb_strimwidth' ) ) {
450
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
448
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
449
+    if (function_exists('mb_strimwidth')) {
450
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
451 451
     }
452 452
     
453
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
453
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
454 454
 }
455 455
 
456 456
 /**
@@ -462,28 +462,28 @@  discard block
 block discarded – undo
462 462
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
463 463
  * @return int Returns the number of characters in string.
464 464
  */
465
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
466
-    if ( function_exists( 'mb_strlen' ) ) {
467
-        return mb_strlen( $str, $encoding );
465
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
466
+    if (function_exists('mb_strlen')) {
467
+        return mb_strlen($str, $encoding);
468 468
     }
469 469
         
470
-    return strlen( $str );
470
+    return strlen($str);
471 471
 }
472 472
 
473
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
474
-    if ( function_exists( 'mb_strtolower' ) ) {
475
-        return mb_strtolower( $str, $encoding );
473
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
474
+    if (function_exists('mb_strtolower')) {
475
+        return mb_strtolower($str, $encoding);
476 476
     }
477 477
     
478
-    return strtolower( $str );
478
+    return strtolower($str);
479 479
 }
480 480
 
481
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
482
-    if ( function_exists( 'mb_strtoupper' ) ) {
483
-        return mb_strtoupper( $str, $encoding );
481
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
482
+    if (function_exists('mb_strtoupper')) {
483
+        return mb_strtoupper($str, $encoding);
484 484
     }
485 485
     
486
-    return strtoupper( $str );
486
+    return strtoupper($str);
487 487
 }
488 488
 
489 489
 /**
@@ -497,12 +497,12 @@  discard block
 block discarded – undo
497 497
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
498 498
  * @return int Returns the position of the first occurrence of search in the string.
499 499
  */
500
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
501
-    if ( function_exists( 'mb_strpos' ) ) {
502
-        return mb_strpos( $str, $find, $offset, $encoding );
500
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
501
+    if (function_exists('mb_strpos')) {
502
+        return mb_strpos($str, $find, $offset, $encoding);
503 503
     }
504 504
         
505
-    return strpos( $str, $find, $offset );
505
+    return strpos($str, $find, $offset);
506 506
 }
507 507
 
508 508
 /**
@@ -516,12 +516,12 @@  discard block
 block discarded – undo
516 516
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
517 517
  * @return int Returns the position of the last occurrence of search.
518 518
  */
519
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
520
-    if ( function_exists( 'mb_strrpos' ) ) {
521
-        return mb_strrpos( $str, $find, $offset, $encoding );
519
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
520
+    if (function_exists('mb_strrpos')) {
521
+        return mb_strrpos($str, $find, $offset, $encoding);
522 522
     }
523 523
         
524
-    return strrpos( $str, $find, $offset );
524
+    return strrpos($str, $find, $offset);
525 525
 }
526 526
 
527 527
 /**
@@ -536,16 +536,16 @@  discard block
 block discarded – undo
536 536
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
537 537
  * @return string
538 538
  */
539
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
540
-    if ( function_exists( 'mb_substr' ) ) {
541
-        if ( $length === null ) {
542
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
539
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
540
+    if (function_exists('mb_substr')) {
541
+        if ($length === null) {
542
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
543 543
         } else {
544
-            return mb_substr( $str, $start, $length, $encoding );
544
+            return mb_substr($str, $start, $length, $encoding);
545 545
         }
546 546
     }
547 547
         
548
-    return substr( $str, $start, $length );
548
+    return substr($str, $start, $length);
549 549
 }
550 550
 
551 551
 /**
@@ -557,48 +557,48 @@  discard block
 block discarded – undo
557 557
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
558 558
  * @return string The width of string.
559 559
  */
560
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
561
-    if ( function_exists( 'mb_strwidth' ) ) {
562
-        return mb_strwidth( $str, $encoding );
560
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
561
+    if (function_exists('mb_strwidth')) {
562
+        return mb_strwidth($str, $encoding);
563 563
     }
564 564
     
565
-    return wpinv_utf8_strlen( $str, $encoding );
565
+    return wpinv_utf8_strlen($str, $encoding);
566 566
 }
567 567
 
568
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
569
-    if ( function_exists( 'mb_strlen' ) ) {
570
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
568
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
569
+    if (function_exists('mb_strlen')) {
570
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
571 571
         $str_end = "";
572 572
         
573
-        if ( $lower_str_end ) {
574
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
573
+        if ($lower_str_end) {
574
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
575 575
         } else {
576
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
576
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
577 577
         }
578 578
 
579 579
         return $first_letter . $str_end;
580 580
     }
581 581
     
582
-    return ucfirst( $str );
582
+    return ucfirst($str);
583 583
 }
584 584
 
585
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
586
-    if ( function_exists( 'mb_convert_case' ) ) {
587
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
585
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
586
+    if (function_exists('mb_convert_case')) {
587
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
588 588
     }
589 589
     
590
-    return ucwords( $str );
590
+    return ucwords($str);
591 591
 }
592 592
 
593
-function wpinv_period_in_days( $period, $unit ) {
594
-    $period = absint( $period );
593
+function wpinv_period_in_days($period, $unit) {
594
+    $period = absint($period);
595 595
     
596
-    if ( $period > 0 ) {
597
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
596
+    if ($period > 0) {
597
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
598 598
             $period = $period * 7;
599
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
599
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
600 600
             $period = $period * 30;
601
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
601
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
602 602
             $period = $period * 365;
603 603
         }
604 604
     }
@@ -606,14 +606,14 @@  discard block
 block discarded – undo
606 606
     return $period;
607 607
 }
608 608
 
609
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
610
-    if ( function_exists( 'cal_days_in_month' ) ) {
611
-        return cal_days_in_month( $calendar, $month, $year );
609
+function wpinv_cal_days_in_month($calendar, $month, $year) {
610
+    if (function_exists('cal_days_in_month')) {
611
+        return cal_days_in_month($calendar, $month, $year);
612 612
     }
613 613
 
614 614
     // Fallback in case the calendar extension is not loaded in PHP
615 615
     // Only supports Gregorian calendar
616
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
616
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
617 617
 }
618 618
 
619 619
 /**
@@ -624,12 +624,12 @@  discard block
 block discarded – undo
624 624
  *
625 625
  * @return string
626 626
  */
627
-function wpi_help_tip( $tip, $allow_html = false ) {
627
+function wpi_help_tip($tip, $allow_html = false) {
628 628
 
629
-    if ( $allow_html ) {
630
-        $tip = wpi_sanitize_tooltip( $tip );
629
+    if ($allow_html) {
630
+        $tip = wpi_sanitize_tooltip($tip);
631 631
     } else {
632
-        $tip = esc_attr( $tip );
632
+        $tip = esc_attr($tip);
633 633
     }
634 634
 
635 635
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -643,8 +643,8 @@  discard block
 block discarded – undo
643 643
  * @param string $var
644 644
  * @return string
645 645
  */
646
-function wpi_sanitize_tooltip( $var ) {
647
-    return wp_kses( html_entity_decode( $var ), array(
646
+function wpi_sanitize_tooltip($var) {
647
+    return wp_kses(html_entity_decode($var), array(
648 648
         'br'     => array(),
649 649
         'em'     => array(),
650 650
         'strong' => array(),
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
         'li'     => array(),
656 656
         'ol'     => array(),
657 657
         'p'      => array(),
658
-    ) );
658
+    ));
659 659
 }
660 660
 
661 661
 /**
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
  */
666 666
 function wpinv_get_screen_ids() {
667 667
 
668
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
668
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
669 669
 
670 670
     $screen_ids = array(
671 671
         'toplevel_page_' . $screen_id,
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
         'invoicing_page_wpi-addons',
684 684
     );
685 685
 
686
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
686
+    return apply_filters('wpinv_screen_ids', $screen_ids);
687 687
 }
688 688
 
689 689
 /**
@@ -694,14 +694,14 @@  discard block
 block discarded – undo
694 694
  * @param array|string $list List of values.
695 695
  * @return array Sanitized array of values.
696 696
  */
697
-function wpinv_parse_list( $list ) {
697
+function wpinv_parse_list($list) {
698 698
 
699
-    if ( empty( $list ) ) {
699
+    if (empty($list)) {
700 700
         $list = array();
701 701
     }
702 702
 
703
-	if ( ! is_array( $list ) ) {
704
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
703
+	if (!is_array($list)) {
704
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
705 705
 	}
706 706
 
707 707
 	return $list;
@@ -715,16 +715,16 @@  discard block
 block discarded – undo
715 715
  * @param string $key Type of data to fetch.
716 716
  * @return mixed Fetched data.
717 717
  */
718
-function wpinv_get_data( $key ) {
718
+function wpinv_get_data($key) {
719 719
 
720 720
     // Try fetching it from the cache.
721
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
722
-    if( $data ) {
721
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
722
+    if ($data) {
723 723
         return $data;
724 724
     }
725 725
 
726
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
727
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
726
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
727
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
728 728
 
729 729
 	return $data;
730 730
 }
@@ -738,10 +738,10 @@  discard block
 block discarded – undo
738 738
  * @param bool $first_empty Whether or not the first item in the list should be empty
739 739
  * @return mixed Fetched data.
740 740
  */
741
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
741
+function wpinv_maybe_add_empty_option($options, $first_empty) {
742 742
 
743
-    if ( ! empty( $options ) && $first_empty ) {
744
-        return array_merge( array( '' => '' ), $options );
743
+    if (!empty($options) && $first_empty) {
744
+        return array_merge(array('' => ''), $options);
745 745
     }
746 746
     return $options;
747 747
 
@@ -753,21 +753,21 @@  discard block
 block discarded – undo
753 753
  * @param mixed $var Data to sanitize.
754 754
  * @return string|array
755 755
  */
756
-function wpinv_clean( $var ) {
756
+function wpinv_clean($var) {
757 757
 
758
-	if ( is_array( $var ) ) {
759
-		return array_map( 'wpinv_clean', $var );
758
+	if (is_array($var)) {
759
+		return array_map('wpinv_clean', $var);
760 760
     }
761 761
 
762
-    if ( is_object( $var ) ) {
763
-		$object_vars = get_object_vars( $var );
764
-		foreach ( $object_vars as $property_name => $property_value ) {
765
-			$var->$property_name = wpinv_clean( $property_value );
762
+    if (is_object($var)) {
763
+		$object_vars = get_object_vars($var);
764
+		foreach ($object_vars as $property_name => $property_value) {
765
+			$var->$property_name = wpinv_clean($property_value);
766 766
         }
767 767
         return $var;
768 768
 	}
769 769
     
770
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
770
+    return is_string($var) ? sanitize_text_field($var) : $var;
771 771
 }
772 772
 
773 773
 /**
@@ -776,43 +776,43 @@  discard block
 block discarded – undo
776 776
  * @param string $str Data to convert.
777 777
  * @return string|array
778 778
  */
779
-function getpaid_convert_price_string_to_options( $str ) {
779
+function getpaid_convert_price_string_to_options($str) {
780 780
 
781
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
782
-    $options     = array();
781
+	$raw_options = array_map('trim', explode(',', $str));
782
+    $options = array();
783 783
 
784
-    foreach ( $raw_options as $option ) {
784
+    foreach ($raw_options as $option) {
785 785
 
786
-        if ( '' == $option ) {
786
+        if ('' == $option) {
787 787
             continue;
788 788
         }
789 789
 
790
-        $option = array_map( 'trim', explode( '|', $option ) );
790
+        $option = array_map('trim', explode('|', $option));
791 791
 
792 792
         $price = null;
793 793
         $label = null;
794 794
 
795
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
796
-            $label  = $option[0];
795
+        if (isset($option[0]) && '' != $option[0]) {
796
+            $label = $option[0];
797 797
         }
798 798
 
799
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
799
+        if (isset($option[1]) && '' != $option[1]) {
800 800
             $price = $option[1];
801 801
         }
802 802
 
803
-        if ( ! isset( $price ) ) {
803
+        if (!isset($price)) {
804 804
             $price = $label;
805 805
         }
806 806
 
807
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
807
+        if (!isset($price) || !is_numeric($price)) {
808 808
             continue;
809 809
         }
810 810
 
811
-        if ( ! isset( $label ) ) {
811
+        if (!isset($label)) {
812 812
             $label = $price;
813 813
         }
814 814
 
815
-        $options[ $price ] = $label;
815
+        $options[$price] = $label;
816 816
     }
817 817
 
818 818
     return $options;
@@ -821,22 +821,22 @@  discard block
 block discarded – undo
821 821
 /**
822 822
  * Returns the help tip.
823 823
  */
824
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
825
-    $additional_classes = sanitize_html_class( $additional_classes );
826
-    $tip                = esc_attr__( $tip );
824
+function getpaid_get_help_tip($tip, $additional_classes = '') {
825
+    $additional_classes = sanitize_html_class($additional_classes);
826
+    $tip                = esc_attr__($tip);
827 827
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
828 828
 }
829 829
 
830 830
 /**
831 831
  * Formats a date
832 832
  */
833
-function getpaid_format_date( $date ) {
833
+function getpaid_format_date($date) {
834 834
 
835
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
835
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
836 836
         return '';
837 837
     }
838 838
 
839
-    return date_i18n( getpaid_date_format(), strtotime( $date ) );
839
+    return date_i18n(getpaid_date_format(), strtotime($date));
840 840
 
841 841
 }
842 842
 
@@ -845,9 +845,9 @@  discard block
 block discarded – undo
845 845
  *
846 846
  * @return string
847 847
  */
848
-function getpaid_format_date_value( $date, $default = "&mdash;" ) {
849
-    $date = getpaid_format_date( $date );
850
-    return empty( $date ) ? $default : $date;
848
+function getpaid_format_date_value($date, $default = "&mdash;") {
849
+    $date = getpaid_format_date($date);
850
+    return empty($date) ? $default : $date;
851 851
 }
852 852
 
853 853
 /**
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
  * @return string
857 857
  */
858 858
 function getpaid_date_format() {
859
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
859
+	return apply_filters('getpaid_date_format', get_option('date_format'));
860 860
 }
861 861
 
862 862
 /**
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
  * @return string
866 866
  */
867 867
 function getpaid_time_format() {
868
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
868
+	return apply_filters('getpaid_time_format', get_option('time_format'));
869 869
 }
870 870
 
871 871
 /**
@@ -875,16 +875,16 @@  discard block
 block discarded – undo
875 875
  * @param  integer $limit Limit size in characters.
876 876
  * @return string
877 877
  */
878
-function getpaid_limit_length( $string, $limit ) {
878
+function getpaid_limit_length($string, $limit) {
879 879
     $str_limit = $limit - 3;
880 880
 
881
-	if ( function_exists( 'mb_strimwidth' ) ) {
882
-		if ( mb_strlen( $string ) > $limit ) {
883
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
881
+	if (function_exists('mb_strimwidth')) {
882
+		if (mb_strlen($string) > $limit) {
883
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
884 884
 		}
885 885
 	} else {
886
-		if ( strlen( $string ) > $limit ) {
887
-			$string = substr( $string, 0, $str_limit ) . '...';
886
+		if (strlen($string) > $limit) {
887
+			$string = substr($string, 0, $str_limit) . '...';
888 888
 		}
889 889
 	}
890 890
     return $string;
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
  * @since 1.0.19
899 899
  */
900 900
 function getpaid_api() {
901
-    return getpaid()->get( 'api' );
901
+    return getpaid()->get('api');
902 902
 }
903 903
 
904 904
 /**
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
  * @since 1.0.19
909 909
  */
910 910
 function getpaid_post_types() {
911
-    return getpaid()->get( 'post_types' );
911
+    return getpaid()->get('post_types');
912 912
 }
913 913
 
914 914
 /**
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
  * @since 1.0.19
919 919
  */
920 920
 function getpaid_session() {
921
-    return getpaid()->get( 'session' );
921
+    return getpaid()->get('session');
922 922
 }
923 923
 
924 924
 /**
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
  * @since 1.0.19
929 929
  */
930 930
 function getpaid_notes() {
931
-    return getpaid()->get( 'notes' );
931
+    return getpaid()->get('notes');
932 932
 }
933 933
 
934 934
 /**
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  * @return GetPaid_Admin
938 938
  */
939 939
 function getpaid_admin() {
940
-    return getpaid()->get( 'admin' );
940
+    return getpaid()->get('admin');
941 941
 }
942 942
 
943 943
 /**
@@ -947,8 +947,8 @@  discard block
 block discarded – undo
947 947
  * @param string $base the base url
948 948
  * @return string
949 949
  */
950
-function getpaid_get_authenticated_action_url( $action, $base = false ) {
951
-    return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' );
950
+function getpaid_get_authenticated_action_url($action, $base = false) {
951
+    return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce');
952 952
 }
953 953
 
954 954
 /**
@@ -956,11 +956,11 @@  discard block
 block discarded – undo
956 956
  *
957 957
  * @return string
958 958
  */
959
-function getpaid_get_post_type_label( $post_type, $plural = true ) {
959
+function getpaid_get_post_type_label($post_type, $plural = true) {
960 960
 
961
-    $post_type = get_post_type_object( $post_type );
961
+    $post_type = get_post_type_object($post_type);
962 962
 
963
-    if ( ! is_object( $post_type ) ) {
963
+    if (!is_object($post_type)) {
964 964
         return null;
965 965
     }
966 966
 
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +467 added lines, -467 removed lines patch added patch discarded remove patch
@@ -14,500 +14,500 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * Tax instance.
40
-	 *
41
-	 * @var WPInv_EUVat
42
-	 */
43
-	public $tax;
44
-
45
-	/**
46
-	 * @param array An array of payment gateways.
47
-	 */
48
-	public $gateways;
49
-
50
-	/**
51
-	 * Class constructor.
52
-	 */
53
-	public function __construct() {
54
-		$this->define_constants();
55
-		$this->includes();
56
-		$this->init_hooks();
57
-		$this->set_properties();
58
-	}
59
-
60
-	/**
61
-	 * Sets a custom data property.
62
-	 * 
63
-	 * @param string $prop The prop to set.
64
-	 * @param mixed $value The value to retrieve.
65
-	 */
66
-	public function set( $prop, $value ) {
67
-		$this->data[ $prop ] = $value;
68
-	}
69
-
70
-	/**
71
-	 * Gets a custom data property.
72
-	 *
73
-	 * @param string $prop The prop to set.
74
-	 * @return mixed The value.
75
-	 */
76
-	public function get( $prop ) {
77
-
78
-		if ( isset( $this->data[ $prop ] ) ) {
79
-			return $this->data[ $prop ];
80
-		}
81
-
82
-		return null;
83
-	}
84
-
85
-	/**
86
-	 * Define class properties.
87
-	 */
88
-	public function set_properties() {
89
-
90
-		// Sessions.
91
-		$this->set( 'session', new WPInv_Session_Handler() );
92
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
93
-		$this->tax              = new WPInv_EUVat();
94
-		$this->tax->init();
95
-		$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
96
-
97
-		// Init other objects.
98
-		$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
99
-		$this->set( 'session', new WPInv_Session_Handler() );
100
-		$this->set( 'notes', new WPInv_Notes() );
101
-		$this->set( 'api', new WPInv_API() );
102
-		$this->set( 'post_types', new GetPaid_Post_Types() );
103
-		$this->set( 'template', new GetPaid_Template() );
104
-		$this->set( 'admin', new GetPaid_Admin() );
105
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
106
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
107
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
108
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
109
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
110
-
111
-	}
112
-
113
-	 /**
114
-	 * Define plugin constants.
115
-	 */
116
-	public function define_constants() {
117
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
118
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
119
-		$this->version = WPINV_VERSION;
120
-	}
121
-
122
-	/**
123
-	 * Hook into actions and filters.
124
-	 *
125
-	 * @since 1.0.19
126
-	 */
127
-	protected function init_hooks() {
128
-		/* Internationalize the text strings used. */
129
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
130
-
131
-		// Init the plugin after WordPress inits.
132
-		add_action( 'init', array( $this, 'init' ), 1 );
133
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
134
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
135
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
136
-
137
-		if ( class_exists( 'BuddyPress' ) ) {
138
-			add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
139
-		}
140
-
141
-		add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
142
-		add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
143
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
144
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
145
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
146
-
147
-		// Fires after registering actions.
148
-		do_action( 'wpinv_actions', $this );
149
-		do_action( 'getpaid_actions', $this );
150
-
151
-	}
152
-
153
-	public function plugins_loaded() {
154
-		/* Internationalize the text strings used. */
155
-		$this->load_textdomain();
156
-
157
-		do_action( 'wpinv_loaded' );
158
-
159
-		// Fix oxygen page builder conflict
160
-		if ( function_exists( 'ct_css_output' ) ) {
161
-			wpinv_oxygen_fix_conflict();
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Load the translation of the plugin.
167
-	 *
168
-	 * @since 1.0
169
-	 */
170
-	public function load_textdomain( $locale = NULL ) {
171
-		if ( empty( $locale ) ) {
172
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
173
-		}
174
-
175
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
176
-
177
-		unload_textdomain( 'invoicing' );
178
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
179
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
180
-
181
-		/**
182
-		 * Define language constants.
183
-		 */
184
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
185
-	}
186
-
187
-	/**
188
-	 * Include required core files used in admin and on the frontend.
189
-	 */
190
-	public function includes() {
191
-
192
-		// Start with the settings.
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
194
-
195
-		// Packages/libraries.
196
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
198
-
199
-		// Load functions.
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
206
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
207
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
208
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
209
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
210
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
211
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
212
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
215
-
216
-		// Register autoloader.
217
-		try {
218
-			spl_autoload_register( array( $this, 'autoload' ), true );
219
-		} catch ( Exception $e ) {
220
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
221
-		}
222
-
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
235
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
236
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
237
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
238
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
239
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
240
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
241
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
242
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
243
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
244
-
245
-		/**
246
-		 * Load the tax class.
247
-		 */
248
-		if ( ! class_exists( 'WPInv_EUVat' ) ) {
249
-			require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
250
-		}
251
-
252
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
253
-			GetPaid_Post_Types_Admin::init();
254
-
255
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
256
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
257
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
258
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
259
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
260
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
261
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
262
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
263
-			// load the user class only on the users.php page
264
-			global $pagenow;
265
-			if($pagenow=='users.php'){
266
-				new WPInv_Admin_Users();
267
-			}
268
-		}
269
-
270
-		// Register cli commands
271
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
272
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
273
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
274
-		}
275
-
276
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
277
-	}
278
-
279
-	/**
280
-	 * Class autoloader
281
-	 *
282
-	 * @param       string $class_name The name of the class to load.
283
-	 * @access      public
284
-	 * @since       1.0.19
285
-	 * @return      void
286
-	 */
287
-	public function autoload( $class_name ) {
288
-
289
-		// Normalize the class name...
290
-		$class_name  = strtolower( $class_name );
291
-
292
-		// ... and make sure it is our class.
293
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
294
-			return;
295
-		}
296
-
297
-		// Next, prepare the file name from the class.
298
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
299
-
300
-		// Base path of the classes.
301
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
302
-
303
-		// And an array of possible locations in order of importance.
304
-		$locations = array(
305
-			"$plugin_path/includes",
306
-			"$plugin_path/includes/data-stores",
307
-			"$plugin_path/includes/gateways",
308
-			"$plugin_path/includes/payments",
309
-			"$plugin_path/includes/api",
310
-			"$plugin_path/includes/admin",
311
-			"$plugin_path/includes/admin/meta-boxes",
312
-		);
313
-
314
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
315
-
316
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
317
-				include trailingslashit( $location ) . $file_name;
318
-				break;
319
-			}
320
-
321
-		}
322
-
323
-	}
324
-
325
-	/**
326
-	 * Inits hooks etc.
327
-	 */
328
-	public function init() {
329
-
330
-		// Fires before getpaid inits.
331
-		do_action( 'before_getpaid_init', $this );
332
-
333
-		// Load default gateways.
334
-		$gateways = apply_filters(
335
-			'getpaid_default_gateways',
336
-			array(
337
-				'manual'        => 'GetPaid_Manual_Gateway',
338
-				'paypal'        => 'GetPaid_Paypal_Gateway',
339
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
340
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
341
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
342
-			)
343
-		);
344
-
345
-		foreach ( $gateways as $id => $class ) {
346
-			$this->gateways[ $id ] = new $class();
347
-		}
348
-
349
-		// Fires after getpaid inits.
350
-		do_action( 'getpaid_init', $this );
351
-
352
-	}
353
-
354
-	/**
355
-	 * Checks if this is an IPN request and processes it.
356
-	 */
357
-	public function maybe_process_ipn() {
358
-
359
-		// Ensure that this is an IPN request.
360
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
361
-			return;
362
-		}
363
-
364
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
365
-
366
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
367
-		do_action( "wpinv_verify_{$gateway}_ipn" );
368
-		exit;
369
-
370
-	}
371
-
372
-	public function enqueue_scripts() {
373
-		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
374
-
375
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
376
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
377
-		wp_enqueue_style( 'wpinv_front_style' );
378
-
379
-		// Register scripts
380
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
381
-		wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
382
-
383
-		$localize                         = array();
384
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
385
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
386
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
387
-		$localize['UseTaxes']             = wpinv_use_taxes();
388
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
389
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
390
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * Tax instance.
40
+     *
41
+     * @var WPInv_EUVat
42
+     */
43
+    public $tax;
44
+
45
+    /**
46
+     * @param array An array of payment gateways.
47
+     */
48
+    public $gateways;
49
+
50
+    /**
51
+     * Class constructor.
52
+     */
53
+    public function __construct() {
54
+        $this->define_constants();
55
+        $this->includes();
56
+        $this->init_hooks();
57
+        $this->set_properties();
58
+    }
59
+
60
+    /**
61
+     * Sets a custom data property.
62
+     * 
63
+     * @param string $prop The prop to set.
64
+     * @param mixed $value The value to retrieve.
65
+     */
66
+    public function set( $prop, $value ) {
67
+        $this->data[ $prop ] = $value;
68
+    }
69
+
70
+    /**
71
+     * Gets a custom data property.
72
+     *
73
+     * @param string $prop The prop to set.
74
+     * @return mixed The value.
75
+     */
76
+    public function get( $prop ) {
77
+
78
+        if ( isset( $this->data[ $prop ] ) ) {
79
+            return $this->data[ $prop ];
80
+        }
81
+
82
+        return null;
83
+    }
84
+
85
+    /**
86
+     * Define class properties.
87
+     */
88
+    public function set_properties() {
89
+
90
+        // Sessions.
91
+        $this->set( 'session', new WPInv_Session_Handler() );
92
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
93
+        $this->tax              = new WPInv_EUVat();
94
+        $this->tax->init();
95
+        $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
96
+
97
+        // Init other objects.
98
+        $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
99
+        $this->set( 'session', new WPInv_Session_Handler() );
100
+        $this->set( 'notes', new WPInv_Notes() );
101
+        $this->set( 'api', new WPInv_API() );
102
+        $this->set( 'post_types', new GetPaid_Post_Types() );
103
+        $this->set( 'template', new GetPaid_Template() );
104
+        $this->set( 'admin', new GetPaid_Admin() );
105
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
106
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
107
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
108
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
109
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
110
+
111
+    }
112
+
113
+        /**
114
+         * Define plugin constants.
115
+         */
116
+    public function define_constants() {
117
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
118
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
119
+        $this->version = WPINV_VERSION;
120
+    }
121
+
122
+    /**
123
+     * Hook into actions and filters.
124
+     *
125
+     * @since 1.0.19
126
+     */
127
+    protected function init_hooks() {
128
+        /* Internationalize the text strings used. */
129
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
130
+
131
+        // Init the plugin after WordPress inits.
132
+        add_action( 'init', array( $this, 'init' ), 1 );
133
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
134
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
135
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
136
+
137
+        if ( class_exists( 'BuddyPress' ) ) {
138
+            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
139
+        }
140
+
141
+        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
142
+        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
143
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
144
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
145
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
146
+
147
+        // Fires after registering actions.
148
+        do_action( 'wpinv_actions', $this );
149
+        do_action( 'getpaid_actions', $this );
150
+
151
+    }
152
+
153
+    public function plugins_loaded() {
154
+        /* Internationalize the text strings used. */
155
+        $this->load_textdomain();
156
+
157
+        do_action( 'wpinv_loaded' );
158
+
159
+        // Fix oxygen page builder conflict
160
+        if ( function_exists( 'ct_css_output' ) ) {
161
+            wpinv_oxygen_fix_conflict();
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Load the translation of the plugin.
167
+     *
168
+     * @since 1.0
169
+     */
170
+    public function load_textdomain( $locale = NULL ) {
171
+        if ( empty( $locale ) ) {
172
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
173
+        }
174
+
175
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
176
+
177
+        unload_textdomain( 'invoicing' );
178
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
179
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
180
+
181
+        /**
182
+         * Define language constants.
183
+         */
184
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
185
+    }
186
+
187
+    /**
188
+     * Include required core files used in admin and on the frontend.
189
+     */
190
+    public function includes() {
191
+
192
+        // Start with the settings.
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
194
+
195
+        // Packages/libraries.
196
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
198
+
199
+        // Load functions.
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
205
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
206
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
207
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
208
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
209
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
210
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
211
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
212
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
213
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
215
+
216
+        // Register autoloader.
217
+        try {
218
+            spl_autoload_register( array( $this, 'autoload' ), true );
219
+        } catch ( Exception $e ) {
220
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
221
+        }
222
+
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
234
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
235
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
236
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
237
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
238
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
239
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
240
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
241
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
242
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
243
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
244
+
245
+        /**
246
+         * Load the tax class.
247
+         */
248
+        if ( ! class_exists( 'WPInv_EUVat' ) ) {
249
+            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
250
+        }
251
+
252
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
253
+            GetPaid_Post_Types_Admin::init();
254
+
255
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
256
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
257
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
258
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
259
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
260
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
261
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
262
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
263
+            // load the user class only on the users.php page
264
+            global $pagenow;
265
+            if($pagenow=='users.php'){
266
+                new WPInv_Admin_Users();
267
+            }
268
+        }
269
+
270
+        // Register cli commands
271
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
272
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
273
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
274
+        }
275
+
276
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
277
+    }
391 278
 
392
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
393
-
394
-		wp_enqueue_script( 'jquery-blockui' );
279
+    /**
280
+     * Class autoloader
281
+     *
282
+     * @param       string $class_name The name of the class to load.
283
+     * @access      public
284
+     * @since       1.0.19
285
+     * @return      void
286
+     */
287
+    public function autoload( $class_name ) {
288
+
289
+        // Normalize the class name...
290
+        $class_name  = strtolower( $class_name );
291
+
292
+        // ... and make sure it is our class.
293
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
294
+            return;
295
+        }
296
+
297
+        // Next, prepare the file name from the class.
298
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
299
+
300
+        // Base path of the classes.
301
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
302
+
303
+        // And an array of possible locations in order of importance.
304
+        $locations = array(
305
+            "$plugin_path/includes",
306
+            "$plugin_path/includes/data-stores",
307
+            "$plugin_path/includes/gateways",
308
+            "$plugin_path/includes/payments",
309
+            "$plugin_path/includes/api",
310
+            "$plugin_path/includes/admin",
311
+            "$plugin_path/includes/admin/meta-boxes",
312
+        );
313
+
314
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
315
+
316
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
317
+                include trailingslashit( $location ) . $file_name;
318
+                break;
319
+            }
320
+
321
+        }
322
+
323
+    }
324
+
325
+    /**
326
+     * Inits hooks etc.
327
+     */
328
+    public function init() {
329
+
330
+        // Fires before getpaid inits.
331
+        do_action( 'before_getpaid_init', $this );
332
+
333
+        // Load default gateways.
334
+        $gateways = apply_filters(
335
+            'getpaid_default_gateways',
336
+            array(
337
+                'manual'        => 'GetPaid_Manual_Gateway',
338
+                'paypal'        => 'GetPaid_Paypal_Gateway',
339
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
340
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
341
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
342
+            )
343
+        );
344
+
345
+        foreach ( $gateways as $id => $class ) {
346
+            $this->gateways[ $id ] = new $class();
347
+        }
348
+
349
+        // Fires after getpaid inits.
350
+        do_action( 'getpaid_init', $this );
351
+
352
+    }
353
+
354
+    /**
355
+     * Checks if this is an IPN request and processes it.
356
+     */
357
+    public function maybe_process_ipn() {
358
+
359
+        // Ensure that this is an IPN request.
360
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
361
+            return;
362
+        }
363
+
364
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
365
+
366
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
367
+        do_action( "wpinv_verify_{$gateway}_ipn" );
368
+        exit;
369
+
370
+    }
395 371
 
396
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' );
397
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
372
+    public function enqueue_scripts() {
373
+        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
398 374
 
399
-		wp_enqueue_script( 'wpinv-front-script' );
400
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
401
-
402
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
403
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
404
-	}
405
-
406
-	public function wpinv_actions() {
407
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
408
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
409
-		}
410
-	}
375
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
376
+        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
377
+        wp_enqueue_style( 'wpinv_front_style' );
411 378
 
412
-	/**
379
+        // Register scripts
380
+        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
381
+        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
382
+
383
+        $localize                         = array();
384
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
385
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
386
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
387
+        $localize['UseTaxes']             = wpinv_use_taxes();
388
+        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
389
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
390
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
391
+
392
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
393
+
394
+        wp_enqueue_script( 'jquery-blockui' );
395
+
396
+        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' );
397
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
398
+
399
+        wp_enqueue_script( 'wpinv-front-script' );
400
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
401
+
402
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
403
+        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
404
+    }
405
+
406
+    public function wpinv_actions() {
407
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
408
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
409
+        }
410
+    }
411
+
412
+    /**
413 413
      * Fires an action after verifying that a user can fire them.
414
-	 *
415
-	 * Note: If the action is on an invoice, subscription etc, esure that the
416
-	 * current user owns the invoice/subscription.
414
+     *
415
+     * Note: If the action is on an invoice, subscription etc, esure that the
416
+     * current user owns the invoice/subscription.
417 417
      */
418 418
     public function maybe_do_authenticated_action() {
419 419
 
420
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
420
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
421 421
 
422
-			$key = sanitize_key( $_REQUEST['getpaid-action'] );
423
-			if ( is_user_logged_in() ) {
424
-				do_action( "getpaid_authenticated_action_$key", $_REQUEST );
425
-			}
422
+            $key = sanitize_key( $_REQUEST['getpaid-action'] );
423
+            if ( is_user_logged_in() ) {
424
+                do_action( "getpaid_authenticated_action_$key", $_REQUEST );
425
+            }
426 426
 
427
-			do_action( "getpaid_unauthenticated_action_$key", $_REQUEST );
427
+            do_action( "getpaid_unauthenticated_action_$key", $_REQUEST );
428 428
 
429
-		}
429
+        }
430 430
         
431 431
 
432 432
     }
433 433
 
434
-	public function pre_get_posts( $wp_query ) {
435
-
436
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
437
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
438
-		}
439
-
440
-		return $wp_query;
441
-	}
442
-
443
-	public function bp_invoicing_init() {
444
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
445
-	}
446
-
447
-	/**
448
-	 * Register widgets
449
-	 *
450
-	 */
451
-	public function register_widgets() {
452
-		$widgets = apply_filters(
453
-			'getpaid_widget_classes',
454
-			array(
455
-				'WPInv_Checkout_Widget',
456
-				'WPInv_History_Widget',
457
-				'WPInv_Receipt_Widget',
458
-				'WPInv_Subscriptions_Widget',
459
-				'WPInv_Buy_Item_Widget',
460
-				'WPInv_Messages_Widget',
461
-				'WPInv_GetPaid_Widget'
462
-			)
463
-		);
464
-
465
-		foreach ( $widgets as $widget ) {
466
-			register_widget( $widget );
467
-		}
434
+    public function pre_get_posts( $wp_query ) {
435
+
436
+        if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
437
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
438
+        }
439
+
440
+        return $wp_query;
441
+    }
442
+
443
+    public function bp_invoicing_init() {
444
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
445
+    }
446
+
447
+    /**
448
+     * Register widgets
449
+     *
450
+     */
451
+    public function register_widgets() {
452
+        $widgets = apply_filters(
453
+            'getpaid_widget_classes',
454
+            array(
455
+                'WPInv_Checkout_Widget',
456
+                'WPInv_History_Widget',
457
+                'WPInv_Receipt_Widget',
458
+                'WPInv_Subscriptions_Widget',
459
+                'WPInv_Buy_Item_Widget',
460
+                'WPInv_Messages_Widget',
461
+                'WPInv_GetPaid_Widget'
462
+            )
463
+        );
464
+
465
+        foreach ( $widgets as $widget ) {
466
+            register_widget( $widget );
467
+        }
468 468
 		
469
-	}
469
+    }
470 470
 
471
-	/**
472
-	 * Remove our pages from yoast sitemaps.
473
-	 *
474
-	 * @since 1.0.19
475
-	 * @param int[] $excluded_posts_ids
476
-	 */
477
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
471
+    /**
472
+     * Remove our pages from yoast sitemaps.
473
+     *
474
+     * @since 1.0.19
475
+     * @param int[] $excluded_posts_ids
476
+     */
477
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
478 478
 
479
-		// Ensure that we have an array.
480
-		if ( ! is_array( $excluded_posts_ids ) ) {
481
-			$excluded_posts_ids = array();
482
-		}
479
+        // Ensure that we have an array.
480
+        if ( ! is_array( $excluded_posts_ids ) ) {
481
+            $excluded_posts_ids = array();
482
+        }
483 483
 
484
-		// Prepare our pages.
485
-		$our_pages = array();
484
+        // Prepare our pages.
485
+        $our_pages = array();
486 486
 
487
-		// Checkout page.
488
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
487
+        // Checkout page.
488
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
489 489
 
490
-		// Success page.
491
-		$our_pages[] = wpinv_get_option( 'success_page', false );
490
+        // Success page.
491
+        $our_pages[] = wpinv_get_option( 'success_page', false );
492 492
 
493
-		// Failure page.
494
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
493
+        // Failure page.
494
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
495 495
 
496
-		// History page.
497
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
496
+        // History page.
497
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
498 498
 
499
-		// Subscriptions page.
500
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
499
+        // Subscriptions page.
500
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
501 501
 
502
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
502
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
503 503
 
504
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
505
-		return array_unique( $excluded_posts_ids );
504
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
505
+        return array_unique( $excluded_posts_ids );
506 506
 
507
-	}
507
+    }
508 508
 
509
-	public function wp_footer() {
510
-		echo '
509
+    public function wp_footer() {
510
+        echo '
511 511
 			<div class="bsui">
512 512
 				<div  id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog">
513 513
 					<div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;">
@@ -518,6 +518,6 @@  discard block
 block discarded – undo
518 518
 				</div>
519 519
 			</div>
520 520
 		';
521
-	}
521
+    }
522 522
 
523 523
 }
Please login to merge, or discard this patch.
Spacing   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Main Invoicing class.
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 * @param string $prop The prop to set.
64 64
 	 * @param mixed $value The value to retrieve.
65 65
 	 */
66
-	public function set( $prop, $value ) {
67
-		$this->data[ $prop ] = $value;
66
+	public function set($prop, $value) {
67
+		$this->data[$prop] = $value;
68 68
 	}
69 69
 
70 70
 	/**
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
 	 * @param string $prop The prop to set.
74 74
 	 * @return mixed The value.
75 75
 	 */
76
-	public function get( $prop ) {
76
+	public function get($prop) {
77 77
 
78
-		if ( isset( $this->data[ $prop ] ) ) {
79
-			return $this->data[ $prop ];
78
+		if (isset($this->data[$prop])) {
79
+			return $this->data[$prop];
80 80
 		}
81 81
 
82 82
 		return null;
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
 	public function set_properties() {
89 89
 
90 90
 		// Sessions.
91
-		$this->set( 'session', new WPInv_Session_Handler() );
92
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
91
+		$this->set('session', new WPInv_Session_Handler());
92
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
93 93
 		$this->tax              = new WPInv_EUVat();
94 94
 		$this->tax->init();
95 95
 		$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
96 96
 
97 97
 		// Init other objects.
98
-		$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
99
-		$this->set( 'session', new WPInv_Session_Handler() );
100
-		$this->set( 'notes', new WPInv_Notes() );
101
-		$this->set( 'api', new WPInv_API() );
102
-		$this->set( 'post_types', new GetPaid_Post_Types() );
103
-		$this->set( 'template', new GetPaid_Template() );
104
-		$this->set( 'admin', new GetPaid_Admin() );
105
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
106
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
107
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
108
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
109
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
98
+		$this->set('reports', new WPInv_Reports()); // TODO: Refactor.
99
+		$this->set('session', new WPInv_Session_Handler());
100
+		$this->set('notes', new WPInv_Notes());
101
+		$this->set('api', new WPInv_API());
102
+		$this->set('post_types', new GetPaid_Post_Types());
103
+		$this->set('template', new GetPaid_Template());
104
+		$this->set('admin', new GetPaid_Admin());
105
+		$this->set('subscriptions', new WPInv_Subscriptions());
106
+		$this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails());
107
+		$this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails());
108
+		$this->set('daily_maintenace', new GetPaid_Daily_Maintenance());
109
+		$this->set('payment_forms', new GetPaid_Payment_Forms());
110 110
 
111 111
 	}
112 112
 
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * Define plugin constants.
115 115
 	 */
116 116
 	public function define_constants() {
117
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
118
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
117
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
118
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
119 119
 		$this->version = WPINV_VERSION;
120 120
 	}
121 121
 
@@ -126,27 +126,27 @@  discard block
 block discarded – undo
126 126
 	 */
127 127
 	protected function init_hooks() {
128 128
 		/* Internationalize the text strings used. */
129
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
129
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
130 130
 
131 131
 		// Init the plugin after WordPress inits.
132
-		add_action( 'init', array( $this, 'init' ), 1 );
133
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
134
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
135
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
132
+		add_action('init', array($this, 'init'), 1);
133
+		add_action('init', array($this, 'maybe_process_ipn'), 10);
134
+		add_action('init', array($this, 'wpinv_actions'));
135
+		add_action('init', array($this, 'maybe_do_authenticated_action'), 100);
136 136
 
137
-		if ( class_exists( 'BuddyPress' ) ) {
138
-			add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
137
+		if (class_exists('BuddyPress')) {
138
+			add_action('bp_include', array(&$this, 'bp_invoicing_init'));
139 139
 		}
140 140
 
141
-		add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
142
-		add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
143
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
144
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
145
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
141
+		add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
142
+		add_action('wp_footer', array(&$this, 'wp_footer'));
143
+		add_action('widgets_init', array(&$this, 'register_widgets'));
144
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
145
+		add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
146 146
 
147 147
 		// Fires after registering actions.
148
-		do_action( 'wpinv_actions', $this );
149
-		do_action( 'getpaid_actions', $this );
148
+		do_action('wpinv_actions', $this);
149
+		do_action('getpaid_actions', $this);
150 150
 
151 151
 	}
152 152
 
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 		/* Internationalize the text strings used. */
155 155
 		$this->load_textdomain();
156 156
 
157
-		do_action( 'wpinv_loaded' );
157
+		do_action('wpinv_loaded');
158 158
 
159 159
 		// Fix oxygen page builder conflict
160
-		if ( function_exists( 'ct_css_output' ) ) {
160
+		if (function_exists('ct_css_output')) {
161 161
 			wpinv_oxygen_fix_conflict();
162 162
 		}
163 163
 	}
@@ -167,21 +167,21 @@  discard block
 block discarded – undo
167 167
 	 *
168 168
 	 * @since 1.0
169 169
 	 */
170
-	public function load_textdomain( $locale = NULL ) {
171
-		if ( empty( $locale ) ) {
172
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
170
+	public function load_textdomain($locale = NULL) {
171
+		if (empty($locale)) {
172
+			$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
173 173
 		}
174 174
 
175
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
175
+		$locale = apply_filters('plugin_locale', $locale, 'invoicing');
176 176
 
177
-		unload_textdomain( 'invoicing' );
178
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
179
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
177
+		unload_textdomain('invoicing');
178
+		load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
179
+		load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
180 180
 
181 181
 		/**
182 182
 		 * Define language constants.
183 183
 		 */
184
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
184
+		require_once(WPINV_PLUGIN_DIR . 'language.php');
185 185
 	}
186 186
 
187 187
 	/**
@@ -190,90 +190,90 @@  discard block
 block discarded – undo
190 190
 	public function includes() {
191 191
 
192 192
 		// Start with the settings.
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
193
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
194 194
 
195 195
 		// Packages/libraries.
196
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
196
+		require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
197
+		require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
198 198
 
199 199
 		// Load functions.
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
206
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
207
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
208
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
209
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
210
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
211
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
212
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
200
+		require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php');
201
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
202
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
203
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
204
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
205
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
206
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
207
+		require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php');
208
+		require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php');
209
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
210
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
211
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
212
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
213
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
214
+		require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php');
215 215
 
216 216
 		// Register autoloader.
217 217
 		try {
218
-			spl_autoload_register( array( $this, 'autoload' ), true );
219
-		} catch ( Exception $e ) {
220
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
218
+			spl_autoload_register(array($this, 'autoload'), true);
219
+		} catch (Exception $e) {
220
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
221 221
 		}
222 222
 
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
235
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
236
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
237
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
238
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
239
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
240
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
241
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
242
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
243
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
223
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
224
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
225
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
226
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
227
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
228
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
229
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
230
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
231
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
232
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
233
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
234
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
235
+		require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
236
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
237
+		require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
238
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
239
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
240
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
241
+		require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
242
+		require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
243
+		require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
244 244
 
245 245
 		/**
246 246
 		 * Load the tax class.
247 247
 		 */
248
-		if ( ! class_exists( 'WPInv_EUVat' ) ) {
249
-			require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
248
+		if (!class_exists('WPInv_EUVat')) {
249
+			require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
250 250
 		}
251 251
 
252
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
252
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
253 253
 			GetPaid_Post_Types_Admin::init();
254 254
 
255
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
256
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
257
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
258
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
259
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
260
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
261
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
262
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
255
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
256
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
257
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
258
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
259
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
260
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
261
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
262
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
263 263
 			// load the user class only on the users.php page
264 264
 			global $pagenow;
265
-			if($pagenow=='users.php'){
265
+			if ($pagenow == 'users.php') {
266 266
 				new WPInv_Admin_Users();
267 267
 			}
268 268
 		}
269 269
 
270 270
 		// Register cli commands
271
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
272
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
273
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
271
+		if (defined('WP_CLI') && WP_CLI) {
272
+			require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
273
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
274 274
 		}
275 275
 
276
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
276
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
277 277
 	}
278 278
 
279 279
 	/**
@@ -284,21 +284,21 @@  discard block
 block discarded – undo
284 284
 	 * @since       1.0.19
285 285
 	 * @return      void
286 286
 	 */
287
-	public function autoload( $class_name ) {
287
+	public function autoload($class_name) {
288 288
 
289 289
 		// Normalize the class name...
290
-		$class_name  = strtolower( $class_name );
290
+		$class_name = strtolower($class_name);
291 291
 
292 292
 		// ... and make sure it is our class.
293
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
293
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
294 294
 			return;
295 295
 		}
296 296
 
297 297
 		// Next, prepare the file name from the class.
298
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
298
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
299 299
 
300 300
 		// Base path of the classes.
301
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
301
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
302 302
 
303 303
 		// And an array of possible locations in order of importance.
304 304
 		$locations = array(
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
 			"$plugin_path/includes/admin/meta-boxes",
312 312
 		);
313 313
 
314
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
314
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
315 315
 
316
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
317
-				include trailingslashit( $location ) . $file_name;
316
+			if (file_exists(trailingslashit($location) . $file_name)) {
317
+				include trailingslashit($location) . $file_name;
318 318
 				break;
319 319
 			}
320 320
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 	public function init() {
329 329
 
330 330
 		// Fires before getpaid inits.
331
-		do_action( 'before_getpaid_init', $this );
331
+		do_action('before_getpaid_init', $this);
332 332
 
333 333
 		// Load default gateways.
334 334
 		$gateways = apply_filters(
@@ -342,12 +342,12 @@  discard block
 block discarded – undo
342 342
 			)
343 343
 		);
344 344
 
345
-		foreach ( $gateways as $id => $class ) {
346
-			$this->gateways[ $id ] = new $class();
345
+		foreach ($gateways as $id => $class) {
346
+			$this->gateways[$id] = new $class();
347 347
 		}
348 348
 
349 349
 		// Fires after getpaid inits.
350
-		do_action( 'getpaid_init', $this );
350
+		do_action('getpaid_init', $this);
351 351
 
352 352
 	}
353 353
 
@@ -357,55 +357,55 @@  discard block
 block discarded – undo
357 357
 	public function maybe_process_ipn() {
358 358
 
359 359
 		// Ensure that this is an IPN request.
360
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
360
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
361 361
 			return;
362 362
 		}
363 363
 
364
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
364
+		$gateway = wpinv_clean($_GET['wpi-gateway']);
365 365
 
366
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
367
-		do_action( "wpinv_verify_{$gateway}_ipn" );
366
+		do_action('wpinv_verify_payment_ipn', $gateway);
367
+		do_action("wpinv_verify_{$gateway}_ipn");
368 368
 		exit;
369 369
 
370 370
 	}
371 371
 
372 372
 	public function enqueue_scripts() {
373
-		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
373
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
374 374
 
375
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
376
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
377
-		wp_enqueue_style( 'wpinv_front_style' );
375
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css');
376
+		wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version);
377
+		wp_enqueue_style('wpinv_front_style');
378 378
 
379 379
 		// Register scripts
380
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
381
-		wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
380
+		wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
381
+		wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
382 382
 
383 383
 		$localize                         = array();
384
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
385
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
386
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
384
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
385
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
386
+		$localize['txtComplete']          = __('Continue', 'invoicing');
387 387
 		$localize['UseTaxes']             = wpinv_use_taxes();
388
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
389
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
390
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
388
+		$localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
389
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
390
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
391 391
 
392
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
392
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
393 393
 
394
-		wp_enqueue_script( 'jquery-blockui' );
394
+		wp_enqueue_script('jquery-blockui');
395 395
 
396
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' );
397
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
396
+		wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all');
397
+		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
398 398
 
399
-		wp_enqueue_script( 'wpinv-front-script' );
400
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
399
+		wp_enqueue_script('wpinv-front-script');
400
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
401 401
 
402
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
403
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
402
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
403
+		wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true);
404 404
 	}
405 405
 
406 406
 	public function wpinv_actions() {
407
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
408
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
407
+		if (isset($_REQUEST['wpi_action'])) {
408
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
409 409
 		}
410 410
 	}
411 411
 
@@ -417,31 +417,31 @@  discard block
 block discarded – undo
417 417
      */
418 418
     public function maybe_do_authenticated_action() {
419 419
 
420
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
420
+		if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
421 421
 
422
-			$key = sanitize_key( $_REQUEST['getpaid-action'] );
423
-			if ( is_user_logged_in() ) {
424
-				do_action( "getpaid_authenticated_action_$key", $_REQUEST );
422
+			$key = sanitize_key($_REQUEST['getpaid-action']);
423
+			if (is_user_logged_in()) {
424
+				do_action("getpaid_authenticated_action_$key", $_REQUEST);
425 425
 			}
426 426
 
427
-			do_action( "getpaid_unauthenticated_action_$key", $_REQUEST );
427
+			do_action("getpaid_unauthenticated_action_$key", $_REQUEST);
428 428
 
429 429
 		}
430 430
         
431 431
 
432 432
     }
433 433
 
434
-	public function pre_get_posts( $wp_query ) {
434
+	public function pre_get_posts($wp_query) {
435 435
 
436
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
437
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
436
+		if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
437
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type']));
438 438
 		}
439 439
 
440 440
 		return $wp_query;
441 441
 	}
442 442
 
443 443
 	public function bp_invoicing_init() {
444
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
444
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
445 445
 	}
446 446
 
447 447
 	/**
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 			)
463 463
 		);
464 464
 
465
-		foreach ( $widgets as $widget ) {
466
-			register_widget( $widget );
465
+		foreach ($widgets as $widget) {
466
+			register_widget($widget);
467 467
 		}
468 468
 		
469 469
 	}
@@ -474,10 +474,10 @@  discard block
 block discarded – undo
474 474
 	 * @since 1.0.19
475 475
 	 * @param int[] $excluded_posts_ids
476 476
 	 */
477
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
477
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
478 478
 
479 479
 		// Ensure that we have an array.
480
-		if ( ! is_array( $excluded_posts_ids ) ) {
480
+		if (!is_array($excluded_posts_ids)) {
481 481
 			$excluded_posts_ids = array();
482 482
 		}
483 483
 
@@ -485,24 +485,24 @@  discard block
 block discarded – undo
485 485
 		$our_pages = array();
486 486
 
487 487
 		// Checkout page.
488
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
488
+		$our_pages[] = wpinv_get_option('checkout_page', false);
489 489
 
490 490
 		// Success page.
491
-		$our_pages[] = wpinv_get_option( 'success_page', false );
491
+		$our_pages[] = wpinv_get_option('success_page', false);
492 492
 
493 493
 		// Failure page.
494
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
494
+		$our_pages[] = wpinv_get_option('failure_page', false);
495 495
 
496 496
 		// History page.
497
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
497
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
498 498
 
499 499
 		// Subscriptions page.
500
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
500
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
501 501
 
502
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
502
+		$our_pages   = array_map('intval', array_filter($our_pages));
503 503
 
504 504
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
505
-		return array_unique( $excluded_posts_ids );
505
+		return array_unique($excluded_posts_ids);
506 506
 
507 507
 	}
508 508
 
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +389 added lines, -389 removed lines patch added patch discarded remove patch
@@ -12,443 +12,443 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		return array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-	}
151
-
152
-	/**
153
-	 * Helper function to send an email.
154
-	 *
155
-	 * @param WPInv_Invoice $invoice
156
-	 * @param GetPaid_Notification_Email $email
157
-	 * @param string $type
158
-	 * @param string|array $recipients
159
-	 * @param array $extra_args Extra template args.
160
-	 */
161
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
162
-
163
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
164
-
165
-		$mailer     = new GetPaid_Notification_Email_Sender();
166
-		$merge_tags = $email->get_merge_tags();
167
-
168
-		$result = $mailer->send(
169
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
170
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
171
-			$email->get_content( $merge_tags, $extra_args ),
172
-			$email->get_attachments()
173
-		);
174
-
175
-		// Maybe send a copy to the admin.
176
-		if ( $email->include_admin_bcc() ) {
177
-			$mailer->send(
178
-				wpinv_get_admin_email(),
179
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
180
-				$email->get_content( $merge_tags ),
181
-				$email->get_attachments()
182
-			);
183
-		}
184
-
185
-		if ( ! $result ) {
186
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
187
-		}
188
-
189
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
190
-
191
-		return $result;
192
-	}
193
-
194
-	/**
195
-	 * Also send emails to any cc users.
196
-	 *
197
-	 * @param array $recipients
198
-	 * @param GetPaid_Notification_Email $email
199
-	 */
200
-	public function filter_email_recipients( $recipients, $email ) {
201
-
202
-		if ( ! $email->is_admin_email() ) {
203
-			$cc = $email->object->get_email_cc();
204
-
205
-			if ( ! empty( $cc ) ) {
206
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
207
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
208
-			}
209
-
210
-		}
211
-
212
-		return $recipients;
213
-
214
-	}
215
-
216
-	/**
217
-	 * Sends a new invoice notification.
218
-	 *
219
-	 * @param WPInv_Invoice $invoice
220
-	 */
221
-	public function new_invoice( $invoice ) {
222
-
223
-		// Only send this email for invoices created via the admin page.
224
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
225
-			return;
226
-		}
227
-
228
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
229
-		$recipient = wpinv_get_admin_email();
230
-
231
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
232
-
233
-	}
234
-
235
-	/**
236
-	 * Sends a cancelled invoice notification.
237
-	 *
238
-	 * @param WPInv_Invoice $invoice
239
-	 */
240
-	public function cancelled_invoice( $invoice ) {
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        return array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+    }
151
+
152
+    /**
153
+     * Helper function to send an email.
154
+     *
155
+     * @param WPInv_Invoice $invoice
156
+     * @param GetPaid_Notification_Email $email
157
+     * @param string $type
158
+     * @param string|array $recipients
159
+     * @param array $extra_args Extra template args.
160
+     */
161
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
162
+
163
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
164
+
165
+        $mailer     = new GetPaid_Notification_Email_Sender();
166
+        $merge_tags = $email->get_merge_tags();
167
+
168
+        $result = $mailer->send(
169
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
170
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
171
+            $email->get_content( $merge_tags, $extra_args ),
172
+            $email->get_attachments()
173
+        );
174
+
175
+        // Maybe send a copy to the admin.
176
+        if ( $email->include_admin_bcc() ) {
177
+            $mailer->send(
178
+                wpinv_get_admin_email(),
179
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
180
+                $email->get_content( $merge_tags ),
181
+                $email->get_attachments()
182
+            );
183
+        }
184
+
185
+        if ( ! $result ) {
186
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
187
+        }
188
+
189
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
190
+
191
+        return $result;
192
+    }
193
+
194
+    /**
195
+     * Also send emails to any cc users.
196
+     *
197
+     * @param array $recipients
198
+     * @param GetPaid_Notification_Email $email
199
+     */
200
+    public function filter_email_recipients( $recipients, $email ) {
201
+
202
+        if ( ! $email->is_admin_email() ) {
203
+            $cc = $email->object->get_email_cc();
204
+
205
+            if ( ! empty( $cc ) ) {
206
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
207
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
208
+            }
209
+
210
+        }
211
+
212
+        return $recipients;
213
+
214
+    }
215
+
216
+    /**
217
+     * Sends a new invoice notification.
218
+     *
219
+     * @param WPInv_Invoice $invoice
220
+     */
221
+    public function new_invoice( $invoice ) {
222
+
223
+        // Only send this email for invoices created via the admin page.
224
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
225
+            return;
226
+        }
227
+
228
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
229
+        $recipient = wpinv_get_admin_email();
230
+
231
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
232
+
233
+    }
234
+
235
+    /**
236
+     * Sends a cancelled invoice notification.
237
+     *
238
+     * @param WPInv_Invoice $invoice
239
+     */
240
+    public function cancelled_invoice( $invoice ) {
241 241
 
242
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
243
-		$recipient = wpinv_get_admin_email();
242
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
243
+        $recipient = wpinv_get_admin_email();
244 244
 
245
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
245
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
246 246
 
247
-	}
247
+    }
248 248
 
249
-	/**
250
-	 * Sends a failed invoice notification.
251
-	 *
252
-	 * @param WPInv_Invoice $invoice
253
-	 */
254
-	public function failed_invoice( $invoice ) {
249
+    /**
250
+     * Sends a failed invoice notification.
251
+     *
252
+     * @param WPInv_Invoice $invoice
253
+     */
254
+    public function failed_invoice( $invoice ) {
255 255
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
257
-		$recipient = wpinv_get_admin_email();
256
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
257
+        $recipient = wpinv_get_admin_email();
258 258
 
259
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
259
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
260 260
 
261
-	}
261
+    }
262 262
 
263
-	/**
264
-	 * Sends a notification whenever an invoice is put on hold.
265
-	 *
266
-	 * @param WPInv_Invoice $invoice
267
-	 */
268
-	public function onhold_invoice( $invoice ) {
263
+    /**
264
+     * Sends a notification whenever an invoice is put on hold.
265
+     *
266
+     * @param WPInv_Invoice $invoice
267
+     */
268
+    public function onhold_invoice( $invoice ) {
269 269
 
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
-		$recipient = $invoice->get_email();
270
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+        $recipient = $invoice->get_email();
272 272
 
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
273
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274 274
 
275
-	}
275
+    }
276 276
 
277
-	/**
278
-	 * Sends a notification whenever an invoice is marked as processing payment.
279
-	 *
280
-	 * @param WPInv_Invoice $invoice
281
-	 */
282
-	public function processing_invoice( $invoice ) {
277
+    /**
278
+     * Sends a notification whenever an invoice is marked as processing payment.
279
+     *
280
+     * @param WPInv_Invoice $invoice
281
+     */
282
+    public function processing_invoice( $invoice ) {
283 283
 
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
-		$recipient = $invoice->get_email();
284
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+        $recipient = $invoice->get_email();
286 286
 
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288 288
 
289
-	}
289
+    }
290 290
 
291
-	/**
292
-	 * Sends a notification whenever an invoice is paid.
293
-	 *
294
-	 * @param WPInv_Invoice $invoice
295
-	 */
296
-	public function completed_invoice( $invoice ) {
291
+    /**
292
+     * Sends a notification whenever an invoice is paid.
293
+     *
294
+     * @param WPInv_Invoice $invoice
295
+     */
296
+    public function completed_invoice( $invoice ) {
297 297
 
298
-		// (Maybe) abort if it is a renewal invoice.
299
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
300
-			return;
301
-		}
298
+        // (Maybe) abort if it is a renewal invoice.
299
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
300
+            return;
301
+        }
302 302
 
303
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
304
-		$recipient = $invoice->get_email();
303
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
304
+        $recipient = $invoice->get_email();
305 305
 
306
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
306
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
307 307
 
308
-	}
308
+    }
309 309
 
310
-	/**
311
-	 * Sends a notification whenever an invoice is refunded.
312
-	 *
313
-	 * @param WPInv_Invoice $invoice
314
-	 */
315
-	public function refunded_invoice( $invoice ) {
310
+    /**
311
+     * Sends a notification whenever an invoice is refunded.
312
+     *
313
+     * @param WPInv_Invoice $invoice
314
+     */
315
+    public function refunded_invoice( $invoice ) {
316 316
 
317
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
318
-		$recipient = $invoice->get_email();
317
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
318
+        $recipient = $invoice->get_email();
319 319
 
320
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
320
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
321 321
 
322
-	}
322
+    }
323 323
 
324
-	/**
325
-	 * Notifies a user about new invoices
326
-	 *
327
-	 * @param WPInv_Invoice $invoice
328
-	 */
329
-	public function user_invoice( $invoice ) {
324
+    /**
325
+     * Notifies a user about new invoices
326
+     *
327
+     * @param WPInv_Invoice $invoice
328
+     */
329
+    public function user_invoice( $invoice ) {
330 330
 
331
-		// Only send this email for invoices created via the admin page.
332
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
333
-			return;
334
-		}
331
+        // Only send this email for invoices created via the admin page.
332
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
333
+            return;
334
+        }
335 335
 
336
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
337
-		$recipient = $invoice->get_email();
336
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
337
+        $recipient = $invoice->get_email();
338 338
 
339
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
339
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
340 340
 
341
-	}
341
+    }
342 342
 
343
-	/**
344
-	 * Checks if an invoice is a payment form invoice.
345
-	 *
346
-	 * @param int $invoice
347
-	 * @return bool
348
-	 */
349
-	public function is_payment_form_invoice( $invoice ) {
350
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
351
-	}
343
+    /**
344
+     * Checks if an invoice is a payment form invoice.
345
+     *
346
+     * @param int $invoice
347
+     * @return bool
348
+     */
349
+    public function is_payment_form_invoice( $invoice ) {
350
+        return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
351
+    }
352 352
 
353
-	/**
354
-	 * Notifies admin about new invoice notes
355
-	 *
356
-	 * @param WPInv_Invoice $invoice
357
-	 * @param string $note
358
-	 */
359
-	public function user_note( $invoice, $note ) {
353
+    /**
354
+     * Notifies admin about new invoice notes
355
+     *
356
+     * @param WPInv_Invoice $invoice
357
+     * @param string $note
358
+     */
359
+    public function user_note( $invoice, $note ) {
360 360
 
361
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
362
-		$recipient = $invoice->get_email();
363
-
364
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
365
-
366
-	}
361
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
362
+        $recipient = $invoice->get_email();
363
+
364
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
365
+
366
+    }
367 367
 
368
-	/**
369
-	 * (Force) Sends overdue notices.
370
-	 *
371
-	 * @param WPInv_Invoice $invoice
372
-	 */
373
-	public function force_send_overdue_notice( $invoice ) {
374
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
375
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
376
-	}
377
-
378
-	/**
379
-	 * Sends overdue notices.
380
-	 *
381
-	 * @TODO: Create an invoices query class.
382
-	 */
383
-	public function overdue() {
384
-		global $wpdb;
385
-
386
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
387
-
388
-		// Fetch reminder days.
389
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
390
-
391
-		// Abort if non is set.
392
-		if ( empty( $reminder_days ) ) {
393
-			return;
394
-		}
395
-
396
-		// Retrieve date query.
397
-		$date_query = $this->get_date_query( $reminder_days );
398
-
399
-		// Invoices table.
400
-		$table = $wpdb->prefix . 'getpaid_invoices';
401
-
402
-		// Fetch invoices.
403
-		$invoices  = $wpdb->get_col(
404
-			"SELECT posts.ID FROM $wpdb->posts as posts
368
+    /**
369
+     * (Force) Sends overdue notices.
370
+     *
371
+     * @param WPInv_Invoice $invoice
372
+     */
373
+    public function force_send_overdue_notice( $invoice ) {
374
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
375
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
376
+    }
377
+
378
+    /**
379
+     * Sends overdue notices.
380
+     *
381
+     * @TODO: Create an invoices query class.
382
+     */
383
+    public function overdue() {
384
+        global $wpdb;
385
+
386
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
387
+
388
+        // Fetch reminder days.
389
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
390
+
391
+        // Abort if non is set.
392
+        if ( empty( $reminder_days ) ) {
393
+            return;
394
+        }
395
+
396
+        // Retrieve date query.
397
+        $date_query = $this->get_date_query( $reminder_days );
398
+
399
+        // Invoices table.
400
+        $table = $wpdb->prefix . 'getpaid_invoices';
401
+
402
+        // Fetch invoices.
403
+        $invoices  = $wpdb->get_col(
404
+            "SELECT posts.ID FROM $wpdb->posts as posts
405 405
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
406 406
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
407 407
 
408
-		foreach ( $invoices as $invoice ) {
408
+        foreach ( $invoices as $invoice ) {
409 409
 
410
-			// Only send this email for invoices created via the admin page.
411
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
412
-				$invoice       = new WPInv_Invoice( $invoice );
413
-				$email->object = $invoice;
410
+            // Only send this email for invoices created via the admin page.
411
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
412
+                $invoice       = new WPInv_Invoice( $invoice );
413
+                $email->object = $invoice;
414 414
 
415
-				if ( $invoice->needs_payment() ) {
416
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
417
-				}
415
+                if ( $invoice->needs_payment() ) {
416
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
417
+                }
418 418
 
419
-			}
419
+            }
420 420
 
421
-		}
421
+        }
422 422
 
423
-	}
423
+    }
424 424
 
425
-	/**
426
-	 * Calculates the date query for an invoices query
427
-	 *
428
-	 * @param array $reminder_days
429
-	 * @return string
430
-	 */
431
-	public function get_date_query( $reminder_days ) {
425
+    /**
426
+     * Calculates the date query for an invoices query
427
+     *
428
+     * @param array $reminder_days
429
+     * @return string
430
+     */
431
+    public function get_date_query( $reminder_days ) {
432 432
 
433
-		$date_query = array(
434
-			'relation'  => 'OR'
435
-		);
433
+        $date_query = array(
434
+            'relation'  => 'OR'
435
+        );
436 436
 
437
-		foreach ( $reminder_days as $days ) {
438
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
437
+        foreach ( $reminder_days as $days ) {
438
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
439 439
 
440
-			$date_query[] = array(
441
-				'year'  => $date['year'],
442
-				'month' => $date['month'],
443
-				'day'   => $date['day'],
444
-			);
440
+            $date_query[] = array(
441
+                'year'  => $date['year'],
442
+                'month' => $date['month'],
443
+                'day'   => $date['day'],
444
+            );
445 445
 
446
-		}
446
+        }
447 447
 
448
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
448
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
449 449
 
450
-		return $date_query->get_sql();
450
+        return $date_query->get_sql();
451 451
 
452
-	}
452
+    }
453 453
 
454 454
 }
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,32 +119,32 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		return array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'           => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'          => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'           => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'               => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'      => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'    => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'       => wpinv_price(wpinv_format_amount($invoice->get_total())),
138
+			'{invoice_link}'        => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'    => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'        => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'    => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'       => sanitize_text_field($invoice->get_type()),
144
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_type())),
145
+			'{invoice_description}' => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'   => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'              => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150 150
 	}
@@ -158,35 +158,35 @@  discard block
 block discarded – undo
158 158
 	 * @param string|array $recipients
159 159
 	 * @param array $extra_args Extra template args.
160 160
 	 */
161
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
161
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
162 162
 
163
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
163
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
164 164
 
165 165
 		$mailer     = new GetPaid_Notification_Email_Sender();
166 166
 		$merge_tags = $email->get_merge_tags();
167 167
 
168 168
 		$result = $mailer->send(
169
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
170
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
171
-			$email->get_content( $merge_tags, $extra_args ),
169
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
170
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
171
+			$email->get_content($merge_tags, $extra_args),
172 172
 			$email->get_attachments()
173 173
 		);
174 174
 
175 175
 		// Maybe send a copy to the admin.
176
-		if ( $email->include_admin_bcc() ) {
176
+		if ($email->include_admin_bcc()) {
177 177
 			$mailer->send(
178 178
 				wpinv_get_admin_email(),
179
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
180
-				$email->get_content( $merge_tags ),
179
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
180
+				$email->get_content($merge_tags),
181 181
 				$email->get_attachments()
182 182
 			);
183 183
 		}
184 184
 
185
-		if ( ! $result ) {
186
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
185
+		if (!$result) {
186
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
187 187
 		}
188 188
 
189
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
189
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
190 190
 
191 191
 		return $result;
192 192
 	}
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 	 * @param array $recipients
198 198
 	 * @param GetPaid_Notification_Email $email
199 199
 	 */
200
-	public function filter_email_recipients( $recipients, $email ) {
200
+	public function filter_email_recipients($recipients, $email) {
201 201
 
202
-		if ( ! $email->is_admin_email() ) {
202
+		if (!$email->is_admin_email()) {
203 203
 			$cc = $email->object->get_email_cc();
204 204
 
205
-			if ( ! empty( $cc ) ) {
206
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
207
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
205
+			if (!empty($cc)) {
206
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
207
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
208 208
 			}
209 209
 
210 210
 		}
@@ -218,17 +218,17 @@  discard block
 block discarded – undo
218 218
 	 *
219 219
 	 * @param WPInv_Invoice $invoice
220 220
 	 */
221
-	public function new_invoice( $invoice ) {
221
+	public function new_invoice($invoice) {
222 222
 
223 223
 		// Only send this email for invoices created via the admin page.
224
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
224
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
225 225
 			return;
226 226
 		}
227 227
 
228
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
228
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
229 229
 		$recipient = wpinv_get_admin_email();
230 230
 
231
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
231
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
232 232
 
233 233
 	}
234 234
 
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @param WPInv_Invoice $invoice
239 239
 	 */
240
-	public function cancelled_invoice( $invoice ) {
240
+	public function cancelled_invoice($invoice) {
241 241
 
242
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
242
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
243 243
 		$recipient = wpinv_get_admin_email();
244 244
 
245
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
245
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
246 246
 
247 247
 	}
248 248
 
@@ -251,12 +251,12 @@  discard block
 block discarded – undo
251 251
 	 *
252 252
 	 * @param WPInv_Invoice $invoice
253 253
 	 */
254
-	public function failed_invoice( $invoice ) {
254
+	public function failed_invoice($invoice) {
255 255
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
256
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
257 257
 		$recipient = wpinv_get_admin_email();
258 258
 
259
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
259
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
260 260
 
261 261
 	}
262 262
 
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
 	 *
266 266
 	 * @param WPInv_Invoice $invoice
267 267
 	 */
268
-	public function onhold_invoice( $invoice ) {
268
+	public function onhold_invoice($invoice) {
269 269
 
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
270
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
271 271
 		$recipient = $invoice->get_email();
272 272
 
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
273
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
274 274
 
275 275
 	}
276 276
 
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @param WPInv_Invoice $invoice
281 281
 	 */
282
-	public function processing_invoice( $invoice ) {
282
+	public function processing_invoice($invoice) {
283 283
 
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
285 285
 		$recipient = $invoice->get_email();
286 286
 
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
288 288
 
289 289
 	}
290 290
 
@@ -293,17 +293,17 @@  discard block
 block discarded – undo
293 293
 	 *
294 294
 	 * @param WPInv_Invoice $invoice
295 295
 	 */
296
-	public function completed_invoice( $invoice ) {
296
+	public function completed_invoice($invoice) {
297 297
 
298 298
 		// (Maybe) abort if it is a renewal invoice.
299
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
299
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
300 300
 			return;
301 301
 		}
302 302
 
303
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
303
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
304 304
 		$recipient = $invoice->get_email();
305 305
 
306
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
306
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
307 307
 
308 308
 	}
309 309
 
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 	 *
313 313
 	 * @param WPInv_Invoice $invoice
314 314
 	 */
315
-	public function refunded_invoice( $invoice ) {
315
+	public function refunded_invoice($invoice) {
316 316
 
317
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
317
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
318 318
 		$recipient = $invoice->get_email();
319 319
 
320
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
320
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
321 321
 
322 322
 	}
323 323
 
@@ -326,17 +326,17 @@  discard block
 block discarded – undo
326 326
 	 *
327 327
 	 * @param WPInv_Invoice $invoice
328 328
 	 */
329
-	public function user_invoice( $invoice ) {
329
+	public function user_invoice($invoice) {
330 330
 
331 331
 		// Only send this email for invoices created via the admin page.
332
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
332
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
333 333
 			return;
334 334
 		}
335 335
 
336
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
336
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
337 337
 		$recipient = $invoice->get_email();
338 338
 
339
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
339
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
340 340
 
341 341
 	}
342 342
 
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
 	 * @param int $invoice
347 347
 	 * @return bool
348 348
 	 */
349
-	public function is_payment_form_invoice( $invoice ) {
350
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
349
+	public function is_payment_form_invoice($invoice) {
350
+		return empty($_GET['getpaid-admin-action']) && 'payment_form' == get_post_meta($invoice, 'wpinv_created_via', true);
351 351
 	}
352 352
 
353 353
 	/**
@@ -356,12 +356,12 @@  discard block
 block discarded – undo
356 356
 	 * @param WPInv_Invoice $invoice
357 357
 	 * @param string $note
358 358
 	 */
359
-	public function user_note( $invoice, $note ) {
359
+	public function user_note($invoice, $note) {
360 360
 
361
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
361
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
362 362
 		$recipient = $invoice->get_email();
363 363
 
364
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
364
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
365 365
 
366 366
 	}
367 367
 
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 	 *
371 371
 	 * @param WPInv_Invoice $invoice
372 372
 	 */
373
-	public function force_send_overdue_notice( $invoice ) {
374
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
375
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
373
+	public function force_send_overdue_notice($invoice) {
374
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
375
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
376 376
 	}
377 377
 
378 378
 	/**
@@ -383,37 +383,37 @@  discard block
 block discarded – undo
383 383
 	public function overdue() {
384 384
 		global $wpdb;
385 385
 
386
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
386
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
387 387
 
388 388
 		// Fetch reminder days.
389
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
389
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
390 390
 
391 391
 		// Abort if non is set.
392
-		if ( empty( $reminder_days ) ) {
392
+		if (empty($reminder_days)) {
393 393
 			return;
394 394
 		}
395 395
 
396 396
 		// Retrieve date query.
397
-		$date_query = $this->get_date_query( $reminder_days );
397
+		$date_query = $this->get_date_query($reminder_days);
398 398
 
399 399
 		// Invoices table.
400 400
 		$table = $wpdb->prefix . 'getpaid_invoices';
401 401
 
402 402
 		// Fetch invoices.
403
-		$invoices  = $wpdb->get_col(
403
+		$invoices = $wpdb->get_col(
404 404
 			"SELECT posts.ID FROM $wpdb->posts as posts
405 405
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
406 406
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
407 407
 
408
-		foreach ( $invoices as $invoice ) {
408
+		foreach ($invoices as $invoice) {
409 409
 
410 410
 			// Only send this email for invoices created via the admin page.
411
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
412
-				$invoice       = new WPInv_Invoice( $invoice );
411
+			if (!$this->is_payment_form_invoice($invoice)) {
412
+				$invoice       = new WPInv_Invoice($invoice);
413 413
 				$email->object = $invoice;
414 414
 
415
-				if ( $invoice->needs_payment() ) {
416
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
415
+				if ($invoice->needs_payment()) {
416
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
417 417
 				}
418 418
 
419 419
 			}
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
 	 * @param array $reminder_days
429 429
 	 * @return string
430 430
 	 */
431
-	public function get_date_query( $reminder_days ) {
431
+	public function get_date_query($reminder_days) {
432 432
 
433 433
 		$date_query = array(
434 434
 			'relation'  => 'OR'
435 435
 		);
436 436
 
437
-		foreach ( $reminder_days as $days ) {
438
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
437
+		foreach ($reminder_days as $days) {
438
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
439 439
 
440 440
 			$date_query[] = array(
441 441
 				'year'  => $date['year'],
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 
446 446
 		}
447 447
 
448
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
448
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
449 449
 
450 450
 		return $date_query->get_sql();
451 451
 
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -11,55 +11,55 @@  discard block
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
 
16 16
     // Update tables.
17
-    if ( ! get_option( 'getpaid_created_invoice_tables' ) ) {
17
+    if (!get_option('getpaid_created_invoice_tables')) {
18 18
         wpinv_v119_upgrades();
19
-        update_option( 'getpaid_created_invoice_tables', true );
19
+        update_option('getpaid_created_invoice_tables', true);
20 20
     }
21 21
 
22
-    if ( $wpi_version == WPINV_VERSION ) {
22
+    if ($wpi_version == WPINV_VERSION) {
23 23
         return;
24 24
     }
25 25
 
26
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
26
+    if (version_compare($wpi_version, '0.0.5', '<')) {
27 27
         wpinv_v005_upgrades();
28 28
     }
29 29
 
30
-    if ( version_compare( $wpi_version, '1.0.3', '<' ) ) {
30
+    if (version_compare($wpi_version, '1.0.3', '<')) {
31 31
         wpinv_v110_upgrades();
32 32
     }
33 33
 
34
-    update_option( 'wpinv_version', WPINV_VERSION );
34
+    update_option('wpinv_version', WPINV_VERSION);
35 35
 }
36
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
36
+add_action('admin_init', 'wpinv_automatic_upgrade');
37 37
 
38 38
 function wpinv_v005_upgrades() {
39 39
     global $wpdb;
40 40
 
41 41
     // Invoices status
42
-    $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' )" );
43
-    if ( !empty( $results ) ) {
44
-        $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' )" );
42
+    $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' )");
43
+    if (!empty($results)) {
44
+        $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' )");
45 45
 
46 46
         // Clean post cache
47
-        foreach ( $results as $row ) {
48
-            clean_post_cache( $row->ID );
47
+        foreach ($results as $row) {
48
+            clean_post_cache($row->ID);
49 49
         }
50 50
     }
51 51
 
52 52
     // Item meta key changes
53 53
     $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' )";
54
-    $results = $wpdb->get_results( $query );
54
+    $results = $wpdb->get_results($query);
55 55
 
56
-    if ( !empty( $results ) ) {
57
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
58
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
59
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
56
+    if (!empty($results)) {
57
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
58
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
59
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
60 60
         
61
-        foreach ( $results as $row ) {
62
-            clean_post_cache( $row->post_id );
61
+        foreach ($results as $row) {
62
+            clean_post_cache($row->post_id);
63 63
         }
64 64
     }
65 65
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 function wpinv_create_invoices_table() {
89 89
     global $wpdb;
90 90
 
91
-    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
91
+    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
92 92
 
93 93
     // Create invoices table.
94 94
     $table = $wpdb->prefix . 'getpaid_invoices';
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             KEY `key` ( `key` )
133 133
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
134 134
 
135
-    dbDelta( $sql );
135
+    dbDelta($sql);
136 136
 
137 137
     // Create invoice items table.
138 138
     $table = $wpdb->prefix . 'getpaid_invoice_items';
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             KEY post_id ( post_id )
161 161
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
162 162
 
163
-    dbDelta( $sql );
163
+    dbDelta($sql);
164 164
 }
165 165
 
166 166
 /**
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
     $invoices = array_unique(
173 173
         get_posts(
174 174
             array(
175
-                'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
175
+                'post_type'      => array('wpi_invoice', 'wpi_quote'),
176 176
                 'posts_per_page' => -1,
177 177
                 'fields'         => 'ids',
178
-                'post_status'    => array_keys( get_post_stati() ),
178
+                'post_status'    => array_keys(get_post_stati()),
179 179
             )
180 180
         )
181 181
     );
@@ -183,19 +183,19 @@  discard block
 block discarded – undo
183 183
     $invoices_table = $wpdb->prefix . 'getpaid_invoices';
184 184
     $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
185 185
 
186
-    if ( ! class_exists( 'WPInv_Legacy_Invoice' ) ) {
187
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
186
+    if (!class_exists('WPInv_Legacy_Invoice')) {
187
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php');
188 188
     }
189 189
 
190 190
     $invoice_rows = array();
191
-    foreach ( $invoices as $invoice ) {
191
+    foreach ($invoices as $invoice) {
192 192
 
193
-        $invoice = new WPInv_Legacy_Invoice( $invoice );
194
-        $fields = array (
193
+        $invoice = new WPInv_Legacy_Invoice($invoice);
194
+        $fields = array(
195 195
             'post_id'        => $invoice->ID,
196 196
             'number'         => $invoice->get_number(),
197 197
             'key'            => $invoice->get_key(),
198
-            'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
198
+            'type'           => str_replace('wpi_', '', $invoice->post_type),
199 199
             'mode'           => $invoice->mode,
200 200
             'user_ip'        => $invoice->get_ip(),
201 201
             'first_name'     => $invoice->get_first_name(),
@@ -224,27 +224,27 @@  discard block
 block discarded – undo
224 224
             'custom_meta'    => $invoice->payment_meta
225 225
         );
226 226
 
227
-        foreach ( $fields as $key => $val ) {
228
-            if ( is_null( $val ) ) {
227
+        foreach ($fields as $key => $val) {
228
+            if (is_null($val)) {
229 229
                 $val = '';
230 230
             }
231
-            $val = maybe_serialize( $val );
232
-            $fields[ $key ] = $wpdb->prepare( '%s', $val );
231
+            $val = maybe_serialize($val);
232
+            $fields[$key] = $wpdb->prepare('%s', $val);
233 233
         }
234 234
 
235
-        $fields = implode( ', ', $fields );
235
+        $fields = implode(', ', $fields);
236 236
         $invoice_rows[] = "($fields)";
237 237
 
238 238
         $item_rows    = array();
239 239
         $item_columns = array();
240
-        foreach ( $invoice->get_cart_details() as $details ) {
240
+        foreach ($invoice->get_cart_details() as $details) {
241 241
             $fields = array(
242 242
                 'post_id'          => $invoice->ID,
243 243
                 'item_id'          => $details['id'],
244 244
                 'item_name'        => $details['name'],
245
-                'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
245
+                'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
246 246
                 'vat_rate'         => $details['vat_rate'],
247
-                'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
247
+                'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
248 248
                 'tax'              => $details['tax'],
249 249
                 'item_price'       => $details['item_price'],
250 250
                 'custom_price'     => $details['custom_price'],
@@ -256,26 +256,26 @@  discard block
 block discarded – undo
256 256
                 'fees'             => $details['fees'],
257 257
             );
258 258
 
259
-            $item_columns = array_keys ( $fields );
259
+            $item_columns = array_keys($fields);
260 260
 
261
-            foreach ( $fields as $key => $val ) {
262
-                if ( is_null( $val ) ) {
261
+            foreach ($fields as $key => $val) {
262
+                if (is_null($val)) {
263 263
                     $val = '';
264 264
                 }
265
-                $val = maybe_serialize( $val );
266
-                $fields[ $key ] = $wpdb->prepare( '%s', $val );
265
+                $val = maybe_serialize($val);
266
+                $fields[$key] = $wpdb->prepare('%s', $val);
267 267
             }
268 268
 
269
-            $fields = implode( ', ', $fields );
269
+            $fields = implode(', ', $fields);
270 270
             $item_rows[] = "($fields)";
271 271
         }
272 272
 
273
-        $item_rows    = implode( ', ', $item_rows );
274
-        $item_columns = implode( ', ', $item_columns );
275
-        $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
273
+        $item_rows    = implode(', ', $item_rows);
274
+        $item_columns = implode(', ', $item_columns);
275
+        $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
276 276
     }
277 277
 
278
-    $invoice_rows = implode( ', ', $invoice_rows );
279
-    $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
278
+    $invoice_rows = implode(', ', $invoice_rows);
279
+    $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
280 280
 
281 281
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 2 patches
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -12,234 +12,234 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
15
+    /**
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
21 21
 
22 22
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-		global $wpinv_euvat;
45
-
46
-		// For invoices...
47
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
-			$invoice = new WPInv_Invoice( $post );
49
-
50
-			// Resend invoice.
51
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
52
-
53
-				add_meta_box(
54
-					'wpinv-mb-resend-invoice',
55
-					sprintf(
56
-						__( 'Resend %s', 'invoicing' ),
57
-						ucfirst( $invoice->get_type() )
58
-					),
59
-					'GetPaid_Meta_Box_Resend_Invoice::output',
60
-					$post_type,
61
-					'side',
62
-					'low'
63
-				);
64
-
65
-			}
66
-
67
-			// Subscriptions.
68
-			$subscription = getpaid_get_invoice_subscription( $invoice );
69
-			if ( ! empty( $subscription ) ) {
70
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
72
-			}
73
-
74
-			// Invoice details.
75
-			add_meta_box(
76
-				'wpinv-details',
77
-				sprintf(
78
-					__( '%s Details', 'invoicing' ),
79
-					ucfirst( $invoice->get_type() )
80
-				),
81
-				'GetPaid_Meta_Box_Invoice_Details::output',
82
-				$post_type,
83
-				'side'
84
-			);
85
-
86
-			// Payment details.
87
-			if ( ! $invoice->is_draft() ) {
88
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
89
-			}
90
-
91
-			// Billing details.
92
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
26
+
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
+
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
+
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
+
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
39
+
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
44
+        global $wpinv_euvat;
45
+
46
+        // For invoices...
47
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
+            $invoice = new WPInv_Invoice( $post );
49
+
50
+            // Resend invoice.
51
+            if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
52
+
53
+                add_meta_box(
54
+                    'wpinv-mb-resend-invoice',
55
+                    sprintf(
56
+                        __( 'Resend %s', 'invoicing' ),
57
+                        ucfirst( $invoice->get_type() )
58
+                    ),
59
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
60
+                    $post_type,
61
+                    'side',
62
+                    'low'
63
+                );
64
+
65
+            }
66
+
67
+            // Subscriptions.
68
+            $subscription = getpaid_get_invoice_subscription( $invoice );
69
+            if ( ! empty( $subscription ) ) {
70
+                add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
+                add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
72
+            }
73
+
74
+            // Invoice details.
75
+            add_meta_box(
76
+                'wpinv-details',
77
+                sprintf(
78
+                    __( '%s Details', 'invoicing' ),
79
+                    ucfirst( $invoice->get_type() )
80
+                ),
81
+                'GetPaid_Meta_Box_Invoice_Details::output',
82
+                $post_type,
83
+                'side'
84
+            );
85
+
86
+            // Payment details.
87
+            if ( ! $invoice->is_draft() ) {
88
+                add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
89
+            }
90
+
91
+            // Billing details.
92
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
93 93
 			
94
-			// Invoice items.
95
-			add_meta_box(
96
-				'wpinv-items',
97
-				sprintf(
98
-					__( '%s Items', 'invoicing' ),
99
-					ucfirst( $invoice->get_type() )
100
-				),
101
-				'GetPaid_Meta_Box_Invoice_Items::output',
102
-				$post_type,
103
-				'normal',
104
-				'high'
105
-			);
94
+            // Invoice items.
95
+            add_meta_box(
96
+                'wpinv-items',
97
+                sprintf(
98
+                    __( '%s Items', 'invoicing' ),
99
+                    ucfirst( $invoice->get_type() )
100
+                ),
101
+                'GetPaid_Meta_Box_Invoice_Items::output',
102
+                $post_type,
103
+                'normal',
104
+                'high'
105
+            );
106 106
 			
107
-			// Invoice notes.
108
-			add_meta_box(
109
-				'wpinv-notes',
110
-				sprintf(
111
-					__( '%s Notes', 'invoicing' ),
112
-					ucfirst( $invoice->get_type() )
113
-				),
114
-				'WPInv_Meta_Box_Notes::output',
115
-				$post_type,
116
-				'side',
117
-				'low'
118
-			);
119
-
120
-			// Payment form information.
121
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
122
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
123
-			}
124
-		}
125
-
126
-		// For payment forms.
127
-		if ( $post_type == 'wpi_payment_form' ) {
128
-
129
-			// Design payment form.
130
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
131
-
132
-			// Payment form information.
133
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
134
-
135
-		}
136
-
137
-		// For invoice items.
138
-		if ( $post_type == 'wpi_item' ) {
139
-
140
-			// Item details.
141
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
142
-
143
-			// If taxes are enabled, register the tax metabox.
144
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
145
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
146
-			}
147
-
148
-			// Item info.
149
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
150
-
151
-		}
152
-
153
-		// For invoice discounts.
154
-		if ( $post_type == 'wpi_discount' ) {
155
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
156
-		}
107
+            // Invoice notes.
108
+            add_meta_box(
109
+                'wpinv-notes',
110
+                sprintf(
111
+                    __( '%s Notes', 'invoicing' ),
112
+                    ucfirst( $invoice->get_type() )
113
+                ),
114
+                'WPInv_Meta_Box_Notes::output',
115
+                $post_type,
116
+                'side',
117
+                'low'
118
+            );
119
+
120
+            // Payment form information.
121
+            if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
122
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
123
+            }
124
+        }
125
+
126
+        // For payment forms.
127
+        if ( $post_type == 'wpi_payment_form' ) {
128
+
129
+            // Design payment form.
130
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
131
+
132
+            // Payment form information.
133
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
134
+
135
+        }
136
+
137
+        // For invoice items.
138
+        if ( $post_type == 'wpi_item' ) {
139
+
140
+            // Item details.
141
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
142
+
143
+            // If taxes are enabled, register the tax metabox.
144
+            if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
145
+                add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
146
+            }
147
+
148
+            // Item info.
149
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
150
+
151
+        }
152
+
153
+        // For invoice discounts.
154
+        if ( $post_type == 'wpi_discount' ) {
155
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
156
+        }
157 157
 		
158 158
 
159
-	}
159
+    }
160 160
 
161
-	/**
162
-	 * Remove some metaboxes.
163
-	 */
164
-	public static function remove_meta_boxes() {
165
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
166
-	}
161
+    /**
162
+     * Remove some metaboxes.
163
+     */
164
+    public static function remove_meta_boxes() {
165
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
166
+    }
167 167
 
168
-	/**
169
-	 * Rename other metaboxes.
170
-	 */
171
-	public static function rename_meta_boxes() {
168
+    /**
169
+     * Rename other metaboxes.
170
+     */
171
+    public static function rename_meta_boxes() {
172 172
 		
173
-	}
174
-
175
-	/**
176
-	 * Check if we're saving, then trigger an action based on the post type.
177
-	 *
178
-	 * @param  int    $post_id Post ID.
179
-	 * @param  object $post Post object.
180
-	 */
181
-	public static function save_meta_boxes( $post_id, $post ) {
182
-		$post_id = absint( $post_id );
183
-		$data    = wp_unslash( $_POST );
184
-
185
-		// Do not save for ajax requests.
186
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
187
-			return;
188
-		}
189
-
190
-		// $post_id and $post are required
191
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
192
-			return;
193
-		}
194
-
195
-		// Dont' save meta boxes for revisions or autosaves.
196
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
197
-			return;
198
-		}
199
-
200
-		// Check the nonce.
201
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
202
-			return;
203
-		}
204
-
205
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
206
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
207
-			return;
208
-		}
209
-
210
-		// Check user has permission to edit.
211
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
212
-			return;
213
-		}
214
-
215
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
216
-
217
-			// We need this save event to run once to avoid potential endless loops.
218
-			self::$saved_meta_boxes = true;
219
-
220
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
221
-
222
-		}
223
-
224
-		// Ensure this is our post type.
225
-		$post_types_map = array(
226
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
227
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
228
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
229
-		);
230
-
231
-		// Is this our post type?
232
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
233
-			return;
234
-		}
235
-
236
-		// We need this save event to run once to avoid potential endless loops.
237
-		self::$saved_meta_boxes = true;
173
+    }
174
+
175
+    /**
176
+     * Check if we're saving, then trigger an action based on the post type.
177
+     *
178
+     * @param  int    $post_id Post ID.
179
+     * @param  object $post Post object.
180
+     */
181
+    public static function save_meta_boxes( $post_id, $post ) {
182
+        $post_id = absint( $post_id );
183
+        $data    = wp_unslash( $_POST );
184
+
185
+        // Do not save for ajax requests.
186
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
187
+            return;
188
+        }
189
+
190
+        // $post_id and $post are required
191
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
192
+            return;
193
+        }
194
+
195
+        // Dont' save meta boxes for revisions or autosaves.
196
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
197
+            return;
198
+        }
199
+
200
+        // Check the nonce.
201
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
202
+            return;
203
+        }
204
+
205
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
206
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
207
+            return;
208
+        }
209
+
210
+        // Check user has permission to edit.
211
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
212
+            return;
213
+        }
214
+
215
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
216
+
217
+            // We need this save event to run once to avoid potential endless loops.
218
+            self::$saved_meta_boxes = true;
219
+
220
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
221
+
222
+        }
223
+
224
+        // Ensure this is our post type.
225
+        $post_types_map = array(
226
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
227
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
228
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
229
+        );
230
+
231
+        // Is this our post type?
232
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
233
+            return;
234
+        }
235
+
236
+        // We need this save event to run once to avoid potential endless loops.
237
+        self::$saved_meta_boxes = true;
238 238
 		
239
-		// Save the post.
240
-		$class = $post_types_map[ $post->post_type ];
241
-		$class::save( $post_id, $_POST, $post );
239
+        // Save the post.
240
+        $class = $post_types_map[ $post->post_type ];
241
+        $class::save( $post_id, $_POST, $post );
242 242
 
243
-	}
243
+    }
244 244
 
245 245
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Metaboxes Admin Class
@@ -25,36 +25,36 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 		global $wpinv_euvat;
45 45
 
46 46
 		// For invoices...
47
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
-			$invoice = new WPInv_Invoice( $post );
47
+		if (getpaid_is_invoice_post_type($post_type)) {
48
+			$invoice = new WPInv_Invoice($post);
49 49
 
50 50
 			// Resend invoice.
51
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
51
+			if (!$invoice->is_draft() && !$invoice->is_paid()) {
52 52
 
53 53
 				add_meta_box(
54 54
 					'wpinv-mb-resend-invoice',
55 55
 					sprintf(
56
-						__( 'Resend %s', 'invoicing' ),
57
-						ucfirst( $invoice->get_type() )
56
+						__('Resend %s', 'invoicing'),
57
+						ucfirst($invoice->get_type())
58 58
 					),
59 59
 					'GetPaid_Meta_Box_Resend_Invoice::output',
60 60
 					$post_type,
@@ -65,18 +65,18 @@  discard block
 block discarded – undo
65 65
 			}
66 66
 
67 67
 			// Subscriptions.
68
-			$subscription = getpaid_get_invoice_subscription( $invoice );
69
-			if ( ! empty( $subscription ) ) {
70
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
68
+			$subscription = getpaid_get_invoice_subscription($invoice);
69
+			if (!empty($subscription)) {
70
+				add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced');
71
+				add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced');
72 72
 			}
73 73
 
74 74
 			// Invoice details.
75 75
 			add_meta_box(
76 76
 				'wpinv-details',
77 77
 				sprintf(
78
-					__( '%s Details', 'invoicing' ),
79
-					ucfirst( $invoice->get_type() )
78
+					__('%s Details', 'invoicing'),
79
+					ucfirst($invoice->get_type())
80 80
 				),
81 81
 				'GetPaid_Meta_Box_Invoice_Details::output',
82 82
 				$post_type,
@@ -84,19 +84,19 @@  discard block
 block discarded – undo
84 84
 			);
85 85
 
86 86
 			// Payment details.
87
-			if ( ! $invoice->is_draft() ) {
88
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
87
+			if (!$invoice->is_draft()) {
88
+				add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default');
89 89
 			}
90 90
 
91 91
 			// Billing details.
92
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
92
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high');
93 93
 			
94 94
 			// Invoice items.
95 95
 			add_meta_box(
96 96
 				'wpinv-items',
97 97
 				sprintf(
98
-					__( '%s Items', 'invoicing' ),
99
-					ucfirst( $invoice->get_type() )
98
+					__('%s Items', 'invoicing'),
99
+					ucfirst($invoice->get_type())
100 100
 				),
101 101
 				'GetPaid_Meta_Box_Invoice_Items::output',
102 102
 				$post_type,
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 			add_meta_box(
109 109
 				'wpinv-notes',
110 110
 				sprintf(
111
-					__( '%s Notes', 'invoicing' ),
112
-					ucfirst( $invoice->get_type() )
111
+					__('%s Notes', 'invoicing'),
112
+					ucfirst($invoice->get_type())
113 113
 				),
114 114
 				'WPInv_Meta_Box_Notes::output',
115 115
 				$post_type,
@@ -118,41 +118,41 @@  discard block
 block discarded – undo
118 118
 			);
119 119
 
120 120
 			// Payment form information.
121
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
122
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
121
+			if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) {
122
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high');
123 123
 			}
124 124
 		}
125 125
 
126 126
 		// For payment forms.
127
-		if ( $post_type == 'wpi_payment_form' ) {
127
+		if ($post_type == 'wpi_payment_form') {
128 128
 
129 129
 			// Design payment form.
130
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
130
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
131 131
 
132 132
 			// Payment form information.
133
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
133
+			add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
134 134
 
135 135
 		}
136 136
 
137 137
 		// For invoice items.
138
-		if ( $post_type == 'wpi_item' ) {
138
+		if ($post_type == 'wpi_item') {
139 139
 
140 140
 			// Item details.
141
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
141
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
142 142
 
143 143
 			// If taxes are enabled, register the tax metabox.
144
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
145
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
144
+			if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) {
145
+				add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
146 146
 			}
147 147
 
148 148
 			// Item info.
149
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
149
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
150 150
 
151 151
 		}
152 152
 
153 153
 		// For invoice discounts.
154
-		if ( $post_type == 'wpi_discount' ) {
155
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
154
+		if ($post_type == 'wpi_discount') {
155
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
156 156
 		}
157 157
 		
158 158
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * Remove some metaboxes.
163 163
 	 */
164 164
 	public static function remove_meta_boxes() {
165
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
165
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
166 166
 	}
167 167
 
168 168
 	/**
@@ -178,46 +178,46 @@  discard block
 block discarded – undo
178 178
 	 * @param  int    $post_id Post ID.
179 179
 	 * @param  object $post Post object.
180 180
 	 */
181
-	public static function save_meta_boxes( $post_id, $post ) {
182
-		$post_id = absint( $post_id );
183
-		$data    = wp_unslash( $_POST );
181
+	public static function save_meta_boxes($post_id, $post) {
182
+		$post_id = absint($post_id);
183
+		$data    = wp_unslash($_POST);
184 184
 
185 185
 		// Do not save for ajax requests.
186
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
186
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
187 187
 			return;
188 188
 		}
189 189
 
190 190
 		// $post_id and $post are required
191
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
191
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
192 192
 			return;
193 193
 		}
194 194
 
195 195
 		// Dont' save meta boxes for revisions or autosaves.
196
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
196
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
197 197
 			return;
198 198
 		}
199 199
 
200 200
 		// Check the nonce.
201
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
201
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
202 202
 			return;
203 203
 		}
204 204
 
205 205
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
206
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
206
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
207 207
 			return;
208 208
 		}
209 209
 
210 210
 		// Check user has permission to edit.
211
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
211
+		if (!current_user_can('edit_post', $post_id)) {
212 212
 			return;
213 213
 		}
214 214
 
215
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
215
+		if (getpaid_is_invoice_post_type($post->post_type)) {
216 216
 
217 217
 			// We need this save event to run once to avoid potential endless loops.
218 218
 			self::$saved_meta_boxes = true;
219 219
 
220
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
220
+			return GetPaid_Meta_Box_Invoice_Address::save($post_id);
221 221
 
222 222
 		}
223 223
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		);
230 230
 
231 231
 		// Is this our post type?
232
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
232
+		if (!isset($post_types_map[$post->post_type])) {
233 233
 			return;
234 234
 		}
235 235
 
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 		self::$saved_meta_boxes = true;
238 238
 		
239 239
 		// Save the post.
240
-		$class = $post_types_map[ $post->post_type ];
241
-		$class::save( $post_id, $_POST, $post );
240
+		$class = $post_types_map[$post->post_type];
241
+		$class::save($post_id, $_POST, $post);
242 242
 
243 243
 	}
244 244
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 2 patches
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -14,62 +14,62 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28 28
     public $admin_url;
29 29
 
30 30
     /**
31
-	 * Class constructor.
32
-	 */
33
-	public function __construct(){
31
+     * Class constructor.
32
+     */
33
+    public function __construct(){
34 34
 
35 35
         $this->admin_path  = plugin_dir_path( __FILE__ );
36 36
         $this->admin_url   = plugins_url( '/', __FILE__ );
37 37
 
38 38
         if ( is_admin() ) {
39
-			$this->init_admin_hooks();
39
+            $this->init_admin_hooks();
40 40
         }
41 41
 
42 42
     }
43 43
 
44 44
     /**
45
-	 * Init action and filter hooks
46
-	 *
47
-	 */
48
-	private function init_admin_hooks() {
45
+     * Init action and filter hooks
46
+     *
47
+     */
48
+    private function init_admin_hooks() {
49 49
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50 50
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51 51
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52 52
         add_action( 'admin_init', array( $this, 'activation_redirect') );
53 53
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
54
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
+        do_action( 'getpaid_init_admin_hooks', $this );
58 58
 
59 59
     }
60 60
 
61 61
     /**
62
-	 * Register admin scripts
63
-	 *
64
-	 */
65
-	public function enqeue_scripts() {
62
+     * Register admin scripts
63
+     *
64
+     */
65
+    public function enqeue_scripts() {
66 66
         global $current_screen, $pagenow;
67 67
 
68
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
69
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
68
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
69
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
70 70
 
71 71
         if ( ! empty( $current_screen->post_type ) ) {
72
-			$page = $current_screen->post_type;
72
+            $page = $current_screen->post_type;
73 73
         }
74 74
 
75 75
         // General styles.
@@ -93,30 +93,30 @@  discard block
 block discarded – undo
93 93
         }
94 94
 
95 95
         // Payment form scripts.
96
-		if ( 'wpi_payment_form' == $page && $editing ) {
96
+        if ( 'wpi_payment_form' == $page && $editing ) {
97 97
             $this->load_payment_form_scripts();
98 98
         }
99 99
 
100 100
         if ( $page == 'wpinv-subscriptions' ) {
101
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
103
-		}
101
+            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
+            wp_enqueue_script( 'wpinv-sub-admin-script' );
103
+        }
104 104
 
105
-		if ( $page == 'wpinv-reports' ) {
106
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
107
-		}
105
+        if ( $page == 'wpinv-reports' ) {
106
+            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
107
+        }
108 108
 
109
-		if ( $page == 'wpinv-subscriptions' ) {
110
-			wp_enqueue_script( 'postbox' );
111
-		}
109
+        if ( $page == 'wpinv-subscriptions' ) {
110
+            wp_enqueue_script( 'postbox' );
111
+        }
112 112
 
113 113
     }
114 114
 
115 115
     /**
116
-	 * Returns admin js translations.
117
-	 *
118
-	 */
119
-	protected function get_admin_i18() {
116
+     * Returns admin js translations.
117
+     *
118
+     */
119
+    protected function get_admin_i18() {
120 120
         global $post;
121 121
 
122 122
         $i18n = array(
@@ -152,50 +152,50 @@  discard block
 block discarded – undo
152 152
             'searching'                 => __( 'Searching', 'invoicing' ),
153 153
         );
154 154
 
155
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
155
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
156 156
 
157
-			$invoice              = new WPInv_Invoice( $post );
158
-			$i18n['save_invoice'] = sprintf(
159
-				__( 'Save %s', 'invoicing' ),
160
-				ucfirst( $invoice->get_type() )
161
-			);
157
+            $invoice              = new WPInv_Invoice( $post );
158
+            $i18n['save_invoice'] = sprintf(
159
+                __( 'Save %s', 'invoicing' ),
160
+                ucfirst( $invoice->get_type() )
161
+            );
162 162
 
163
-			$i18n['invoice_description'] = sprintf(
164
-				__( '%s Description', 'invoicing' ),
165
-				ucfirst( $invoice->get_type() )
166
-			);
163
+            $i18n['invoice_description'] = sprintf(
164
+                __( '%s Description', 'invoicing' ),
165
+                ucfirst( $invoice->get_type() )
166
+            );
167 167
 
168
-		}
169
-		return $i18n;
168
+        }
169
+        return $i18n;
170 170
     }
171 171
 
172 172
     /**
173
-	 * Loads payment form js.
174
-	 *
175
-	 */
176
-	protected function load_payment_form_scripts() {
173
+     * Loads payment form js.
174
+     *
175
+     */
176
+    protected function load_payment_form_scripts() {
177 177
         global $post;
178 178
 
179 179
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
180
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
181
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
180
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
181
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
182 182
 
183
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
184
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
183
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
184
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
185 185
 
186
-		wp_localize_script(
186
+        wp_localize_script(
187 187
             'wpinv-admin-payment-form-script',
188 188
             'wpinvPaymentFormAdmin',
189 189
             array(
190
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
191
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
192
-				'currency'      => wpinv_currency_symbol(),
193
-				'position'      => wpinv_currency_position(),
194
-				'decimals'      => (int) wpinv_decimals(),
195
-				'thousands_sep' => wpinv_thousands_separator(),
196
-				'decimals_sep'  => wpinv_decimal_separator(),
197
-				'form_items'    => gepaid_get_form_items( $post->ID ),
198
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
190
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
191
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
192
+                'currency'      => wpinv_currency_symbol(),
193
+                'position'      => wpinv_currency_position(),
194
+                'decimals'      => (int) wpinv_decimals(),
195
+                'thousands_sep' => wpinv_thousands_separator(),
196
+                'decimals_sep'  => wpinv_decimal_separator(),
197
+                'form_items'    => gepaid_get_form_items( $post->ID ),
198
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
199 199
             )
200 200
         );
201 201
 
@@ -204,20 +204,20 @@  discard block
 block discarded – undo
204 204
     }
205 205
 
206 206
     /**
207
-	 * Add our classes to admin pages.
207
+     * Add our classes to admin pages.
208 208
      *
209 209
      * @param string $classes
210 210
      * @return string
211
-	 *
212
-	 */
211
+     *
212
+     */
213 213
     public function admin_body_class( $classes ) {
214
-		global $pagenow, $post, $current_screen;
214
+        global $pagenow, $post, $current_screen;
215 215
 
216 216
 
217 217
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
218 218
 
219 219
         if ( ! empty( $current_screen->post_type ) ) {
220
-			$page = $current_screen->post_type;
220
+            $page = $current_screen->post_type;
221 221
         }
222 222
 
223 223
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -226,33 +226,33 @@  discard block
 block discarded – undo
226 226
 
227 227
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
228 228
             $classes .= ' wpinv-cpt wpinv';
229
-		}
229
+        }
230 230
 		
231
-		if ( getpaid_is_invoice_post_type( $page ) ) {
231
+        if ( getpaid_is_invoice_post_type( $page ) ) {
232 232
             $classes .= ' getpaid-is-invoice-cpt';
233 233
         }
234 234
 
235
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
236
-			$classes .= ' wpi-editable-n';
237
-		}
235
+        if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
236
+            $classes .= ' wpi-editable-n';
237
+        }
238 238
 
239
-		return $classes;
239
+        return $classes;
240 240
     }
241 241
 
242 242
     /**
243
-	 * Maybe show the AyeCode Connect Notice.
244
-	 */
245
-	public function init_ayecode_connect_helper(){
243
+     * Maybe show the AyeCode Connect Notice.
244
+     */
245
+    public function init_ayecode_connect_helper(){
246 246
 
247 247
         new AyeCode_Connect_Helper(
248 248
             array(
249
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
250
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
251
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
252
-				'connect_button'    => __("Connect Site","invoicing"),
253
-				'connecting_button'    => __("Connecting...","invoicing"),
254
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
255
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
249
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
250
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
251
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
252
+                'connect_button'    => __("Connect Site","invoicing"),
253
+                'connecting_button'    => __("Connecting...","invoicing"),
254
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
255
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
256 256
             ),
257 257
             array( 'wpi-addons' )
258 258
         );
@@ -264,21 +264,21 @@  discard block
 block discarded – undo
264 264
      */
265 265
     public function activation_redirect() {
266 266
 
267
-		// Bail if no activation redirect.
268
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
269
-			return;
270
-		}
267
+        // Bail if no activation redirect.
268
+        if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
269
+            return;
270
+        }
271 271
 
272
-		// Delete the redirect transient.
273
-		delete_transient( '_wpinv_activation_redirect' );
272
+        // Delete the redirect transient.
273
+        delete_transient( '_wpinv_activation_redirect' );
274 274
 
275
-		// Bail if activating from network, or bulk
276
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
277
-			return;
278
-		}
275
+        // Bail if activating from network, or bulk
276
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
277
+            return;
278
+        }
279 279
 
280
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
281
-		exit;
280
+        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
281
+        exit;
282 282
     }
283 283
 
284 284
     /**
@@ -293,150 +293,150 @@  discard block
 block discarded – undo
293 293
 
294 294
     }
295 295
 
296
-	/**
296
+    /**
297 297
      * Sends a payment reminder to a customer.
298
-	 * 
299
-	 * @param array $args
298
+     * 
299
+     * @param array $args
300 300
      */
301 301
     public function send_customer_invoice( $args ) {
302
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
302
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
303 303
 
304
-		if ( $sent ) {
305
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
306
-		} else {
307
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
308
-		}
304
+        if ( $sent ) {
305
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
306
+        } else {
307
+            $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
308
+        }
309 309
 
310
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
311
-		exit;
312
-	}
310
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
311
+        exit;
312
+    }
313 313
 
314
-	/**
314
+    /**
315 315
      * Sends a payment reminder to a customer.
316
-	 * 
317
-	 * @param array $args
316
+     * 
317
+     * @param array $args
318 318
      */
319 319
     public function send_customer_payment_reminder( $args ) {
320
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
320
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
321 321
 
322
-		if ( $sent ) {
323
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
324
-		} else {
325
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
326
-		}
322
+        if ( $sent ) {
323
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
324
+        } else {
325
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
326
+        }
327 327
 
328
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
329
-		exit;
330
-	}
328
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
329
+        exit;
330
+    }
331 331
 
332 332
     /**
333
-	 * Returns an array of admin notices.
334
-	 *
335
-	 * @since       1.0.19
333
+     * Returns an array of admin notices.
334
+     *
335
+     * @since       1.0.19
336 336
      * @return array
337
-	 */
338
-	public function get_notices() {
339
-		$notices = get_option( 'wpinv_admin_notices' );
337
+     */
338
+    public function get_notices() {
339
+        $notices = get_option( 'wpinv_admin_notices' );
340 340
         return is_array( $notices ) ? $notices : array();
341
-	}
342
-
343
-	/**
344
-	 * Clears all admin notices
345
-	 *
346
-	 * @access      public
347
-	 * @since       1.0.19
348
-	 */
349
-	public function clear_notices() {
350
-		delete_option( 'wpinv_admin_notices' );
351
-	}
352
-
353
-	/**
354
-	 * Saves a new admin notice
355
-	 *
356
-	 * @access      public
357
-	 * @since       1.0.19
358
-	 */
359
-	public function save_notice( $type, $message ) {
360
-		$notices = $this->get_notices();
361
-
362
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
363
-			$notices[ $type ] = array();
364
-		}
365
-
366
-		$notices[ $type ][] = $message;
367
-
368
-		update_option( 'wpinv_admin_notices', $notices );
369
-	}
370
-
371
-	/**
372
-	 * Displays a success notice
373
-	 *
374
-	 * @param       string $msg The message to qeue.
375
-	 * @access      public
376
-	 * @since       1.0.19
377
-	 */
378
-	public function show_success( $msg ) {
379
-		$this->save_notice( 'success', $msg );
380
-	}
381
-
382
-	/**
383
-	 * Displays a error notice
384
-	 *
385
-	 * @access      public
386
-	 * @param       string $msg The message to qeue.
387
-	 * @since       1.0.19
388
-	 */
389
-	public function show_error( $msg ) {
390
-		$this->save_notice( 'error', $msg );
391
-	}
392
-
393
-	/**
394
-	 * Displays a warning notice
395
-	 *
396
-	 * @access      public
397
-	 * @param       string $msg The message to qeue.
398
-	 * @since       1.0.19
399
-	 */
400
-	public function show_warning( $msg ) {
401
-		$this->save_notice( 'warning', $msg );
402
-	}
403
-
404
-	/**
405
-	 * Displays a info notice
406
-	 *
407
-	 * @access      public
408
-	 * @param       string $msg The message to qeue.
409
-	 * @since       1.0.19
410
-	 */
411
-	public function show_info( $msg ) {
412
-		$this->save_notice( 'info', $msg );
413
-	}
414
-
415
-	/**
416
-	 * Show notices
417
-	 *
418
-	 * @access      public
419
-	 * @since       1.0.19
420
-	 */
421
-	public function show_notices() {
341
+    }
342
+
343
+    /**
344
+     * Clears all admin notices
345
+     *
346
+     * @access      public
347
+     * @since       1.0.19
348
+     */
349
+    public function clear_notices() {
350
+        delete_option( 'wpinv_admin_notices' );
351
+    }
352
+
353
+    /**
354
+     * Saves a new admin notice
355
+     *
356
+     * @access      public
357
+     * @since       1.0.19
358
+     */
359
+    public function save_notice( $type, $message ) {
360
+        $notices = $this->get_notices();
361
+
362
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
363
+            $notices[ $type ] = array();
364
+        }
365
+
366
+        $notices[ $type ][] = $message;
367
+
368
+        update_option( 'wpinv_admin_notices', $notices );
369
+    }
370
+
371
+    /**
372
+     * Displays a success notice
373
+     *
374
+     * @param       string $msg The message to qeue.
375
+     * @access      public
376
+     * @since       1.0.19
377
+     */
378
+    public function show_success( $msg ) {
379
+        $this->save_notice( 'success', $msg );
380
+    }
381
+
382
+    /**
383
+     * Displays a error notice
384
+     *
385
+     * @access      public
386
+     * @param       string $msg The message to qeue.
387
+     * @since       1.0.19
388
+     */
389
+    public function show_error( $msg ) {
390
+        $this->save_notice( 'error', $msg );
391
+    }
392
+
393
+    /**
394
+     * Displays a warning notice
395
+     *
396
+     * @access      public
397
+     * @param       string $msg The message to qeue.
398
+     * @since       1.0.19
399
+     */
400
+    public function show_warning( $msg ) {
401
+        $this->save_notice( 'warning', $msg );
402
+    }
403
+
404
+    /**
405
+     * Displays a info notice
406
+     *
407
+     * @access      public
408
+     * @param       string $msg The message to qeue.
409
+     * @since       1.0.19
410
+     */
411
+    public function show_info( $msg ) {
412
+        $this->save_notice( 'info', $msg );
413
+    }
414
+
415
+    /**
416
+     * Show notices
417
+     *
418
+     * @access      public
419
+     * @since       1.0.19
420
+     */
421
+    public function show_notices() {
422 422
 
423 423
         $notices = $this->get_notices();
424 424
         $this->clear_notices();
425 425
 
426
-		foreach ( $notices as $type => $messages ) {
426
+        foreach ( $notices as $type => $messages ) {
427 427
 
428
-			if ( ! is_array( $messages ) ) {
429
-				continue;
430
-			}
428
+            if ( ! is_array( $messages ) ) {
429
+                continue;
430
+            }
431 431
 
432 432
             $type  = sanitize_key( $type );
433
-			foreach ( $messages as $message ) {
433
+            foreach ( $messages as $message ) {
434 434
                 $message = wp_kses_post( $message );
435
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
435
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
436 436
             }
437 437
 
438 438
         }
439 439
 
440
-	}
440
+    }
441 441
 
442 442
 }
Please login to merge, or discard this patch.
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * The main admin class.
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
     /**
31 31
 	 * Class constructor.
32 32
 	 */
33
-	public function __construct(){
33
+	public function __construct() {
34 34
 
35
-        $this->admin_path  = plugin_dir_path( __FILE__ );
36
-        $this->admin_url   = plugins_url( '/', __FILE__ );
35
+        $this->admin_path  = plugin_dir_path(__FILE__);
36
+        $this->admin_url   = plugins_url('/', __FILE__);
37 37
 
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
 			$this->init_admin_hooks();
40 40
         }
41 41
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 */
48 48
 	private function init_admin_hooks() {
49
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
53
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
49
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
50
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
51
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
52
+        add_action('admin_init', array($this, 'activation_redirect'));
53
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
54
+		add_action('admin_notices', array($this, 'show_notices'));
55
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
56
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
57
+		do_action('getpaid_init_admin_hooks', $this);
58 58
 
59 59
     }
60 60
 
@@ -65,49 +65,49 @@  discard block
 block discarded – undo
65 65
 	public function enqeue_scripts() {
66 66
         global $current_screen, $pagenow;
67 67
 
68
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
68
+		$page    = isset($_GET['page']) ? $_GET['page'] : '';
69 69
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
70 70
 
71
-        if ( ! empty( $current_screen->post_type ) ) {
71
+        if (!empty($current_screen->post_type)) {
72 72
 			$page = $current_screen->post_type;
73 73
         }
74 74
 
75 75
         // General styles.
76
-        if ( false !== stripos( $page, 'wpi' ) ) {
76
+        if (false !== stripos($page, 'wpi')) {
77 77
 
78 78
             // Styles.
79
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
80
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
81
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
82
-            wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
83
-            wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' );
79
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
80
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
81
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
82
+            wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
83
+            wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16');
84 84
 
85 85
             // Scripts.
86
-            wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true );
87
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
86
+            wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true);
87
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
88 88
 
89
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
90
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ),  $version );
91
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
89
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
90
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version);
91
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
92 92
 
93 93
         }
94 94
 
95 95
         // Payment form scripts.
96
-		if ( 'wpi_payment_form' == $page && $editing ) {
96
+		if ('wpi_payment_form' == $page && $editing) {
97 97
             $this->load_payment_form_scripts();
98 98
         }
99 99
 
100
-        if ( $page == 'wpinv-subscriptions' ) {
101
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
102
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
100
+        if ($page == 'wpinv-subscriptions') {
101
+			wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
102
+			wp_enqueue_script('wpinv-sub-admin-script');
103 103
 		}
104 104
 
105
-		if ( $page == 'wpinv-reports' ) {
106
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
105
+		if ($page == 'wpinv-reports') {
106
+			wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
107 107
 		}
108 108
 
109
-		if ( $page == 'wpinv-subscriptions' ) {
110
-			wp_enqueue_script( 'postbox' );
109
+		if ($page == 'wpinv-subscriptions') {
110
+			wp_enqueue_script('postbox');
111 111
 		}
112 112
 
113 113
     }
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
         global $post;
121 121
 
122 122
         $i18n = array(
123
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
124
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
125
-            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
126
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
127
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
128
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
129
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
123
+            'ajax_url'                  => admin_url('admin-ajax.php'),
124
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
125
+            'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
126
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
127
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
128
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
129
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
130 130
             'tax'                       => wpinv_tax_amount(),
131 131
             'discount'                  => wpinv_discount_amount(),
132 132
             'currency_symbol'           => wpinv_currency_symbol(),
@@ -134,35 +134,35 @@  discard block
 block discarded – undo
134 134
             'thousand_sep'              => wpinv_thousands_separator(),
135 135
             'decimal_sep'               => wpinv_decimal_separator(),
136 136
             'decimals'                  => wpinv_decimals(),
137
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
138
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
139
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
140
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
141
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
142
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
143
-            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
144
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
145
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
146
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
147
-            'action_edit'               => __( 'Edit', 'invoicing' ),
148
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
149
-            'item_description'          => __( 'Item Description', 'invoicing' ),
150
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
151
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
152
-            'searching'                 => __( 'Searching', 'invoicing' ),
137
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
138
+            'status_publish'            => wpinv_status_nicename('publish'),
139
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
140
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
141
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
142
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
143
+            'confirmCalcTotals'         => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'),
144
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
145
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
146
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
147
+            'action_edit'               => __('Edit', 'invoicing'),
148
+            'action_cancel'             => __('Cancel', 'invoicing'),
149
+            'item_description'          => __('Item Description', 'invoicing'),
150
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
151
+            'discount_description'      => __('Discount Description', 'invoicing'),
152
+            'searching'                 => __('Searching', 'invoicing'),
153 153
         );
154 154
 
155
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
155
+		if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) {
156 156
 
157
-			$invoice              = new WPInv_Invoice( $post );
157
+			$invoice              = new WPInv_Invoice($post);
158 158
 			$i18n['save_invoice'] = sprintf(
159
-				__( 'Save %s', 'invoicing' ),
160
-				ucfirst( $invoice->get_type() )
159
+				__('Save %s', 'invoicing'),
160
+				ucfirst($invoice->get_type())
161 161
 			);
162 162
 
163 163
 			$i18n['invoice_description'] = sprintf(
164
-				__( '%s Description', 'invoicing' ),
165
-				ucfirst( $invoice->get_type() )
164
+				__('%s Description', 'invoicing'),
165
+				ucfirst($invoice->get_type())
166 166
 			);
167 167
 
168 168
 		}
@@ -176,30 +176,30 @@  discard block
 block discarded – undo
176 176
 	protected function load_payment_form_scripts() {
177 177
         global $post;
178 178
 
179
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
180
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
181
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
179
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
180
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
181
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
182 182
 
183
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
184
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
183
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
184
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
185 185
 
186 186
 		wp_localize_script(
187 187
             'wpinv-admin-payment-form-script',
188 188
             'wpinvPaymentFormAdmin',
189 189
             array(
190
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
191
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
190
+				'elements'      => wpinv_get_data('payment-form-elements'),
191
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
192 192
 				'currency'      => wpinv_currency_symbol(),
193 193
 				'position'      => wpinv_currency_position(),
194 194
 				'decimals'      => (int) wpinv_decimals(),
195 195
 				'thousands_sep' => wpinv_thousands_separator(),
196 196
 				'decimals_sep'  => wpinv_decimal_separator(),
197
-				'form_items'    => gepaid_get_form_items( $post->ID ),
197
+				'form_items'    => gepaid_get_form_items($post->ID),
198 198
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
199 199
             )
200 200
         );
201 201
 
202
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
202
+        wp_enqueue_script('wpinv-admin-payment-form-script');
203 203
 
204 204
     }
205 205
 
@@ -210,29 +210,29 @@  discard block
 block discarded – undo
210 210
      * @return string
211 211
 	 *
212 212
 	 */
213
-    public function admin_body_class( $classes ) {
213
+    public function admin_body_class($classes) {
214 214
 		global $pagenow, $post, $current_screen;
215 215
 
216 216
 
217
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
217
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
218 218
 
219
-        if ( ! empty( $current_screen->post_type ) ) {
219
+        if (!empty($current_screen->post_type)) {
220 220
 			$page = $current_screen->post_type;
221 221
         }
222 222
 
223
-        if ( false !== stripos( $page, 'wpi' ) ) {
224
-            $classes .= ' wpi-' . sanitize_key( $page );
223
+        if (false !== stripos($page, 'wpi')) {
224
+            $classes .= ' wpi-' . sanitize_key($page);
225 225
         }
226 226
 
227
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
227
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
228 228
             $classes .= ' wpinv-cpt wpinv';
229 229
 		}
230 230
 		
231
-		if ( getpaid_is_invoice_post_type( $page ) ) {
231
+		if (getpaid_is_invoice_post_type($page)) {
232 232
             $classes .= ' getpaid-is-invoice-cpt';
233 233
         }
234 234
 
235
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
235
+		if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
236 236
 			$classes .= ' wpi-editable-n';
237 237
 		}
238 238
 
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
     /**
243 243
 	 * Maybe show the AyeCode Connect Notice.
244 244
 	 */
245
-	public function init_ayecode_connect_helper(){
245
+	public function init_ayecode_connect_helper() {
246 246
 
247 247
         new AyeCode_Connect_Helper(
248 248
             array(
249
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
250
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
251
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
252
-				'connect_button'    => __("Connect Site","invoicing"),
253
-				'connecting_button'    => __("Connecting...","invoicing"),
254
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
255
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
249
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
250
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
251
+				'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
252
+				'connect_button'    => __("Connect Site", "invoicing"),
253
+				'connecting_button'    => __("Connecting...", "invoicing"),
254
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
255
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
256 256
             ),
257
-            array( 'wpi-addons' )
257
+            array('wpi-addons')
258 258
         );
259 259
 
260 260
     }
@@ -265,19 +265,19 @@  discard block
 block discarded – undo
265 265
     public function activation_redirect() {
266 266
 
267 267
 		// Bail if no activation redirect.
268
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
268
+		if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) {
269 269
 			return;
270 270
 		}
271 271
 
272 272
 		// Delete the redirect transient.
273
-		delete_transient( '_wpinv_activation_redirect' );
273
+		delete_transient('_wpinv_activation_redirect');
274 274
 
275 275
 		// Bail if activating from network, or bulk
276
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
276
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
277 277
 			return;
278 278
 		}
279 279
 
280
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
280
+		wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
281 281
 		exit;
282 282
     }
283 283
 
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
      */
287 287
     public function maybe_do_admin_action() {
288 288
 
289
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
290
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
291
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
289
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
290
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
291
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
292 292
         }
293 293
 
294 294
     }
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
 	 * 
299 299
 	 * @param array $args
300 300
      */
301
-    public function send_customer_invoice( $args ) {
302
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
301
+    public function send_customer_invoice($args) {
302
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']));
303 303
 
304
-		if ( $sent ) {
305
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
304
+		if ($sent) {
305
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
306 306
 		} else {
307
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
307
+			$this->show_error(__('Could not sent the invoice to the customer', 'invoicing'));
308 308
 		}
309 309
 
310
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
310
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
311 311
 		exit;
312 312
 	}
313 313
 
@@ -316,16 +316,16 @@  discard block
 block discarded – undo
316 316
 	 * 
317 317
 	 * @param array $args
318 318
      */
319
-    public function send_customer_payment_reminder( $args ) {
320
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
319
+    public function send_customer_payment_reminder($args) {
320
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
321 321
 
322
-		if ( $sent ) {
323
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
322
+		if ($sent) {
323
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
324 324
 		} else {
325
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
325
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
326 326
 		}
327 327
 
328
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
328
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
329 329
 		exit;
330 330
 	}
331 331
 
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
      * @return array
337 337
 	 */
338 338
 	public function get_notices() {
339
-		$notices = get_option( 'wpinv_admin_notices' );
340
-        return is_array( $notices ) ? $notices : array();
339
+		$notices = get_option('wpinv_admin_notices');
340
+        return is_array($notices) ? $notices : array();
341 341
 	}
342 342
 
343 343
 	/**
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 	 * @since       1.0.19
348 348
 	 */
349 349
 	public function clear_notices() {
350
-		delete_option( 'wpinv_admin_notices' );
350
+		delete_option('wpinv_admin_notices');
351 351
 	}
352 352
 
353 353
 	/**
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
 	 * @access      public
357 357
 	 * @since       1.0.19
358 358
 	 */
359
-	public function save_notice( $type, $message ) {
359
+	public function save_notice($type, $message) {
360 360
 		$notices = $this->get_notices();
361 361
 
362
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
363
-			$notices[ $type ] = array();
362
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
363
+			$notices[$type] = array();
364 364
 		}
365 365
 
366
-		$notices[ $type ][] = $message;
366
+		$notices[$type][] = $message;
367 367
 
368
-		update_option( 'wpinv_admin_notices', $notices );
368
+		update_option('wpinv_admin_notices', $notices);
369 369
 	}
370 370
 
371 371
 	/**
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * @access      public
376 376
 	 * @since       1.0.19
377 377
 	 */
378
-	public function show_success( $msg ) {
379
-		$this->save_notice( 'success', $msg );
378
+	public function show_success($msg) {
379
+		$this->save_notice('success', $msg);
380 380
 	}
381 381
 
382 382
 	/**
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 	 * @param       string $msg The message to qeue.
387 387
 	 * @since       1.0.19
388 388
 	 */
389
-	public function show_error( $msg ) {
390
-		$this->save_notice( 'error', $msg );
389
+	public function show_error($msg) {
390
+		$this->save_notice('error', $msg);
391 391
 	}
392 392
 
393 393
 	/**
@@ -397,8 +397,8 @@  discard block
 block discarded – undo
397 397
 	 * @param       string $msg The message to qeue.
398 398
 	 * @since       1.0.19
399 399
 	 */
400
-	public function show_warning( $msg ) {
401
-		$this->save_notice( 'warning', $msg );
400
+	public function show_warning($msg) {
401
+		$this->save_notice('warning', $msg);
402 402
 	}
403 403
 
404 404
 	/**
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param       string $msg The message to qeue.
409 409
 	 * @since       1.0.19
410 410
 	 */
411
-	public function show_info( $msg ) {
412
-		$this->save_notice( 'info', $msg );
411
+	public function show_info($msg) {
412
+		$this->save_notice('info', $msg);
413 413
 	}
414 414
 
415 415
 	/**
@@ -423,15 +423,15 @@  discard block
 block discarded – undo
423 423
         $notices = $this->get_notices();
424 424
         $this->clear_notices();
425 425
 
426
-		foreach ( $notices as $type => $messages ) {
426
+		foreach ($notices as $type => $messages) {
427 427
 
428
-			if ( ! is_array( $messages ) ) {
428
+			if (!is_array($messages)) {
429 429
 				continue;
430 430
 			}
431 431
 
432
-            $type  = sanitize_key( $type );
433
-			foreach ( $messages as $message ) {
434
-                $message = wp_kses_post( $message );
432
+            $type = sanitize_key($type);
433
+			foreach ($messages as $message) {
434
+                $message = wp_kses_post($message);
435 435
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
436 436
             }
437 437
 
Please login to merge, or discard this patch.
includes/admin/class-wpinv-admin-menus.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Setup menus in WP admin.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WC_Admin_Menus Class.
@@ -13,25 +13,25 @@  discard block
 block discarded – undo
13 13
      * Hook in tabs.
14 14
      */
15 15
     public function __construct() {
16
-        add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
17
-        add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 );
18
-        add_action( 'admin_menu', array( $this, 'add_subscriptions_menu' ), 40 );
19
-        add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 );
20
-        add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 );
21
-        add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 );
22
-        add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
16
+        add_action('admin_menu', array($this, 'admin_menu'), 10);
17
+        add_action('admin_menu', array($this, 'add_customers_menu'), 18);
18
+        add_action('admin_menu', array($this, 'add_subscriptions_menu'), 40);
19
+        add_action('admin_menu', array($this, 'add_addons_menu'), 100);
20
+        add_action('admin_menu', array($this, 'add_settings_menu'), 60);
21
+        add_action('admin_menu', array($this, 'remove_admin_submenus'), 10);
22
+        add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes'));
23 23
     }
24 24
 
25 25
     public function admin_menu() {
26 26
 
27
-        $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() );
27
+        $capability = apply_filters('invoicing_capability', wpinv_get_capability());
28 28
         add_menu_page(
29
-            __( 'GetPaid', 'invoicing' ),
30
-            __( 'GetPaid', 'invoicing' ),
29
+            __('GetPaid', 'invoicing'),
30
+            __('GetPaid', 'invoicing'),
31 31
             $capability,
32 32
             'wpinv',
33 33
             null,
34
-            'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ),
34
+            'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')),
35 35
             '54.123460'
36 36
         );
37 37
 
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
     public function add_customers_menu() {
44 44
         add_submenu_page(
45 45
             'wpinv',
46
-            __( 'Customers', 'invoicing' ),
47
-            __( 'Customers', 'invoicing' ),
46
+            __('Customers', 'invoicing'),
47
+            __('Customers', 'invoicing'),
48 48
             wpinv_get_capability(),
49 49
             'wpinv-customers',
50
-            array( $this, 'customers_page' )
50
+            array($this, 'customers_page')
51 51
         );
52 52
     }
53 53
 
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
     public function add_subscriptions_menu() {
58 58
         add_submenu_page(
59 59
             'wpinv',
60
-            __( 'Subscriptions', 'invoicing' ),
61
-            __( 'Subscriptions', 'invoicing' ),
60
+            __('Subscriptions', 'invoicing'),
61
+            __('Subscriptions', 'invoicing'),
62 62
             wpinv_get_capability(),
63 63
             'wpinv-subscriptions',
64 64
             'wpinv_subscriptions_page'
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      * Displays the customers page.
70 70
      */
71 71
     public function customers_page() {
72
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php' );
72
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php');
73 73
         ?>
74 74
         <div class="wrap wpi-customers-wrap">
75 75
             <style>
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
                     width: 30%;
78 78
                 }
79 79
             </style>
80
-            <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?></h1>
80
+            <h1><?php echo esc_html(__('Customers', 'invoicing')); ?></h1>
81 81
             <?php
82 82
                 $table = new WPInv_Customers_Table();
83 83
                 $table->prepare_items();
@@ -93,16 +93,16 @@  discard block
 block discarded – undo
93 93
     public function add_settings_menu() {
94 94
         add_submenu_page(
95 95
             'wpinv',
96
-            __( 'Invoice Settings', 'invoicing' ),
97
-            __( 'Settings', 'invoicing' ),
98
-            apply_filters( 'invoicing_capability', wpinv_get_capability() ),
96
+            __('Invoice Settings', 'invoicing'),
97
+            __('Settings', 'invoicing'),
98
+            apply_filters('invoicing_capability', wpinv_get_capability()),
99 99
             'wpinv-settings',
100
-            array( $this, 'options_page' )
100
+            array($this, 'options_page')
101 101
         );
102 102
     }
103 103
 
104
-    public function add_addons_menu(){
105
-        if ( !apply_filters( 'wpi_show_addons_page', true ) ) {
104
+    public function add_addons_menu() {
105
+        if (!apply_filters('wpi_show_addons_page', true)) {
106 106
             return;
107 107
         }
108 108
 
@@ -112,78 +112,78 @@  discard block
 block discarded – undo
112 112
             __('Extensions', 'invoicing'),
113 113
             'manage_options',
114 114
             'wpi-addons',
115
-            array( $this, 'addons_page' )
115
+            array($this, 'addons_page')
116 116
         );
117 117
     }
118 118
 
119
-    public function addons_page(){
119
+    public function addons_page() {
120 120
         $addon_obj = new WPInv_Admin_Addons();
121 121
         $addon_obj->output();
122 122
     }
123 123
 
124 124
     function options_page() {
125
-        $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
125
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
126 126
 
127
-        if ( $page !== 'wpinv-settings' ) {
127
+        if ($page !== 'wpinv-settings') {
128 128
             return;
129 129
         }
130 130
 
131 131
         $settings_tabs = wpinv_get_settings_tabs();
132 132
         $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
133
-        $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
134
-        $sections      = wpinv_get_settings_tab_sections( $active_tab );
133
+        $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
134
+        $sections      = wpinv_get_settings_tab_sections($active_tab);
135 135
         $key           = 'main';
136 136
 
137
-        if ( is_array( $sections ) ) {
138
-            $key = key( $sections );
137
+        if (is_array($sections)) {
138
+            $key = key($sections);
139 139
         }
140 140
 
141
-        $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
142
-        $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
141
+        $registered_sections = wpinv_get_settings_tab_sections($active_tab);
142
+        $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
143 143
         ob_start();
144 144
         ?>
145 145
         <div class="wrap">
146 146
             <h1 class="nav-tab-wrapper">
147 147
                 <?php
148
-                foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
149
-                    $tab_url = add_query_arg( array(
148
+                foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
149
+                    $tab_url = add_query_arg(array(
150 150
                         'settings-updated' => false,
151 151
                         'tab' => $tab_id,
152
-                    ) );
152
+                    ));
153 153
 
154 154
                     // Remove the section from the tabs so we always end up at the main section
155
-                    $tab_url = remove_query_arg( 'section', $tab_url );
156
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
155
+                    $tab_url = remove_query_arg('section', $tab_url);
156
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
157 157
 
158 158
                     $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
159 159
 
160
-                    echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
161
-                    echo esc_html( $tab_name );
160
+                    echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
161
+                    echo esc_html($tab_name);
162 162
                     echo '</a>';
163 163
                 }
164 164
                 ?>
165 165
             </h1>
166 166
             <?php
167
-            $number_of_sections = count( $sections );
167
+            $number_of_sections = count($sections);
168 168
             $number = 0;
169
-            if ( $number_of_sections > 1 ) {
169
+            if ($number_of_sections > 1) {
170 170
                 echo '<div><ul class="subsubsub">';
171
-                foreach( $sections as $section_id => $section_name ) {
171
+                foreach ($sections as $section_id => $section_name) {
172 172
                     echo '<li>';
173 173
                     $number++;
174
-                    $tab_url = add_query_arg( array(
174
+                    $tab_url = add_query_arg(array(
175 175
                         'settings-updated' => false,
176 176
                         'tab' => $active_tab,
177 177
                         'section' => $section_id
178
-                    ) );
179
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
178
+                    ));
179
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
180 180
                     $class = '';
181
-                    if ( $section == $section_id ) {
181
+                    if ($section == $section_id) {
182 182
                         $class = 'current';
183 183
                     }
184
-                    echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
184
+                    echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
185 185
 
186
-                    if ( $number != $number_of_sections ) {
186
+                    if ($number != $number_of_sections) {
187 187
                         echo ' | ';
188 188
                     }
189 189
                     echo '</li>';
@@ -195,20 +195,20 @@  discard block
 block discarded – undo
195 195
                 <form method="post" action="options.php">
196 196
                     <table class="form-table">
197 197
                         <?php
198
-                        settings_fields( 'wpinv_settings' );
198
+                        settings_fields('wpinv_settings');
199 199
 
200
-                        if ( 'main' === $section ) {
201
-                            do_action( 'wpinv_settings_tab_top', $active_tab );
200
+                        if ('main' === $section) {
201
+                            do_action('wpinv_settings_tab_top', $active_tab);
202 202
                         }
203 203
 
204
-                        do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
205
-                        do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
206
-                        do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
207
-                        do_action( 'getpaid_settings_tab_bottom', $active_tab, $section );
204
+                        do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
205
+                        do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
206
+                        do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
207
+                        do_action('getpaid_settings_tab_bottom', $active_tab, $section);
208 208
 
209 209
                         // For backwards compatibility
210
-                        if ( 'main' === $section ) {
211
-                            do_action( 'wpinv_settings_tab_bottom', $active_tab );
210
+                        if ('main' === $section) {
211
+                            do_action('wpinv_settings_tab_bottom', $active_tab);
212 212
                         }
213 213
                         ?>
214 214
                     </table>
@@ -222,18 +222,18 @@  discard block
 block discarded – undo
222 222
     }
223 223
 
224 224
     public function remove_admin_submenus() {
225
-        remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
225
+        remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
226 226
     }
227 227
 
228
-    public function add_nav_menu_meta_boxes(){
229
-        add_meta_box( 'wpinv_endpoints_nav_link', __( 'Invoicing Pages', 'invoicing' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' );
228
+    public function add_nav_menu_meta_boxes() {
229
+        add_meta_box('wpinv_endpoints_nav_link', __('Invoicing Pages', 'invoicing'), array($this, 'nav_menu_links'), 'nav-menus', 'side', 'low');
230 230
     }
231 231
 
232
-    public function nav_menu_links(){
232
+    public function nav_menu_links() {
233 233
         $endpoints = $this->get_menu_items();
234 234
         ?>
235 235
         <div id="invoicing-endpoints" class="posttypediv">
236
-        <?php if(!empty($endpoints['pages'])){ ?>
236
+        <?php if (!empty($endpoints['pages'])) { ?>
237 237
             <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active">
238 238
                 <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear">
239 239
                     <?php
@@ -245,29 +245,29 @@  discard block
 block discarded – undo
245 245
         <?php } ?>
246 246
         <p class="button-controls">
247 247
         <span class="list-controls">
248
-            <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints' ); ?>" class="select-all"><?php _e( 'Select all', 'invoicing' ); ?></a>
248
+            <a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints'); ?>" class="select-all"><?php _e('Select all', 'invoicing'); ?></a>
249 249
         </span>
250 250
             <span class="add-to-menu">
251
-            <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints">
251
+            <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints">
252 252
             <span class="spinner"></span>
253 253
         </span>
254 254
         </p>
255 255
         <?php
256 256
     }
257 257
 
258
-    public function get_menu_items(){
258
+    public function get_menu_items() {
259 259
         $items = array();
260 260
 
261
-        $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' );
262
-        if($wpinv_history_page_id > 0){
261
+        $wpinv_history_page_id = (int) wpinv_get_option('invoice_history_page');
262
+        if ($wpinv_history_page_id > 0) {
263 263
             $item = new stdClass();
264 264
             $item->object_id = $wpinv_history_page_id;
265 265
             $item->db_id = 0;
266
-            $item->object =  'page';
266
+            $item->object = 'page';
267 267
             $item->menu_item_parent = 0;
268 268
             $item->type = 'post_type';
269
-            $item->title = __('Invoice History Page','invoicing');
270
-            $item->url = get_permalink( $wpinv_history_page_id );
269
+            $item->title = __('Invoice History Page', 'invoicing');
270
+            $item->url = get_permalink($wpinv_history_page_id);
271 271
             $item->target = '';
272 272
             $item->attr_title = '';
273 273
             $item->classes = array('wpinv-menu-item');
@@ -276,16 +276,16 @@  discard block
 block discarded – undo
276 276
             $items['pages'][] = $item;
277 277
         }
278 278
 
279
-        $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' );
280
-        if($wpinv_sub_history_page_id > 0){
279
+        $wpinv_sub_history_page_id = (int) wpinv_get_option('invoice_subscription_page');
280
+        if ($wpinv_sub_history_page_id > 0) {
281 281
             $item = new stdClass();
282 282
             $item->object_id = $wpinv_sub_history_page_id;
283 283
             $item->db_id = 0;
284
-            $item->object =  'page';
284
+            $item->object = 'page';
285 285
             $item->menu_item_parent = 0;
286 286
             $item->type = 'post_type';
287
-            $item->title = __('Invoice Subscriptions Page','invoicing');
288
-            $item->url = get_permalink( $wpinv_sub_history_page_id );
287
+            $item->title = __('Invoice Subscriptions Page', 'invoicing');
288
+            $item->url = get_permalink($wpinv_sub_history_page_id);
289 289
             $item->target = '';
290 290
             $item->attr_title = '';
291 291
             $item->classes = array('wpinv-menu-item');
@@ -294,16 +294,16 @@  discard block
 block discarded – undo
294 294
             $items['pages'][] = $item;
295 295
         }
296 296
 
297
-        $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' );
298
-        if($wpinv_checkout_page_id > 0){
297
+        $wpinv_checkout_page_id = (int) wpinv_get_option('checkout_page');
298
+        if ($wpinv_checkout_page_id > 0) {
299 299
             $item = new stdClass();
300 300
             $item->object_id = $wpinv_checkout_page_id;
301 301
             $item->db_id = 0;
302
-            $item->object =  'page';
302
+            $item->object = 'page';
303 303
             $item->menu_item_parent = 0;
304 304
             $item->type = 'post_type';
305
-            $item->title = __('Checkout Page','invoicing');
306
-            $item->url = get_permalink( $wpinv_checkout_page_id );
305
+            $item->title = __('Checkout Page', 'invoicing');
306
+            $item->url = get_permalink($wpinv_checkout_page_id);
307 307
             $item->target = '';
308 308
             $item->attr_title = '';
309 309
             $item->classes = array('wpinv-menu-item');
@@ -312,16 +312,16 @@  discard block
 block discarded – undo
312 312
             $items['pages'][] = $item;
313 313
         }
314 314
 
315
-        $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' );
316
-        if($wpinv_tandc_page_id > 0){
315
+        $wpinv_tandc_page_id = (int) wpinv_get_option('tandc_page');
316
+        if ($wpinv_tandc_page_id > 0) {
317 317
             $item = new stdClass();
318 318
             $item->object_id = $wpinv_tandc_page_id;
319 319
             $item->db_id = 0;
320
-            $item->object =  'page';
320
+            $item->object = 'page';
321 321
             $item->menu_item_parent = 0;
322 322
             $item->type = 'post_type';
323
-            $item->title = __('Terms & Conditions','invoicing');
324
-            $item->url = get_permalink( $wpinv_tandc_page_id );
323
+            $item->title = __('Terms & Conditions', 'invoicing');
324
+            $item->url = get_permalink($wpinv_tandc_page_id);
325 325
             $item->target = '';
326 326
             $item->attr_title = '';
327 327
             $item->classes = array('wpinv-menu-item');
@@ -330,16 +330,16 @@  discard block
 block discarded – undo
330 330
             $items['pages'][] = $item;
331 331
         }
332 332
 
333
-        $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' );
334
-        if($wpinv_success_page_id > 0){
333
+        $wpinv_success_page_id = (int) wpinv_get_option('success_page');
334
+        if ($wpinv_success_page_id > 0) {
335 335
             $item = new stdClass();
336 336
             $item->object_id = $wpinv_success_page_id;
337 337
             $item->db_id = 0;
338
-            $item->object =  'page';
338
+            $item->object = 'page';
339 339
             $item->menu_item_parent = 0;
340 340
             $item->type = 'post_type';
341
-            $item->title = __('Success Page','invoicing');
342
-            $item->url = get_permalink( $wpinv_success_page_id );
341
+            $item->title = __('Success Page', 'invoicing');
342
+            $item->url = get_permalink($wpinv_success_page_id);
343 343
             $item->target = '';
344 344
             $item->attr_title = '';
345 345
             $item->classes = array('wpinv-menu-item');
@@ -348,16 +348,16 @@  discard block
 block discarded – undo
348 348
             $items['pages'][] = $item;
349 349
         }
350 350
 
351
-        $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' );
352
-        if($wpinv_failure_page_id > 0){
351
+        $wpinv_failure_page_id = (int) wpinv_get_option('failure_page');
352
+        if ($wpinv_failure_page_id > 0) {
353 353
             $item = new stdClass();
354 354
             $item->object_id = $wpinv_failure_page_id;
355 355
             $item->db_id = 0;
356
-            $item->object =  'page';
356
+            $item->object = 'page';
357 357
             $item->menu_item_parent = 0;
358 358
             $item->type = 'post_type';
359
-            $item->title = __('Failed Transaction Page','invoicing');
360
-            $item->url = get_permalink( $wpinv_failure_page_id );
359
+            $item->title = __('Failed Transaction Page', 'invoicing');
360
+            $item->url = get_permalink($wpinv_failure_page_id);
361 361
             $item->target = '';
362 362
             $item->attr_title = '';
363 363
             $item->classes = array('wpinv-menu-item');
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
             $items['pages'][] = $item;
367 367
         }
368 368
 
369
-        return apply_filters( 'wpinv_menu_items', $items );
369
+        return apply_filters('wpinv_menu_items', $items);
370 370
     }
371 371
 
372 372
 }
Please login to merge, or discard this patch.
templates/invoice/invoice.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
         <?php
19 19
 
20 20
             // Fires when printing the header.
21
-            do_action( 'getpaid_invoice_header', $invoice );
21
+            do_action('getpaid_invoice_header', $invoice);
22 22
 
23 23
             // Print the opening wrapper.
24 24
             echo '<div class="container bg-white border mt-4 mb-4 p-4 position-relative flex-grow-1">';
25 25
 
26 26
             // Fires when printing the invoice details.
27
-            do_action( 'getpaid_invoice_details', $invoice );
27
+            do_action('getpaid_invoice_details', $invoice);
28 28
 
29 29
             // Fires when printing the invoice line items.
30
-            do_action( 'getpaid_invoice_line_items', $invoice );
30
+            do_action('getpaid_invoice_line_items', $invoice);
31 31
 
32 32
             // Print notifications.
33 33
             wpinv_print_errors();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
             echo '</div>';
37 37
 
38 38
             // Fires when printing the invoice footer.
39
-            do_action( 'getpaid_invoice_footer', $invoice );
39
+            do_action('getpaid_invoice_footer', $invoice);
40 40
 
41 41
         ?>
42 42
 
Please login to merge, or discard this patch.