Passed
Push — master ( 9b80b5...fde38c )
by Brian
06:01
created
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +417 added lines, -417 removed lines patch added patch discarded remove patch
@@ -14,77 +14,77 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29 29
 	
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct(){
38
+     * Class constructor.
39
+     */
40
+    public function __construct(){
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect') );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
66 66
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
71
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
72
-		do_action( 'getpaid_init_admin_hooks', $this );
67
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
68
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
69
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
70
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
71
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
72
+        do_action( 'getpaid_init_admin_hooks', $this );
73 73
 
74 74
     }
75 75
 
76 76
     /**
77
-	 * Register admin scripts
78
-	 *
79
-	 */
80
-	public function enqeue_scripts() {
77
+     * Register admin scripts
78
+     *
79
+     */
80
+    public function enqeue_scripts() {
81 81
         global $current_screen, $pagenow;
82 82
 
83
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
84
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
83
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
84
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
85 85
 
86 86
         if ( ! empty( $current_screen->post_type ) ) {
87
-			$page = $current_screen->post_type;
87
+            $page = $current_screen->post_type;
88 88
         }
89 89
 
90 90
         // General styles.
@@ -105,54 +105,54 @@  discard block
 block discarded – undo
105 105
         }
106 106
 
107 107
         // Payment form scripts.
108
-		if ( 'wpi_payment_form' == $page && $editing ) {
108
+        if ( 'wpi_payment_form' == $page && $editing ) {
109 109
             $this->load_payment_form_scripts();
110 110
         }
111 111
 
112
-		if ( $page == 'wpinv-subscriptions' ) {
113
-			wp_enqueue_script( 'postbox' );
114
-		}
112
+        if ( $page == 'wpinv-subscriptions' ) {
113
+            wp_enqueue_script( 'postbox' );
114
+        }
115 115
 
116 116
     }
117 117
 
118 118
     /**
119
-	 * Returns admin js translations.
120
-	 *
121
-	 */
122
-	protected function get_admin_i18() {
119
+     * Returns admin js translations.
120
+     *
121
+     */
122
+    protected function get_admin_i18() {
123 123
         global $post;
124 124
 
125
-		$date_range = array(
126
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
127
-		);
125
+        $date_range = array(
126
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
127
+        );
128 128
 
129
-		if ( $date_range['period'] == 'custom' ) {
129
+        if ( $date_range['period'] == 'custom' ) {
130 130
 			
131
-			if ( isset( $_GET['from'] ) ) {
132
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
133
-			}
131
+            if ( isset( $_GET['from'] ) ) {
132
+                $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
133
+            }
134 134
 
135
-			if ( isset( $_GET['to'] ) ) {
136
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
137
-			}
135
+            if ( isset( $_GET['to'] ) ) {
136
+                $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
137
+            }
138 138
 
139
-		}
139
+        }
140 140
 
141 141
         $i18n = array(
142 142
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
143 143
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
144
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
145
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
146
-			'rest_root'                 => esc_url_raw( rest_url() ),
147
-			'date_range'                => $date_range,
144
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
145
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
146
+            'rest_root'                 => esc_url_raw( rest_url() ),
147
+            'date_range'                => $date_range,
148 148
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
149 149
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
150 150
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
151 151
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
152 152
             'tax'                       => wpinv_tax_amount(),
153 153
             'discount'                  => 0,
154
-			'currency_symbol'           => wpinv_currency_symbol(),
155
-			'currency'                  => wpinv_get_currency(),
154
+            'currency_symbol'           => wpinv_currency_symbol(),
155
+            'currency'                  => wpinv_get_currency(),
156 156
             'currency_pos'              => wpinv_currency_position(),
157 157
             'thousand_sep'              => wpinv_thousands_separator(),
158 158
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -172,118 +172,118 @@  discard block
 block discarded – undo
172 172
             'item_description'          => __( 'Item Description', 'invoicing' ),
173 173
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
174 174
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
175
-			'searching'                 => __( 'Searching', 'invoicing' ),
176
-			'loading'                   => __( 'Loading...', 'invoicing' ),
177
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
178
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
175
+            'searching'                 => __( 'Searching', 'invoicing' ),
176
+            'loading'                   => __( 'Loading...', 'invoicing' ),
177
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
178
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
179 179
         );
180 180
 
181
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
181
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
182 182
 
183
-			$invoice              = new WPInv_Invoice( $post );
184
-			$i18n['save_invoice'] = sprintf(
185
-				__( 'Save %s', 'invoicing' ),
186
-				ucfirst( $invoice->get_invoice_quote_type() )
187
-			);
183
+            $invoice              = new WPInv_Invoice( $post );
184
+            $i18n['save_invoice'] = sprintf(
185
+                __( 'Save %s', 'invoicing' ),
186
+                ucfirst( $invoice->get_invoice_quote_type() )
187
+            );
188 188
 
189
-			$i18n['invoice_description'] = sprintf(
190
-				__( '%s Description', 'invoicing' ),
191
-				ucfirst( $invoice->get_invoice_quote_type() )
192
-			);
189
+            $i18n['invoice_description'] = sprintf(
190
+                __( '%s Description', 'invoicing' ),
191
+                ucfirst( $invoice->get_invoice_quote_type() )
192
+            );
193 193
 
194
-		}
195
-		return $i18n;
196
-	}
194
+        }
195
+        return $i18n;
196
+    }
197 197
 
198
-	/**
199
-	 * Change the admin footer text on GetPaid admin pages.
200
-	 *
201
-	 * @since  2.0.0
202
-	 * @param  string $footer_text
203
-	 * @return string
204
-	 */
205
-	public function admin_footer_text( $footer_text ) {
206
-		global $current_screen;
198
+    /**
199
+     * Change the admin footer text on GetPaid admin pages.
200
+     *
201
+     * @since  2.0.0
202
+     * @param  string $footer_text
203
+     * @return string
204
+     */
205
+    public function admin_footer_text( $footer_text ) {
206
+        global $current_screen;
207 207
 
208
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
208
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
209 209
 
210 210
         if ( ! empty( $current_screen->post_type ) ) {
211
-			$page = $current_screen->post_type;
211
+            $page = $current_screen->post_type;
212 212
         }
213 213
 
214 214
         // General styles.
215 215
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
216 216
 
217
-			// Change the footer text
218
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
219
-
220
-				$rating_url  = esc_url(
221
-					wp_nonce_url(
222
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
223
-						'getpaid-nonce',
224
-						'getpaid-nonce'
225
-						)
226
-				);
227
-
228
-				$footer_text = sprintf(
229
-					/* translators: %s: five stars */
230
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
231
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
232
-				);
233
-
234
-			} else {
235
-
236
-				$footer_text = sprintf(
237
-					/* translators: %s: GetPaid */
238
-					__( 'Thank you for using %s!', 'invoicing' ),
239
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
240
-				);
241
-
242
-			}
243
-
244
-		}
245
-
246
-		return $footer_text;
247
-	}
248
-
249
-	/**
250
-	 * Redirects to wp.org to rate the plugin.
251
-	 *
252
-	 * @since  2.0.0
253
-	 */
254
-	public function redirect_to_wordpress_rating_page() {
255
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
256
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
257
-		exit;
258
-	}
217
+            // Change the footer text
218
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
219
+
220
+                $rating_url  = esc_url(
221
+                    wp_nonce_url(
222
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
223
+                        'getpaid-nonce',
224
+                        'getpaid-nonce'
225
+                        )
226
+                );
227
+
228
+                $footer_text = sprintf(
229
+                    /* translators: %s: five stars */
230
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
231
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
232
+                );
233
+
234
+            } else {
235
+
236
+                $footer_text = sprintf(
237
+                    /* translators: %s: GetPaid */
238
+                    __( 'Thank you for using %s!', 'invoicing' ),
239
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
240
+                );
241
+
242
+            }
243
+
244
+        }
245
+
246
+        return $footer_text;
247
+    }
259 248
 
260 249
     /**
261
-	 * Loads payment form js.
262
-	 *
263
-	 */
264
-	protected function load_payment_form_scripts() {
250
+     * Redirects to wp.org to rate the plugin.
251
+     *
252
+     * @since  2.0.0
253
+     */
254
+    public function redirect_to_wordpress_rating_page() {
255
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
256
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
257
+        exit;
258
+    }
259
+
260
+    /**
261
+     * Loads payment form js.
262
+     *
263
+     */
264
+    protected function load_payment_form_scripts() {
265 265
         global $post;
266 266
 
267 267
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
268
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
269
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
268
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
269
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
270 270
 
271
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
272
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
271
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
272
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
273 273
 
274
-		wp_localize_script(
274
+        wp_localize_script(
275 275
             'wpinv-admin-payment-form-script',
276 276
             'wpinvPaymentFormAdmin',
277 277
             array(
278
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
279
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
280
-				'currency'      => wpinv_currency_symbol(),
281
-				'position'      => wpinv_currency_position(),
282
-				'decimals'      => (int) wpinv_decimals(),
283
-				'thousands_sep' => wpinv_thousands_separator(),
284
-				'decimals_sep'  => wpinv_decimal_separator(),
285
-				'form_items'    => gepaid_get_form_items( $post->ID ),
286
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
278
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
279
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
280
+                'currency'      => wpinv_currency_symbol(),
281
+                'position'      => wpinv_currency_position(),
282
+                'decimals'      => (int) wpinv_decimals(),
283
+                'thousands_sep' => wpinv_thousands_separator(),
284
+                'decimals_sep'  => wpinv_decimal_separator(),
285
+                'form_items'    => gepaid_get_form_items( $post->ID ),
286
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
287 287
             )
288 288
         );
289 289
 
@@ -292,20 +292,20 @@  discard block
 block discarded – undo
292 292
     }
293 293
 
294 294
     /**
295
-	 * Add our classes to admin pages.
295
+     * Add our classes to admin pages.
296 296
      *
297 297
      * @param string $classes
298 298
      * @return string
299
-	 *
300
-	 */
299
+     *
300
+     */
301 301
     public function admin_body_class( $classes ) {
302
-		global $pagenow, $post, $current_screen;
302
+        global $pagenow, $post, $current_screen;
303 303
 
304 304
 
305 305
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
306 306
 
307 307
         if ( ! empty( $current_screen->post_type ) ) {
308
-			$page = $current_screen->post_type;
308
+            $page = $current_screen->post_type;
309 309
         }
310 310
 
311 311
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -314,59 +314,59 @@  discard block
 block discarded – undo
314 314
 
315 315
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
316 316
             $classes .= ' wpinv-cpt wpinv';
317
-		}
317
+        }
318 318
 		
319
-		if ( getpaid_is_invoice_post_type( $page ) ) {
319
+        if ( getpaid_is_invoice_post_type( $page ) ) {
320 320
             $classes .= ' getpaid-is-invoice-cpt';
321 321
         }
322 322
 
323
-		return $classes;
323
+        return $classes;
324 324
     }
325 325
 
326 326
     /**
327
-	 * Maybe show the AyeCode Connect Notice.
328
-	 */
329
-	public function init_ayecode_connect_helper(){
327
+     * Maybe show the AyeCode Connect Notice.
328
+     */
329
+    public function init_ayecode_connect_helper(){
330 330
 
331 331
         new AyeCode_Connect_Helper(
332 332
             array(
333
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
334
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
335
-				'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>" ),
336
-				'connect_button'    => __("Connect Site","invoicing"),
337
-				'connecting_button'    => __("Connecting...","invoicing"),
338
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
339
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
333
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
334
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
335
+                '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>" ),
336
+                'connect_button'    => __("Connect Site","invoicing"),
337
+                'connecting_button'    => __("Connecting...","invoicing"),
338
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
339
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
340 340
             ),
341 341
             array( 'wpi-addons' )
342 342
         );
343 343
 
344 344
     }
345 345
 
346
-	/**
347
-	 * Redirect users to settings on activation.
348
-	 *
349
-	 * @return void
350
-	 */
351
-	public function activation_redirect() {
346
+    /**
347
+     * Redirect users to settings on activation.
348
+     *
349
+     * @return void
350
+     */
351
+    public function activation_redirect() {
352 352
 
353
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
353
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
354 354
 
355
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
356
-			return;
357
-		}
355
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
356
+            return;
357
+        }
358 358
 
359
-		// Bail if activating from network, or bulk
360
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
361
-			return;
362
-		}
359
+        // Bail if activating from network, or bulk
360
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
361
+            return;
362
+        }
363 363
 
364
-	    update_option( 'wpinv_redirected_to_settings', 1 );
364
+        update_option( 'wpinv_redirected_to_settings', 1 );
365 365
 
366 366
         wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
367 367
         exit;
368 368
 
369
-	}
369
+    }
370 370
 
371 371
     /**
372 372
      * Fires an admin action after verifying that a user can fire them.
@@ -380,304 +380,304 @@  discard block
 block discarded – undo
380 380
 
381 381
     }
382 382
 
383
-	/**
383
+    /**
384 384
      * Sends a payment reminder to a customer.
385
-	 * 
386
-	 * @param array $args
385
+     * 
386
+     * @param array $args
387 387
      */
388 388
     public function send_customer_invoice( $args ) {
389
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
389
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
390 390
 
391
-		if ( $sent ) {
392
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
393
-		} else {
394
-			$this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
395
-		}
391
+        if ( $sent ) {
392
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
393
+        } else {
394
+            $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
395
+        }
396 396
 
397
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
398
-		exit;
399
-	}
397
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
398
+        exit;
399
+    }
400 400
 
401
-	/**
401
+    /**
402 402
      * Sends a payment reminder to a customer.
403
-	 * 
404
-	 * @param array $args
403
+     * 
404
+     * @param array $args
405 405
      */
406 406
     public function send_customer_payment_reminder( $args ) {
407
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
407
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
408 408
 
409
-		if ( $sent ) {
410
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
411
-		} else {
412
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
413
-		}
409
+        if ( $sent ) {
410
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
411
+        } else {
412
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
413
+        }
414 414
 
415
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
416
-		exit;
417
-	}
415
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
416
+        exit;
417
+    }
418 418
 
419
-	/**
419
+    /**
420 420
      * Resets tax rates.
421
-	 * 
421
+     * 
422 422
      */
423 423
     public function admin_reset_tax_rates() {
424 424
 
425
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
426
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
427
-		exit;
425
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
426
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
427
+        exit;
428 428
 
429
-	}
429
+    }
430 430
 
431
-	/**
431
+    /**
432 432
      * Resets admin pages.
433
-	 * 
433
+     * 
434 434
      */
435 435
     public function admin_create_missing_pages() {
436
-		$installer = new GetPaid_Installer();
437
-		$installer->create_pages();
438
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
439
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
440
-		exit;
441
-	}
442
-
443
-	/**
436
+        $installer = new GetPaid_Installer();
437
+        $installer->create_pages();
438
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
439
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
440
+        exit;
441
+    }
442
+
443
+    /**
444 444
      * Creates an missing admin tables.
445
-	 * 
445
+     * 
446 446
      */
447 447
     public function admin_create_missing_tables() {
448
-		global $wpdb;
449
-		$installer = new GetPaid_Installer();
448
+        global $wpdb;
449
+        $installer = new GetPaid_Installer();
450 450
 
451
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
452
-			$installer->create_subscriptions_table();
451
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
452
+            $installer->create_subscriptions_table();
453 453
 
454
-			if ( $wpdb->last_error !== '' ) {
455
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
456
-			}
457
-		}
454
+            if ( $wpdb->last_error !== '' ) {
455
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
456
+            }
457
+        }
458 458
 
459
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
460
-			$installer->create_invoices_table();
459
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
460
+            $installer->create_invoices_table();
461 461
 
462
-			if ( $wpdb->last_error !== '' ) {
463
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
464
-			}
465
-		}
462
+            if ( $wpdb->last_error !== '' ) {
463
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
464
+            }
465
+        }
466 466
 
467
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
468
-			$installer->create_invoice_items_table();
467
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
468
+            $installer->create_invoice_items_table();
469 469
 
470
-			if ( $wpdb->last_error !== '' ) {
471
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
472
-			}
473
-		}
470
+            if ( $wpdb->last_error !== '' ) {
471
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
472
+            }
473
+        }
474 474
 
475
-		if ( ! $this->has_notices() ) {
476
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
477
-		}
475
+        if ( ! $this->has_notices() ) {
476
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
477
+        }
478 478
 
479
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
480
-		exit;
481
-	}
479
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
480
+        exit;
481
+    }
482 482
 
483
-	/**
483
+    /**
484 484
      * Migrates old invoices to the new database tables.
485
-	 * 
485
+     * 
486 486
      */
487 487
     public function admin_migrate_old_invoices() {
488 488
 
489
-		// Migrate the invoices.
490
-		$installer = new GetPaid_Installer();
491
-		$installer->migrate_old_invoices();
489
+        // Migrate the invoices.
490
+        $installer = new GetPaid_Installer();
491
+        $installer->migrate_old_invoices();
492 492
 
493
-		// Show an admin message.
494
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
493
+        // Show an admin message.
494
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
495 495
 
496
-		// Redirect the admin.
497
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
498
-		exit;
496
+        // Redirect the admin.
497
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
498
+        exit;
499 499
 
500
-	}
500
+    }
501 501
 
502
-	/**
502
+    /**
503 503
      * Recalculates discounts.
504
-	 * 
504
+     * 
505 505
      */
506 506
     public function admin_recalculate_discounts() {
507
-		global $wpdb;
507
+        global $wpdb;
508 508
 
509
-		// Fetch all invoices that have discount codes.
510
-		$table    = $wpdb->prefix . 'getpaid_invoices';
511
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
509
+        // Fetch all invoices that have discount codes.
510
+        $table    = $wpdb->prefix . 'getpaid_invoices';
511
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
512 512
 
513
-		foreach ( $invoices as $invoice ) {
513
+        foreach ( $invoices as $invoice ) {
514 514
 
515
-			$invoice = new WPInv_Invoice( $invoice );
515
+            $invoice = new WPInv_Invoice( $invoice );
516 516
 
517
-			if ( ! $invoice->exists() ) {
518
-				continue;
519
-			}
517
+            if ( ! $invoice->exists() ) {
518
+                continue;
519
+            }
520 520
 
521
-			// Abort if the discount does not exist or does not apply here.
522
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
523
-			if ( ! $discount->exists() ) {
524
-				continue;
525
-			}
521
+            // Abort if the discount does not exist or does not apply here.
522
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
523
+            if ( ! $discount->exists() ) {
524
+                continue;
525
+            }
526 526
 
527
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
528
-			$invoice->recalculate_total();
527
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
528
+            $invoice->recalculate_total();
529 529
 
530
-			if ( $invoice->get_total_discount() > 0 ) {
531
-				$invoice->save();
532
-			}
530
+            if ( $invoice->get_total_discount() > 0 ) {
531
+                $invoice->save();
532
+            }
533 533
 
534
-		}
534
+        }
535 535
 
536
-		// Show an admin message.
537
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
536
+        // Show an admin message.
537
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
538 538
 
539
-		// Redirect the admin.
540
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
541
-		exit;
539
+        // Redirect the admin.
540
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
541
+        exit;
542 542
 
543
-	}
543
+    }
544 544
 
545 545
     /**
546
-	 * Returns an array of admin notices.
547
-	 *
548
-	 * @since       1.0.19
546
+     * Returns an array of admin notices.
547
+     *
548
+     * @since       1.0.19
549 549
      * @return array
550
-	 */
551
-	public function get_notices() {
552
-		$notices = get_option( 'wpinv_admin_notices' );
550
+     */
551
+    public function get_notices() {
552
+        $notices = get_option( 'wpinv_admin_notices' );
553 553
         return is_array( $notices ) ? $notices : array();
554
-	}
554
+    }
555 555
 
556
-	/**
557
-	 * Checks if we have any admin notices.
558
-	 *
559
-	 * @since       2.0.4
556
+    /**
557
+     * Checks if we have any admin notices.
558
+     *
559
+     * @since       2.0.4
560 560
      * @return array
561
-	 */
562
-	public function has_notices() {
563
-		return count( $this->get_notices() ) > 0;
564
-	}
565
-
566
-	/**
567
-	 * Clears all admin notices
568
-	 *
569
-	 * @access      public
570
-	 * @since       1.0.19
571
-	 */
572
-	public function clear_notices() {
573
-		delete_option( 'wpinv_admin_notices' );
574
-	}
575
-
576
-	/**
577
-	 * Saves a new admin notice
578
-	 *
579
-	 * @access      public
580
-	 * @since       1.0.19
581
-	 */
582
-	public function save_notice( $type, $message ) {
583
-		$notices = $this->get_notices();
584
-
585
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
586
-			$notices[ $type ] = array();
587
-		}
588
-
589
-		$notices[ $type ][] = $message;
590
-
591
-		update_option( 'wpinv_admin_notices', $notices );
592
-	}
593
-
594
-	/**
595
-	 * Displays a success notice
596
-	 *
597
-	 * @param       string $msg The message to qeue.
598
-	 * @access      public
599
-	 * @since       1.0.19
600
-	 */
601
-	public function show_success( $msg ) {
602
-		$this->save_notice( 'success', $msg );
603
-	}
604
-
605
-	/**
606
-	 * Displays a error notice
607
-	 *
608
-	 * @access      public
609
-	 * @param       string $msg The message to qeue.
610
-	 * @since       1.0.19
611
-	 */
612
-	public function show_error( $msg ) {
613
-		$this->save_notice( 'error', $msg );
614
-	}
615
-
616
-	/**
617
-	 * Displays a warning notice
618
-	 *
619
-	 * @access      public
620
-	 * @param       string $msg The message to qeue.
621
-	 * @since       1.0.19
622
-	 */
623
-	public function show_warning( $msg ) {
624
-		$this->save_notice( 'warning', $msg );
625
-	}
626
-
627
-	/**
628
-	 * Displays a info notice
629
-	 *
630
-	 * @access      public
631
-	 * @param       string $msg The message to qeue.
632
-	 * @since       1.0.19
633
-	 */
634
-	public function show_info( $msg ) {
635
-		$this->save_notice( 'info', $msg );
636
-	}
637
-
638
-	/**
639
-	 * Show notices
640
-	 *
641
-	 * @access      public
642
-	 * @since       1.0.19
643
-	 */
644
-	public function show_notices() {
561
+     */
562
+    public function has_notices() {
563
+        return count( $this->get_notices() ) > 0;
564
+    }
565
+
566
+    /**
567
+     * Clears all admin notices
568
+     *
569
+     * @access      public
570
+     * @since       1.0.19
571
+     */
572
+    public function clear_notices() {
573
+        delete_option( 'wpinv_admin_notices' );
574
+    }
575
+
576
+    /**
577
+     * Saves a new admin notice
578
+     *
579
+     * @access      public
580
+     * @since       1.0.19
581
+     */
582
+    public function save_notice( $type, $message ) {
583
+        $notices = $this->get_notices();
584
+
585
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
586
+            $notices[ $type ] = array();
587
+        }
588
+
589
+        $notices[ $type ][] = $message;
590
+
591
+        update_option( 'wpinv_admin_notices', $notices );
592
+    }
593
+
594
+    /**
595
+     * Displays a success notice
596
+     *
597
+     * @param       string $msg The message to qeue.
598
+     * @access      public
599
+     * @since       1.0.19
600
+     */
601
+    public function show_success( $msg ) {
602
+        $this->save_notice( 'success', $msg );
603
+    }
604
+
605
+    /**
606
+     * Displays a error notice
607
+     *
608
+     * @access      public
609
+     * @param       string $msg The message to qeue.
610
+     * @since       1.0.19
611
+     */
612
+    public function show_error( $msg ) {
613
+        $this->save_notice( 'error', $msg );
614
+    }
615
+
616
+    /**
617
+     * Displays a warning notice
618
+     *
619
+     * @access      public
620
+     * @param       string $msg The message to qeue.
621
+     * @since       1.0.19
622
+     */
623
+    public function show_warning( $msg ) {
624
+        $this->save_notice( 'warning', $msg );
625
+    }
626
+
627
+    /**
628
+     * Displays a info notice
629
+     *
630
+     * @access      public
631
+     * @param       string $msg The message to qeue.
632
+     * @since       1.0.19
633
+     */
634
+    public function show_info( $msg ) {
635
+        $this->save_notice( 'info', $msg );
636
+    }
637
+
638
+    /**
639
+     * Show notices
640
+     *
641
+     * @access      public
642
+     * @since       1.0.19
643
+     */
644
+    public function show_notices() {
645 645
 
646 646
         $notices = $this->get_notices();
647 647
         $this->clear_notices();
648 648
 
649
-		foreach ( $notices as $type => $messages ) {
649
+        foreach ( $notices as $type => $messages ) {
650 650
 
651
-			if ( ! is_array( $messages ) ) {
652
-				continue;
653
-			}
651
+            if ( ! is_array( $messages ) ) {
652
+                continue;
653
+            }
654 654
 
655 655
             $type  = sanitize_key( $type );
656
-			foreach ( $messages as $message ) {
656
+            foreach ( $messages as $message ) {
657 657
                 $message = wp_kses_post( $message );
658
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
658
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
659
+            }
660
+
661
+        }
662
+
663
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
664
+
665
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
666
+                $url     = esc_url(
667
+                    wp_nonce_url(
668
+                        add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
669
+                        'getpaid-nonce',
670
+                        'getpaid-nonce'
671
+                    )
672
+                );
673
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
674
+                $message2 = __( 'Generate Pages', 'invoicing' );
675
+                echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
676
+                break;
659 677
             }
660 678
 
661 679
         }
662 680
 
663
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
664
-
665
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
666
-				$url     = esc_url(
667
-					wp_nonce_url(
668
-						add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
669
-						'getpaid-nonce',
670
-						'getpaid-nonce'
671
-					)
672
-				);
673
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
674
-				$message2 = __( 'Generate Pages', 'invoicing' );
675
-				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
676
-				break;
677
-			}
678
-
679
-		}
680
-
681
-	}
681
+    }
682 682
 
683 683
 }
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +395 added lines, -395 removed lines patch added patch discarded remove patch
@@ -12,449 +12,449 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
151
-	}
152
-
153
-	/**
154
-	 * Helper function to send an email.
155
-	 *
156
-	 * @param WPInv_Invoice $invoice
157
-	 * @param GetPaid_Notification_Email $email
158
-	 * @param string $type
159
-	 * @param string|array $recipients
160
-	 * @param array $extra_args Extra template args.
161
-	 */
162
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
163
-
164
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
165
-
166
-		$mailer     = new GetPaid_Notification_Email_Sender();
167
-		$merge_tags = $email->get_merge_tags();
168
-
169
-		$result = $mailer->send(
170
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
172
-			$email->get_content( $merge_tags, $extra_args ),
173
-			$email->get_attachments()
174
-		);
175
-
176
-		// Maybe send a copy to the admin.
177
-		if ( $email->include_admin_bcc() ) {
178
-			$mailer->send(
179
-				wpinv_get_admin_email(),
180
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
181
-				$email->get_content( $merge_tags ),
182
-				$email->get_attachments()
183
-			);
184
-		}
185
-
186
-		if ( ! $result ) {
187
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
188
-		}
189
-
190
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
191
-
192
-		return $result;
193
-	}
194
-
195
-	/**
196
-	 * Also send emails to any cc users.
197
-	 *
198
-	 * @param array $recipients
199
-	 * @param GetPaid_Notification_Email $email
200
-	 */
201
-	public function filter_email_recipients( $recipients, $email ) {
202
-
203
-		if ( ! $email->is_admin_email() ) {
204
-			$cc = $email->object->get_email_cc();
205
-
206
-			if ( ! empty( $cc ) ) {
207
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
208
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
209
-			}
210
-
211
-		}
212
-
213
-		return $recipients;
214
-
215
-	}
216
-
217
-	/**
218
-	 * Sends a new invoice notification.
219
-	 *
220
-	 * @param WPInv_Invoice $invoice
221
-	 */
222
-	public function new_invoice( $invoice ) {
223
-
224
-		// Only send this email for invoices created via the admin page.
225
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
226
-			return;
227
-		}
228
-
229
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
230
-		$recipient = wpinv_get_admin_email();
231
-
232
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
233
-
234
-	}
235
-
236
-	/**
237
-	 * Sends a cancelled invoice notification.
238
-	 *
239
-	 * @param WPInv_Invoice $invoice
240
-	 */
241
-	public function cancelled_invoice( $invoice ) {
242
-
243
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
244
-		$recipient = wpinv_get_admin_email();
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
151
+    }
152
+
153
+    /**
154
+     * Helper function to send an email.
155
+     *
156
+     * @param WPInv_Invoice $invoice
157
+     * @param GetPaid_Notification_Email $email
158
+     * @param string $type
159
+     * @param string|array $recipients
160
+     * @param array $extra_args Extra template args.
161
+     */
162
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
163
+
164
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
165
+
166
+        $mailer     = new GetPaid_Notification_Email_Sender();
167
+        $merge_tags = $email->get_merge_tags();
168
+
169
+        $result = $mailer->send(
170
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
172
+            $email->get_content( $merge_tags, $extra_args ),
173
+            $email->get_attachments()
174
+        );
175
+
176
+        // Maybe send a copy to the admin.
177
+        if ( $email->include_admin_bcc() ) {
178
+            $mailer->send(
179
+                wpinv_get_admin_email(),
180
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
181
+                $email->get_content( $merge_tags ),
182
+                $email->get_attachments()
183
+            );
184
+        }
185
+
186
+        if ( ! $result ) {
187
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
188
+        }
189
+
190
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
191
+
192
+        return $result;
193
+    }
194
+
195
+    /**
196
+     * Also send emails to any cc users.
197
+     *
198
+     * @param array $recipients
199
+     * @param GetPaid_Notification_Email $email
200
+     */
201
+    public function filter_email_recipients( $recipients, $email ) {
202
+
203
+        if ( ! $email->is_admin_email() ) {
204
+            $cc = $email->object->get_email_cc();
205
+
206
+            if ( ! empty( $cc ) ) {
207
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
208
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
209
+            }
210
+
211
+        }
212
+
213
+        return $recipients;
214
+
215
+    }
216
+
217
+    /**
218
+     * Sends a new invoice notification.
219
+     *
220
+     * @param WPInv_Invoice $invoice
221
+     */
222
+    public function new_invoice( $invoice ) {
223
+
224
+        // Only send this email for invoices created via the admin page.
225
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
226
+            return;
227
+        }
228
+
229
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
230
+        $recipient = wpinv_get_admin_email();
231
+
232
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
233
+
234
+    }
235
+
236
+    /**
237
+     * Sends a cancelled invoice notification.
238
+     *
239
+     * @param WPInv_Invoice $invoice
240
+     */
241
+    public function cancelled_invoice( $invoice ) {
242
+
243
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
244
+        $recipient = wpinv_get_admin_email();
245 245
 
246
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
246
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
247 247
 
248
-	}
248
+    }
249 249
 
250
-	/**
251
-	 * Sends a failed invoice notification.
252
-	 *
253
-	 * @param WPInv_Invoice $invoice
254
-	 */
255
-	public function failed_invoice( $invoice ) {
250
+    /**
251
+     * Sends a failed invoice notification.
252
+     *
253
+     * @param WPInv_Invoice $invoice
254
+     */
255
+    public function failed_invoice( $invoice ) {
256 256
 
257
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
258
-		$recipient = wpinv_get_admin_email();
257
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
258
+        $recipient = wpinv_get_admin_email();
259 259
 
260
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
260
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
261 261
 
262
-	}
262
+    }
263 263
 
264
-	/**
265
-	 * Sends a notification whenever an invoice is put on hold.
266
-	 *
267
-	 * @param WPInv_Invoice $invoice
268
-	 */
269
-	public function onhold_invoice( $invoice ) {
264
+    /**
265
+     * Sends a notification whenever an invoice is put on hold.
266
+     *
267
+     * @param WPInv_Invoice $invoice
268
+     */
269
+    public function onhold_invoice( $invoice ) {
270 270
 
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
-		$recipient = $invoice->get_email();
271
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
+        $recipient = $invoice->get_email();
273 273
 
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275 275
 
276
-	}
276
+    }
277 277
 
278
-	/**
279
-	 * Sends a notification whenever an invoice is marked as processing payment.
280
-	 *
281
-	 * @param WPInv_Invoice $invoice
282
-	 */
283
-	public function processing_invoice( $invoice ) {
278
+    /**
279
+     * Sends a notification whenever an invoice is marked as processing payment.
280
+     *
281
+     * @param WPInv_Invoice $invoice
282
+     */
283
+    public function processing_invoice( $invoice ) {
284 284
 
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
-		$recipient = $invoice->get_email();
285
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
+        $recipient = $invoice->get_email();
287 287
 
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289 289
 
290
-	}
290
+    }
291 291
 
292
-	/**
293
-	 * Sends a notification whenever an invoice is paid.
294
-	 *
295
-	 * @param WPInv_Invoice $invoice
296
-	 */
297
-	public function completed_invoice( $invoice ) {
292
+    /**
293
+     * Sends a notification whenever an invoice is paid.
294
+     *
295
+     * @param WPInv_Invoice $invoice
296
+     */
297
+    public function completed_invoice( $invoice ) {
298 298
 
299
-		// (Maybe) abort if it is a renewal invoice.
300
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
301
-			return;
302
-		}
299
+        // (Maybe) abort if it is a renewal invoice.
300
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
301
+            return;
302
+        }
303 303
 
304
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
305
-		$recipient = $invoice->get_email();
304
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
305
+        $recipient = $invoice->get_email();
306 306
 
307
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
307
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
308 308
 
309
-	}
309
+    }
310 310
 
311
-	/**
312
-	 * Sends a notification whenever an invoice is refunded.
313
-	 *
314
-	 * @param WPInv_Invoice $invoice
315
-	 */
316
-	public function refunded_invoice( $invoice ) {
311
+    /**
312
+     * Sends a notification whenever an invoice is refunded.
313
+     *
314
+     * @param WPInv_Invoice $invoice
315
+     */
316
+    public function refunded_invoice( $invoice ) {
317 317
 
318
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
319
-		$recipient = $invoice->get_email();
318
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
319
+        $recipient = $invoice->get_email();
320 320
 
321
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
321
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
322 322
 
323
-	}
323
+    }
324 324
 
325
-	/**
326
-	 * Notifies a user about new invoices
327
-	 *
328
-	 * @param WPInv_Invoice $invoice
329
-	 * @param bool $force
330
-	 */
331
-	public function user_invoice( $invoice, $force = false ) {
325
+    /**
326
+     * Notifies a user about new invoices
327
+     *
328
+     * @param WPInv_Invoice $invoice
329
+     * @param bool $force
330
+     */
331
+    public function user_invoice( $invoice, $force = false ) {
332 332
 
333
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
334
-			return;
335
-		}
333
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
334
+            return;
335
+        }
336 336
 
337
-		// Only send this email for invoices created via the admin page.
338
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
339
-			return;
340
-		}
337
+        // Only send this email for invoices created via the admin page.
338
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
339
+            return;
340
+        }
341 341
 
342
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
343
-		$recipient = $invoice->get_email();
342
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
343
+        $recipient = $invoice->get_email();
344 344
 
345
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
345
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
346 346
 
347
-	}
347
+    }
348 348
 
349
-	/**
350
-	 * Checks if an invoice is a payment form invoice.
351
-	 *
352
-	 * @param int $invoice
353
-	 * @return bool
354
-	 */
355
-	public function is_payment_form_invoice( $invoice ) {
356
-		return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
357
-	}
349
+    /**
350
+     * Checks if an invoice is a payment form invoice.
351
+     *
352
+     * @param int $invoice
353
+     * @return bool
354
+     */
355
+    public function is_payment_form_invoice( $invoice ) {
356
+        return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
357
+    }
358 358
 
359
-	/**
360
-	 * Notifies admin about new invoice notes
361
-	 *
362
-	 * @param WPInv_Invoice $invoice
363
-	 * @param string $note
364
-	 */
365
-	public function user_note( $invoice, $note ) {
366
-
367
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
368
-		$recipient = $invoice->get_email();
359
+    /**
360
+     * Notifies admin about new invoice notes
361
+     *
362
+     * @param WPInv_Invoice $invoice
363
+     * @param string $note
364
+     */
365
+    public function user_note( $invoice, $note ) {
366
+
367
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
368
+        $recipient = $invoice->get_email();
369 369
 
370
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
371
-
372
-	}
370
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
371
+
372
+    }
373 373
 
374
-	/**
375
-	 * (Force) Sends overdue notices.
376
-	 *
377
-	 * @param WPInv_Invoice $invoice
378
-	 */
379
-	public function force_send_overdue_notice( $invoice ) {
380
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
381
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
382
-	}
383
-
384
-	/**
385
-	 * Sends overdue notices.
386
-	 *
387
-	 * @TODO: Create an invoices query class.
388
-	 */
389
-	public function overdue() {
390
-		global $wpdb;
391
-
392
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
393
-
394
-		// Fetch reminder days.
395
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
396
-
397
-		// Abort if non is set.
398
-		if ( empty( $reminder_days ) ) {
399
-			return;
400
-		}
401
-
402
-		// Retrieve date query.
403
-		$date_query = $this->get_date_query( $reminder_days );
404
-
405
-		// Invoices table.
406
-		$table = $wpdb->prefix . 'getpaid_invoices';
407
-
408
-		// Fetch invoices.
409
-		$invoices  = $wpdb->get_col(
410
-			"SELECT posts.ID FROM $wpdb->posts as posts
374
+    /**
375
+     * (Force) Sends overdue notices.
376
+     *
377
+     * @param WPInv_Invoice $invoice
378
+     */
379
+    public function force_send_overdue_notice( $invoice ) {
380
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
381
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
382
+    }
383
+
384
+    /**
385
+     * Sends overdue notices.
386
+     *
387
+     * @TODO: Create an invoices query class.
388
+     */
389
+    public function overdue() {
390
+        global $wpdb;
391
+
392
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
393
+
394
+        // Fetch reminder days.
395
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
396
+
397
+        // Abort if non is set.
398
+        if ( empty( $reminder_days ) ) {
399
+            return;
400
+        }
401
+
402
+        // Retrieve date query.
403
+        $date_query = $this->get_date_query( $reminder_days );
404
+
405
+        // Invoices table.
406
+        $table = $wpdb->prefix . 'getpaid_invoices';
407
+
408
+        // Fetch invoices.
409
+        $invoices  = $wpdb->get_col(
410
+            "SELECT posts.ID FROM $wpdb->posts as posts
411 411
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
412 412
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
413 413
 
414
-		foreach ( $invoices as $invoice ) {
414
+        foreach ( $invoices as $invoice ) {
415 415
 
416
-			// Only send this email for invoices created via the admin page.
417
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
418
-				$invoice       = new WPInv_Invoice( $invoice );
419
-				$email->object = $invoice;
416
+            // Only send this email for invoices created via the admin page.
417
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
418
+                $invoice       = new WPInv_Invoice( $invoice );
419
+                $email->object = $invoice;
420 420
 
421
-				if ( $invoice->needs_payment() ) {
422
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
423
-				}
421
+                if ( $invoice->needs_payment() ) {
422
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
423
+                }
424 424
 
425
-			}
425
+            }
426 426
 
427
-		}
427
+        }
428 428
 
429
-	}
429
+    }
430 430
 
431
-	/**
432
-	 * Calculates the date query for an invoices query
433
-	 *
434
-	 * @param array $reminder_days
435
-	 * @return string
436
-	 */
437
-	public function get_date_query( $reminder_days ) {
431
+    /**
432
+     * Calculates the date query for an invoices query
433
+     *
434
+     * @param array $reminder_days
435
+     * @return string
436
+     */
437
+    public function get_date_query( $reminder_days ) {
438 438
 
439
-		$date_query = array(
440
-			'relation'  => 'OR'
441
-		);
439
+        $date_query = array(
440
+            'relation'  => 'OR'
441
+        );
442 442
 
443
-		foreach ( $reminder_days as $days ) {
444
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
443
+        foreach ( $reminder_days as $days ) {
444
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
445 445
 
446
-			$date_query[] = array(
447
-				'year'  => $date['year'],
448
-				'month' => $date['month'],
449
-				'day'   => $date['day'],
450
-			);
446
+            $date_query[] = array(
447
+                'year'  => $date['year'],
448
+                'month' => $date['month'],
449
+                'day'   => $date['day'],
450
+            );
451 451
 
452
-		}
452
+        }
453 453
 
454
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
454
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
455 455
 
456
-		return $date_query->get_sql();
456
+        return $date_query->get_sql();
457 457
 
458
-	}
458
+    }
459 459
 
460 460
 }
Please login to merge, or discard this patch.