Completed
Push — master ( e1fcb8...b01a52 )
by Brian
26s queued 17s
created
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -14,61 +14,61 @@  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;
67 67
 
68 68
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
69 69
 
70 70
         if ( ! empty( $current_screen->post_type ) ) {
71
-			$page = $current_screen->post_type;
71
+            $page = $current_screen->post_type;
72 72
         }
73 73
 
74 74
         // General styles.
@@ -92,30 +92,30 @@  discard block
 block discarded – undo
92 92
         }
93 93
 
94 94
         // Payment form scripts.
95
-		if ( 'wpi_payment_form' == $page ) {
95
+        if ( 'wpi_payment_form' == $page ) {
96 96
             $this->load_payment_form_scripts();
97 97
         }
98 98
 
99 99
         if ( $page == 'wpinv-subscriptions' ) {
100
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
101
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
102
-		}
100
+            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
101
+            wp_enqueue_script( 'wpinv-sub-admin-script' );
102
+        }
103 103
 
104
-		if ( $page == 'wpinv-reports' ) {
105
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
106
-		}
104
+        if ( $page == 'wpinv-reports' ) {
105
+            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
106
+        }
107 107
 
108
-		if ( $page == 'wpinv-subscriptions' ) {
109
-			wp_enqueue_script( 'postbox' );
110
-		}
108
+        if ( $page == 'wpinv-subscriptions' ) {
109
+            wp_enqueue_script( 'postbox' );
110
+        }
111 111
 
112 112
     }
113 113
 
114 114
     /**
115
-	 * Returns admin js translations.
116
-	 *
117
-	 */
118
-	protected function get_admin_i18() {
115
+     * Returns admin js translations.
116
+     *
117
+     */
118
+    protected function get_admin_i18() {
119 119
         global $post;
120 120
 
121 121
         return array(
@@ -156,33 +156,33 @@  discard block
 block discarded – undo
156 156
     }
157 157
 
158 158
     /**
159
-	 * Loads payment form js.
160
-	 *
161
-	 */
162
-	protected function load_payment_form_scripts() {
159
+     * Loads payment form js.
160
+     *
161
+     */
162
+    protected function load_payment_form_scripts() {
163 163
         global $post;
164 164
 
165 165
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
166
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
167
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
166
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
167
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
168 168
 
169
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
170
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
169
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
170
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
171 171
 
172
-		wp_localize_script(
172
+        wp_localize_script(
173 173
             'wpinv-admin-payment-form-script',
174 174
             'wpinvPaymentFormAdmin',
175 175
             array(
176
-				'elements'      => $this->form_elements->get_elements(),
177
-				'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
178
-				'all_items'     => $this->form_elements->get_published_items(),
179
-				'currency'      => wpinv_currency_symbol(),
180
-				'position'      => wpinv_currency_position(),
181
-				'decimals'      => (int) wpinv_decimals(),
182
-				'thousands_sep' => wpinv_thousands_separator(),
183
-				'decimals_sep'  => wpinv_decimal_separator(),
184
-				'form_items'    => $this->form_elements->get_form_items( $post->ID ),
185
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
176
+                'elements'      => $this->form_elements->get_elements(),
177
+                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
178
+                'all_items'     => $this->form_elements->get_published_items(),
179
+                'currency'      => wpinv_currency_symbol(),
180
+                'position'      => wpinv_currency_position(),
181
+                'decimals'      => (int) wpinv_decimals(),
182
+                'thousands_sep' => wpinv_thousands_separator(),
183
+                'decimals_sep'  => wpinv_decimal_separator(),
184
+                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
185
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
186 186
             )
187 187
         );
188 188
 
@@ -191,20 +191,20 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-	 * Add our classes to admin pages.
194
+     * Add our classes to admin pages.
195 195
      *
196 196
      * @param string $classes
197 197
      * @return string
198
-	 *
199
-	 */
198
+     *
199
+     */
200 200
     public function admin_body_class( $classes ) {
201
-		global $pagenow, $post, $current_screen;
201
+        global $pagenow, $post, $current_screen;
202 202
 
203 203
 
204 204
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
205 205
 
206 206
         if ( ! empty( $current_screen->post_type ) ) {
207
-			$page = $current_screen->post_type;
207
+            $page = $current_screen->post_type;
208 208
         }
209 209
 
210 210
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -215,27 +215,27 @@  discard block
 block discarded – undo
215 215
             $classes .= ' wpinv-cpt wpinv';
216 216
         }
217 217
 
218
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
219
-			$classes .= ' wpi-editable-n';
220
-		}
218
+        if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
219
+            $classes .= ' wpi-editable-n';
220
+        }
221 221
 
222
-		return $classes;
222
+        return $classes;
223 223
     }
224 224
 
225 225
     /**
226
-	 * Maybe show the AyeCode Connect Notice.
227
-	 */
228
-	public function init_ayecode_connect_helper(){
226
+     * Maybe show the AyeCode Connect Notice.
227
+     */
228
+    public function init_ayecode_connect_helper(){
229 229
 
230 230
         new AyeCode_Connect_Helper(
231 231
             array(
232
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
-				'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>" ),
235
-				'connect_button'    => __("Connect Site","invoicing"),
236
-				'connecting_button'    => __("Connecting...","invoicing"),
237
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
232
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
+                '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>" ),
235
+                'connect_button'    => __("Connect Site","invoicing"),
236
+                'connecting_button'    => __("Connecting...","invoicing"),
237
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
239 239
             ),
240 240
             array( 'wpi-addons' )
241 241
         );
@@ -247,21 +247,21 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function activation_redirect() {
249 249
 
250
-		// Bail if no activation redirect.
251
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || is_ajax() ) {
252
-			return;
253
-		}
250
+        // Bail if no activation redirect.
251
+        if ( ! get_transient( '_wpinv_activation_redirect' ) || is_ajax() ) {
252
+            return;
253
+        }
254 254
 
255
-		// Delete the redirect transient.
256
-		delete_transient( '_wpinv_activation_redirect' );
255
+        // Delete the redirect transient.
256
+        delete_transient( '_wpinv_activation_redirect' );
257 257
 
258
-		// Bail if activating from network, or bulk
259
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
260
-			return;
261
-		}
258
+        // Bail if activating from network, or bulk
259
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
260
+            return;
261
+        }
262 262
 
263
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
264
-		exit;
263
+        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
264
+        exit;
265 265
     }
266 266
 
267 267
     /**
@@ -276,150 +276,150 @@  discard block
 block discarded – undo
276 276
 
277 277
     }
278 278
 
279
-	/**
279
+    /**
280 280
      * Sends a payment reminder to a customer.
281
-	 * 
282
-	 * @param array $args
281
+     * 
282
+     * @param array $args
283 283
      */
284 284
     public function send_customer_invoice( $args ) {
285
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
285
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
286 286
 
287
-		if ( $sent ) {
288
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
289
-		} else {
290
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
291
-		}
287
+        if ( $sent ) {
288
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
289
+        } else {
290
+            $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
291
+        }
292 292
 
293
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
294
-		exit;
295
-	}
293
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
294
+        exit;
295
+    }
296 296
 
297
-	/**
297
+    /**
298 298
      * Sends a payment reminder to a customer.
299
-	 * 
300
-	 * @param array $args
299
+     * 
300
+     * @param array $args
301 301
      */
302 302
     public function send_customer_payment_reminder( $args ) {
303
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
303
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
304 304
 
305
-		if ( $sent ) {
306
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
307
-		} else {
308
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
309
-		}
305
+        if ( $sent ) {
306
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
307
+        } else {
308
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
309
+        }
310 310
 
311
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
312
-		exit;
313
-	}
311
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
312
+        exit;
313
+    }
314 314
 
315 315
     /**
316
-	 * Returns an array of admin notices.
317
-	 *
318
-	 * @since       1.0.19
316
+     * Returns an array of admin notices.
317
+     *
318
+     * @since       1.0.19
319 319
      * @return array
320
-	 */
321
-	public function get_notices() {
322
-		$notices = get_option( 'wpinv_admin_notices' );
320
+     */
321
+    public function get_notices() {
322
+        $notices = get_option( 'wpinv_admin_notices' );
323 323
         return is_array( $notices ) ? $notices : array();
324
-	}
325
-
326
-	/**
327
-	 * Clears all admin notices
328
-	 *
329
-	 * @access      public
330
-	 * @since       1.0.19
331
-	 */
332
-	public function clear_notices() {
333
-		delete_option( 'wpinv_admin_notices' );
334
-	}
335
-
336
-	/**
337
-	 * Saves a new admin notice
338
-	 *
339
-	 * @access      public
340
-	 * @since       1.0.19
341
-	 */
342
-	public function save_notice( $type, $message ) {
343
-		$notices = $this->get_notices();
344
-
345
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
-			$notices[ $type ] = array();
347
-		}
348
-
349
-		$notices[ $type ][] = $message;
350
-
351
-		update_option( 'wpinv_admin_notices', $notices );
352
-	}
353
-
354
-	/**
355
-	 * Displays a success notice
356
-	 *
357
-	 * @param       string $msg The message to qeue.
358
-	 * @access      public
359
-	 * @since       1.0.19
360
-	 */
361
-	public function show_success( $msg ) {
362
-		$this->save_notice( 'success', $msg );
363
-	}
364
-
365
-	/**
366
-	 * Displays a error notice
367
-	 *
368
-	 * @access      public
369
-	 * @param       string $msg The message to qeue.
370
-	 * @since       1.0.19
371
-	 */
372
-	public function show_error( $msg ) {
373
-		$this->save_notice( 'error', $msg );
374
-	}
375
-
376
-	/**
377
-	 * Displays a warning notice
378
-	 *
379
-	 * @access      public
380
-	 * @param       string $msg The message to qeue.
381
-	 * @since       1.0.19
382
-	 */
383
-	public function show_warning( $msg ) {
384
-		$this->save_notice( 'warning', $msg );
385
-	}
386
-
387
-	/**
388
-	 * Displays a info notice
389
-	 *
390
-	 * @access      public
391
-	 * @param       string $msg The message to qeue.
392
-	 * @since       1.0.19
393
-	 */
394
-	public function show_info( $msg ) {
395
-		$this->save_notice( 'info', $msg );
396
-	}
397
-
398
-	/**
399
-	 * Show notices
400
-	 *
401
-	 * @access      public
402
-	 * @since       1.0.19
403
-	 */
404
-	public function show_notices() {
324
+    }
325
+
326
+    /**
327
+     * Clears all admin notices
328
+     *
329
+     * @access      public
330
+     * @since       1.0.19
331
+     */
332
+    public function clear_notices() {
333
+        delete_option( 'wpinv_admin_notices' );
334
+    }
335
+
336
+    /**
337
+     * Saves a new admin notice
338
+     *
339
+     * @access      public
340
+     * @since       1.0.19
341
+     */
342
+    public function save_notice( $type, $message ) {
343
+        $notices = $this->get_notices();
344
+
345
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
+            $notices[ $type ] = array();
347
+        }
348
+
349
+        $notices[ $type ][] = $message;
350
+
351
+        update_option( 'wpinv_admin_notices', $notices );
352
+    }
353
+
354
+    /**
355
+     * Displays a success notice
356
+     *
357
+     * @param       string $msg The message to qeue.
358
+     * @access      public
359
+     * @since       1.0.19
360
+     */
361
+    public function show_success( $msg ) {
362
+        $this->save_notice( 'success', $msg );
363
+    }
364
+
365
+    /**
366
+     * Displays a error notice
367
+     *
368
+     * @access      public
369
+     * @param       string $msg The message to qeue.
370
+     * @since       1.0.19
371
+     */
372
+    public function show_error( $msg ) {
373
+        $this->save_notice( 'error', $msg );
374
+    }
375
+
376
+    /**
377
+     * Displays a warning notice
378
+     *
379
+     * @access      public
380
+     * @param       string $msg The message to qeue.
381
+     * @since       1.0.19
382
+     */
383
+    public function show_warning( $msg ) {
384
+        $this->save_notice( 'warning', $msg );
385
+    }
386
+
387
+    /**
388
+     * Displays a info notice
389
+     *
390
+     * @access      public
391
+     * @param       string $msg The message to qeue.
392
+     * @since       1.0.19
393
+     */
394
+    public function show_info( $msg ) {
395
+        $this->save_notice( 'info', $msg );
396
+    }
397
+
398
+    /**
399
+     * Show notices
400
+     *
401
+     * @access      public
402
+     * @since       1.0.19
403
+     */
404
+    public function show_notices() {
405 405
 
406 406
         $notices = $this->get_notices();
407 407
         $this->clear_notices();
408 408
 
409
-		foreach ( $notices as $type => $messages ) {
409
+        foreach ( $notices as $type => $messages ) {
410 410
 
411
-			if ( ! is_array( $messages ) ) {
412
-				continue;
413
-			}
411
+            if ( ! is_array( $messages ) ) {
412
+                continue;
413
+            }
414 414
 
415 415
             $type  = sanitize_key( $type );
416
-			foreach ( $messages as $message ) {
416
+            foreach ( $messages as $message ) {
417 417
                 $message = wp_kses_post( $message );
418
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
418
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
419 419
             }
420 420
 
421 421
         }
422 422
 
423
-	}
423
+    }
424 424
 
425 425
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 1 patch
Indentation   +613 added lines, -613 removed lines patch added patch discarded remove patch
@@ -13,614 +13,614 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-
29
-		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
32
-
33
-		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
40
-
41
-		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
-
46
-		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
48
-
49
-		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
-	}
53
-
54
-	/**
55
-	 * Post updated messages.
56
-	 */
57
-	public static function post_updated_messages( $messages ) {
58
-		global $post;
59
-
60
-		$messages['wpi_discount'] = array(
61
-			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
72
-		);
73
-
74
-		$messages['wpi_payment_form'] = array(
75
-			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
-		);
87
-
88
-		return $messages;
89
-
90
-	}
91
-
92
-	/**
93
-	 * Post row actions.
94
-	 */
95
-	public static function post_row_actions( $actions, $post ) {
96
-
97
-		$post = get_post( $post );
98
-
99
-		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
103
-		}
104
-
105
-		return $actions;
106
-	}
107
-
108
-	/**
109
-	 * Returns an array of invoice table columns.
110
-	 */
111
-	public static function invoice_columns( $columns ) {
112
-
113
-		$columns = array(
114
-			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
-		);
123
-
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
125
-	}
126
-
127
-	/**
128
-	 * Displays invoice table columns.
129
-	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
131
-
132
-		$invoice = new WPInv_Invoice( $post_id );
133
-
134
-		switch ( $column_name ) {
135
-
136
-			case 'invoice_date' :
137
-				$date_time = sanitize_text_field( $invoice->get_created_date() );
138
-				$date      = mysql2date( get_option( 'date_format' ), $date_time );
139
-				echo "<span title='$date_time'>$date</span>";
140
-				break;
141
-
142
-			case 'amount' :
143
-
144
-				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
-
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
-					echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150
-				} else {
151
-
152
-					$discount = $invoice->get_total_discount();
153
-
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
-						echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157
-					} else {
158
-						echo $formated_amount;
159
-					}
160
-
161
-				}
162
-
163
-				break;
164
-
165
-			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
-
169
-				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
173 19
 
174
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
-				} else {
176
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
-				}
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
178 22
 
179
-				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
181 25
 
182
-					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
-					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
-					}
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
188 28
 
189
-					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
191
-						$due_date = $invoice->get_due_date();
29
+        // Invoice table columns.
30
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
192 32
 
193
-						if ( ! empty( $due_date ) ) {
194
-							$date = mysql2date( get_option( 'date_format' ), $due_date );
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date );
196
-							echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>";
197
-						}
198
-					}
33
+        // Items table columns.
34
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
199 40
 
200
-				}
41
+        // Payment forms columns.
42
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
201 45
 
202
-				break;
46
+        // Discount table columns.
47
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
203 48
 
204
-			case 'recurring':
49
+        // Deleting posts.
50
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
+    }
205 53
 
206
-				if ( $invoice->is_recurring() ) {
207
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
-				} else {
209
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
-				}
211
-				break;
54
+    /**
55
+     * Post updated messages.
56
+     */
57
+    public static function post_updated_messages( $messages ) {
58
+        global $post;
59
+
60
+        $messages['wpi_discount'] = array(
61
+            0   => '',
62
+            1   => __( 'Discount updated.', 'invoicing' ),
63
+            2   => __( 'Custom field updated.', 'invoicing' ),
64
+            3   => __( 'Custom field deleted.', 'invoicing' ),
65
+            4   => __( 'Discount updated.', 'invoicing' ),
66
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
+            6   => __( 'Discount updated.', 'invoicing' ),
68
+            7   => __( 'Discount saved.', 'invoicing' ),
69
+            8   => __( 'Discount submitted.', 'invoicing' ),
70
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
+            10  => __( 'Discount draft updated.', 'invoicing' ),
72
+        );
73
+
74
+        $messages['wpi_payment_form'] = array(
75
+            0   => '',
76
+            1   => __( 'Payment Form updated.', 'invoicing' ),
77
+            2   => __( 'Custom field updated.', 'invoicing' ),
78
+            3   => __( 'Custom field deleted.', 'invoicing' ),
79
+            4   => __( 'Payment Form updated.', 'invoicing' ),
80
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
+            6   => __( 'Payment Form updated.', 'invoicing' ),
82
+            7   => __( 'Payment Form saved.', 'invoicing' ),
83
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
84
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
+        );
87
+
88
+        return $messages;
89
+
90
+    }
91
+
92
+    /**
93
+     * Post row actions.
94
+     */
95
+    public static function post_row_actions( $actions, $post ) {
96
+
97
+        $post = get_post( $post );
98
+
99
+        // We do not want to edit the default payment form.
100
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
+            unset( $actions['trash'] );
102
+            unset( $actions['inline hide-if-no-js'] );
103
+        }
104
+
105
+        return $actions;
106
+    }
107
+
108
+    /**
109
+     * Returns an array of invoice table columns.
110
+     */
111
+    public static function invoice_columns( $columns ) {
112
+
113
+        $columns = array(
114
+            'cb'                => $columns['cb'],
115
+            'number'            => __( 'Invoice', 'invoicing' ),
116
+            'customer'          => __( 'Customer', 'invoicing' ),
117
+            'invoice_date'      => __( 'Date', 'invoicing' ),
118
+            'amount'            => __( 'Amount', 'invoicing' ),
119
+            'recurring'         => __( 'Recurring', 'invoicing' ),
120
+            'status'            => __( 'Status', 'invoicing' ),
121
+            'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
+        );
123
+
124
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
125
+    }
126
+
127
+    /**
128
+     * Displays invoice table columns.
129
+     */
130
+    public static function display_invoice_columns( $column_name, $post_id ) {
131
+
132
+        $invoice = new WPInv_Invoice( $post_id );
133
+
134
+        switch ( $column_name ) {
135
+
136
+            case 'invoice_date' :
137
+                $date_time = sanitize_text_field( $invoice->get_created_date() );
138
+                $date      = mysql2date( get_option( 'date_format' ), $date_time );
139
+                echo "<span title='$date_time'>$date</span>";
140
+                break;
141
+
142
+            case 'amount' :
143
+
144
+                $amount = $invoice->get_total();
145
+                $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
+
147
+                if ( $invoice->is_refunded() ) {
148
+                    $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
+                    echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150
+                } else {
151
+
152
+                    $discount = $invoice->get_total_discount();
153
+
154
+                    if ( ! empty( $discount ) ) {
155
+                        $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
+                        echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157
+                    } else {
158
+                        echo $formated_amount;
159
+                    }
160
+
161
+                }
162
+
163
+                break;
164
+
165
+            case 'status' :
166
+                $status       = sanitize_text_field( $invoice->get_status() );
167
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
+
169
+                // If it is paid, show the gateway title.
170
+                if ( $invoice->is_paid() ) {
171
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
212 173
 
213
-			case 'number' :
174
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
+                } else {
176
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
+                }
214 178
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
179
+                // If it is not paid, display the overdue and view status.
180
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
218 181
 
219
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
182
+                    // Invoice view status.
183
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
+                    } else {
186
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
+                    }
220 188
 
221
-				break;
189
+                    // Display the overview status.
190
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
191
+                        $due_date = $invoice->get_due_date();
222 192
 
223
-			case 'customer' :
193
+                        if ( ! empty( $due_date ) ) {
194
+                            $date = mysql2date( get_option( 'date_format' ), $due_date );
195
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date );
196
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>";
197
+                        }
198
+                    }
199
+
200
+                }
201
+
202
+                break;
203
+
204
+            case 'recurring':
205
+
206
+                if ( $invoice->is_recurring() ) {
207
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
+                } else {
209
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
+                }
211
+                break;
212
+
213
+            case 'number' :
214
+
215
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
217
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
218
+
219
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220
+
221
+                break;
222
+
223
+            case 'customer' :
224 224
 	
225
-				$customer_name = $invoice->get_user_full_name();
225
+                $customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
228
-					$customer_name = $invoice->get_email();
229
-				}
227
+                if ( empty( $customer_name ) ) {
228
+                    $customer_name = $invoice->get_email();
229
+                }
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
-				} else {
236
-					echo '<div>&mdash;</div>';
237
-				}
231
+                if ( ! empty( $customer_name ) ) {
232
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
+                } else {
236
+                    echo '<div>&mdash;</div>';
237
+                }
238
+
239
+                break;
240
+
241
+            case 'wpi_actions' :
242
+
243
+                if ( $invoice->is_draft() ) {
244
+                    return;
245
+                }
246
+
247
+                $url    = esc_url( $invoice->get_view_url() );
248
+                $print  = esc_attr__( 'Print invoice', 'invoicing' );
249
+                echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250
+
251
+                $url    = esc_url(
252
+                    wp_nonce_url(
253
+                        add_query_arg(
254
+                            array(
255
+                                'getpaid-admin-action' => 'send_invoice',
256
+                                'invoice_id'           => $invoice->get_id()
257
+                            )
258
+                        ),
259
+                        'getpaid-nonce',
260
+                        'getpaid-nonce'
261
+                    )
262
+                );
263
+
264
+                $send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
+                echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266
+
267
+                break;
268
+        }
238 269
 
239
-				break;
270
+    }
240 271
 
241
-			case 'wpi_actions' :
242
-
243
-				if ( $invoice->is_draft() ) {
244
-					return;
245
-				}
246
-
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
249
-				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
272
+    /**
273
+     * Returns an array of payment forms table columns.
274
+     */
275
+    public static function payment_form_columns( $columns ) {
250 276
 
251
-				$url    = esc_url(
252
-					wp_nonce_url(
253
-						add_query_arg(
254
-							array(
255
-								'getpaid-admin-action' => 'send_invoice',
256
-								'invoice_id'           => $invoice->get_id()
257
-							)
258
-						),
259
-						'getpaid-nonce',
260
-						'getpaid-nonce'
261
-					)
262
-				);
277
+        $columns = array(
278
+            'cb'                => $columns['cb'],
279
+            'title'             => __( 'Name', 'invoicing' ),
280
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
+            'earnings'          => __( 'Revenue', 'invoicing' ),
282
+            'refunds'           => __( 'Refunded', 'invoicing' ),
283
+            'items'             => __( 'Items', 'invoicing' ),
284
+            'date'              => __( 'Date', 'invoicing' ),
285
+        );
263 286
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
-				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
287
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
266 288
 
267
-				break;
268
-		}
289
+    }
269 290
 
270
-	}
291
+    /**
292
+     * Displays payment form table columns.
293
+     */
294
+    public static function display_payment_form_columns( $column_name, $post_id ) {
271 295
 
272
-	/**
273
-	 * Returns an array of payment forms table columns.
274
-	 */
275
-	public static function payment_form_columns( $columns ) {
296
+        // Retrieve the payment form.
297
+        $form = new GetPaid_Payment_Form( $post_id );
276 298
 
277
-		$columns = array(
278
-			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
285
-		);
299
+        switch ( $column_name ) {
286 300
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
301
+            case 'earnings' :
302
+                echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
+                break;
288 304
 
289
-	}
305
+            case 'refunds' :
306
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
+                break;
290 308
 
291
-	/**
292
-	 * Displays payment form table columns.
293
-	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
309
+            case 'refunds' :
310
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
+                break;
295 312
 
296
-		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
313
+            case 'shortcode' :
298 314
 
299
-		switch ( $column_name ) {
315
+                if ( $form->is_default() ) {
316
+                    echo '&mdash;';
317
+                } else {
318
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
+                }
300 320
 
301
-			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
-				break;
321
+                break;
304 322
 
305
-			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
-				break;
323
+            case 'items' :
308 324
 
309
-			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
-				break;
325
+                $items = $form->get_items();
312 326
 
313
-			case 'shortcode' :
327
+                if ( $form->is_default() || empty( $items ) ) {
328
+                    echo '&mdash;';
329
+                    return;
330
+                }
314 331
 
315
-				if ( $form->is_default() ) {
316
-					echo '&mdash;';
317
-				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
-				}
332
+                $_items = array();
320 333
 
321
-				break;
334
+                foreach ( $items as $item ) {
335
+                    $url = $item->get_edit_url();
322 336
 
323
-			case 'items' :
337
+                    if ( empty( $url ) ) {
338
+                        $_items[] = sanitize_text_field( $item->get_name() );
339
+                    } else {
340
+                        $_items[] = sprintf(
341
+                            '<a href="%s">%s</a>',
342
+                            esc_url( $url ),
343
+                            sanitize_text_field( $item->get_name() )
344
+                        );
345
+                    }
324 346
 
325
-				$items = $form->get_items();
347
+                }
326 348
 
327
-				if ( $form->is_default() || empty( $items ) ) {
328
-					echo '&mdash;';
329
-					return;
330
-				}
349
+                echo implode( '<br>', $_items );
331 350
 
332
-				$_items = array();
351
+                break;
333 352
 
334
-				foreach ( $items as $item ) {
335
-					$url = $item->get_edit_url();
353
+        }
336 354
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
339
-					} else {
340
-						$_items[] = sprintf(
341
-							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
344
-						);
345
-					}
355
+    }
346 356
 
347
-				}
357
+    /**
358
+     * Filters post states.
359
+     */
360
+    public static function filter_payment_form_state( $post_states, $post ) {
348 361
 
349
-				echo implode( '<br>', $_items );
362
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
+        }
365
+	
366
+        return $post_states;
350 367
 
351
-				break;
368
+    }
352 369
 
353
-		}
370
+    /**
371
+     * Returns an array of coupon table columns.
372
+     */
373
+    public static function discount_columns( $columns ) {
374
+
375
+        $columns = array(
376
+            'cb'                => $columns['cb'],
377
+            'title'             => __( 'Name', 'invoicing' ),
378
+            'code'              => __( 'Code', 'invoicing' ),
379
+            'amount'            => __( 'Amount', 'invoicing' ),
380
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
+            'start_date'        => __( 'Start Date', 'invoicing' ),
382
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
+        );
384
+
385
+        return apply_filters( 'wpi_discount_table_columns', $columns );
386
+    }
354 387
 
355
-	}
388
+    /**
389
+     * Filters post states.
390
+     */
391
+    public static function filter_discount_state( $post_states, $post ) {
356 392
 
357
-	/**
358
-	 * Filters post states.
359
-	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
393
+        if ( 'wpi_discount' == $post->post_type ) {
361 394
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
-		}
365
-	
366
-		return $post_states;
395
+            $discount = new WPInv_Discount( $post );
367 396
 
368
-	}
397
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
369 398
 
370
-	/**
371
-	 * Returns an array of coupon table columns.
372
-	 */
373
-	public static function discount_columns( $columns ) {
399
+            if ( $status != 'publish' ) {
400
+                return array(
401
+                    'discount_status' => wpinv_discount_status( $status ),
402
+                );
403
+            }
374 404
 
375
-		$columns = array(
376
-			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
-		);
405
+            return array();
384 406
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
386
-	}
407
+        }
387 408
 
388
-	/**
389
-	 * Filters post states.
390
-	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
409
+        return $post_states;
392 410
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
411
+    }
394 412
 
395
-			$discount = new WPInv_Discount( $post );
413
+    /**
414
+     * Returns an array of items table columns.
415
+     */
416
+    public static function item_columns( $columns ) {
417
+        global $wpinv_euvat;
418
+
419
+        $columns = array(
420
+            'cb'                => $columns['cb'],
421
+            'title'             => __( 'Name', 'invoicing' ),
422
+            'price'             => __( 'Price', 'invoicing' ),
423
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
425
+            'type'              => __( 'Type', 'invoicing' ),
426
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
+        );
428
+
429
+        if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
+            unset( $columns['vat_rule'] );
431
+        }
396 432
 
397
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
433
+        if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
+            unset( $columns['vat_class'] );
435
+        }
398 436
 
399
-			if ( $status != 'publish' ) {
400
-				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
402
-				);
403
-			}
437
+        return apply_filters( 'wpi_item_table_columns', $columns );
438
+    }
404 439
 
405
-			return array();
440
+    /**
441
+     * Returns an array of sortable items table columns.
442
+     */
443
+    public static function sortable_item_columns( $columns ) {
444
+
445
+        return array_merge(
446
+            $columns,
447
+            array(
448
+                'price'     => 'price',
449
+                'vat_rule'  => 'vat_rule',
450
+                'vat_class' => 'vat_class',
451
+                'type'      => 'type',
452
+            )
453
+        );
454
+
455
+    }
406 456
 
407
-		}
457
+    /**
458
+     * Displays items table columns.
459
+     */
460
+    public static function display_item_columns( $column_name, $post_id ) {
461
+        global $wpinv_euvat;
408 462
 
409
-		return $post_states;
463
+        $item = new WPInv_Item( $post_id );
410 464
 
411
-	}
465
+        switch ( $column_name ) {
412 466
 
413
-	/**
414
-	 * Returns an array of items table columns.
415
-	 */
416
-	public static function item_columns( $columns ) {
417
-		global $wpinv_euvat;
467
+            case 'price' :
418 468
 
419
-		$columns = array(
420
-			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
-		);
469
+                if ( ! $item->is_recurring() ) {
470
+                    echo $item->get_the_price();
471
+                    break;
472
+                }
428 473
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
431
-		}
474
+                $price = wp_sprintf(
475
+                    __( '%s / %s', 'invoicing' ),
476
+                    $item->get_the_price(),
477
+                    WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() )
478
+                );
432 479
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
435
-		}
480
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
+                    echo $price;
482
+                    break;
483
+                }
436 484
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
438
-	}
485
+                echo $item->get_the_initial_price();
439 486
 
440
-	/**
441
-	 * Returns an array of sortable items table columns.
442
-	 */
443
-	public static function sortable_item_columns( $columns ) {
487
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
+                break;
444 489
 
445
-		return array_merge(
446
-			$columns,
447
-			array(
448
-				'price'     => 'price',
449
-				'vat_rule'  => 'vat_rule',
450
-				'vat_class' => 'vat_class',
451
-				'type'      => 'type',
452
-			)
453
-		);
490
+            case 'vat_rule' :
491
+                echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
+                break;
454 493
 
455
-	}
494
+            case 'vat_class' :
495
+                echo $wpinv_euvat->item_class_label( $item->get_id() );
496
+                break;
456 497
 
457
-	/**
458
-	 * Displays items table columns.
459
-	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
461
-		global $wpinv_euvat;
498
+            case 'shortcode' :
499
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
+                break;
462 501
 
463
-		$item = new WPInv_Item( $post_id );
502
+            case 'type' :
503
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
+                break;
464 505
 
465
-		switch ( $column_name ) {
506
+        }
466 507
 
467
-			case 'price' :
508
+    }
468 509
 
469
-				if ( ! $item->is_recurring() ) {
470
-					echo $item->get_the_price();
471
-					break;
472
-				}
510
+    /**
511
+     * Lets users filter items using taxes.
512
+     */
513
+    public static function add_item_filters( $post_type ) {
514
+        global $wpinv_euvat;
515
+
516
+        // Abort if we're not dealing with items.
517
+        if ( $post_type != 'wpi_item' ) {
518
+            return;
519
+        }
520
+
521
+        // Filter by vat rules.
522
+        if ( $wpinv_euvat->allow_vat_rules() ) {
523
+	
524
+            // Sanitize selected vat rule.
525
+            $vat_rule   = '';
526
+            if ( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) {
527
+                $vat_rule   =  $_GET['vat_rule'];
528
+            }
529
+
530
+            // Filter by VAT rule.
531
+            echo wpinv_html_select(
532
+                array(
533
+                    'options'          => array_merge(
534
+                        array(
535
+                            '' => __( 'All VAT rules', 'invoicing' )
536
+                        ),
537
+                        $wpinv_euvat->get_rules()
538
+                    ),
539
+                    'name'             => 'vat_rule',
540
+                    'id'               => 'vat_rule',
541
+                    'selected'         => $vat_rule,
542
+                    'show_option_all'  => false,
543
+                    'show_option_none' => false,
544
+                    'class'            => 'gdmbx2-text-medium',
545
+                )
546
+            );
547
+
548
+            // Filter by VAT class.
549
+        }
473 550
 
474
-				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
476
-					$item->get_the_price(),
477
-					WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() )
478
-				);
551
+        // Filter by vat class.
552
+        if ( $wpinv_euvat->allow_vat_classes() ) {
553
+	
554
+            // Sanitize selected vat rule.
555
+            $vat_class   = '';
556
+            if ( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) {
557
+                $vat_class   =  $_GET['vat_class'];
558
+            }
559
+
560
+            echo wpinv_html_select(
561
+                array(
562
+                    'options'          => array_merge(
563
+                        array(
564
+                            '' => __( 'All VAT classes', 'invoicing' )
565
+                        ),
566
+                        $wpinv_euvat->get_all_classes()
567
+                    ),
568
+                    'name'             => 'vat_class',
569
+                    'id'               => 'vat_class',
570
+                    'selected'         => $vat_class,
571
+                    'show_option_all'  => false,
572
+                    'show_option_none' => false,
573
+                    'class'            => 'gdmbx2-text-medium',
574
+                )
575
+            );
479 576
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
-					echo $price;
482
-					break;
483
-				}
577
+        }
484 578
 
485
-				echo $item->get_the_initial_price();
579
+        // Filter by item type.
580
+        $type   = '';
581
+        if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
582
+            $type   =  $_GET['type'];
583
+        }
486 584
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
-				break;
585
+        echo wpinv_html_select(
586
+            array(
587
+                'options'          => array_merge(
588
+                    array(
589
+                        '' => __( 'All item types', 'invoicing' )
590
+                    ),
591
+                    wpinv_get_item_types()
592
+                ),
593
+                'name'             => 'type',
594
+                'id'               => 'type',
595
+                'selected'         => $type,
596
+                'show_option_all'  => false,
597
+                'show_option_none' => false,
598
+                'class'            => 'gdmbx2-text-medium',
599
+            )
600
+        );
601
+
602
+    }
489 603
 
490
-			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
-				break;
604
+    /**
605
+     * Filters the item query.
606
+     */
607
+    public static function filter_item_query( $query ) {
493 608
 
494
-			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
496
-				break;
609
+        // modify the query only if it admin and main query.
610
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
611
+            return $query;
612
+        }
497 613
 
498
-			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
-				break;
614
+        // we want to modify the query for our items.
615
+        if ( 'wpi_item' != $query->query['post_type'] ){
616
+            return $query;
617
+        }
501 618
 
502
-			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
-				break;
619
+        if ( empty( $query->query_vars['meta_query'] ) ) {
620
+            $query->query_vars['meta_query'] = array();
621
+        }
505 622
 
506
-		}
507
-
508
-	}
509
-
510
-	/**
511
-	 * Lets users filter items using taxes.
512
-	 */
513
-	public static function add_item_filters( $post_type ) {
514
-		global $wpinv_euvat;
515
-
516
-		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
518
-			return;
519
-		}
520
-
521
-		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
523
-	
524
-			// Sanitize selected vat rule.
525
-			$vat_rule   = '';
526
-			if ( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) {
527
-				$vat_rule   =  $_GET['vat_rule'];
528
-			}
529
-
530
-			// Filter by VAT rule.
531
-			echo wpinv_html_select(
532
-				array(
533
-					'options'          => array_merge(
534
-						array(
535
-							'' => __( 'All VAT rules', 'invoicing' )
536
-						),
537
-						$wpinv_euvat->get_rules()
538
-					),
539
-					'name'             => 'vat_rule',
540
-					'id'               => 'vat_rule',
541
-					'selected'         => $vat_rule,
542
-					'show_option_all'  => false,
543
-					'show_option_none' => false,
544
-					'class'            => 'gdmbx2-text-medium',
545
-				)
546
-			);
547
-
548
-			// Filter by VAT class.
549
-		}
550
-
551
-		// Filter by vat class.
552
-		if ( $wpinv_euvat->allow_vat_classes() ) {
553
-	
554
-			// Sanitize selected vat rule.
555
-			$vat_class   = '';
556
-			if ( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) {
557
-				$vat_class   =  $_GET['vat_class'];
558
-			}
559
-
560
-			echo wpinv_html_select(
561
-				array(
562
-					'options'          => array_merge(
563
-						array(
564
-							'' => __( 'All VAT classes', 'invoicing' )
565
-						),
566
-						$wpinv_euvat->get_all_classes()
567
-					),
568
-					'name'             => 'vat_class',
569
-					'id'               => 'vat_class',
570
-					'selected'         => $vat_class,
571
-					'show_option_all'  => false,
572
-					'show_option_none' => false,
573
-					'class'            => 'gdmbx2-text-medium',
574
-				)
575
-			);
576
-
577
-		}
578
-
579
-		// Filter by item type.
580
-		$type   = '';
581
-		if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
582
-			$type   =  $_GET['type'];
583
-		}
584
-
585
-		echo wpinv_html_select(
586
-			array(
587
-				'options'          => array_merge(
588
-					array(
589
-						'' => __( 'All item types', 'invoicing' )
590
-					),
591
-					wpinv_get_item_types()
592
-				),
593
-				'name'             => 'type',
594
-				'id'               => 'type',
595
-				'selected'         => $type,
596
-				'show_option_all'  => false,
597
-				'show_option_none' => false,
598
-				'class'            => 'gdmbx2-text-medium',
599
-			)
600
-		);
601
-
602
-	}
603
-
604
-	/**
605
-	 * Filters the item query.
606
-	 */
607
-	public static function filter_item_query( $query ) {
608
-
609
-		// modify the query only if it admin and main query.
610
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
611
-			return $query;
612
-		}
613
-
614
-		// we want to modify the query for our items.
615
-		if ( 'wpi_item' != $query->query['post_type'] ){
616
-			return $query;
617
-		}
618
-
619
-		if ( empty( $query->query_vars['meta_query'] ) ) {
620
-			$query->query_vars['meta_query'] = array();
621
-		}
622
-
623
-		// Filter vat rule type
623
+        // Filter vat rule type
624 624
         if ( ! empty( $_GET['vat_rule'] ) ) {
625 625
             $query->query_vars['meta_query'][] = array(
626 626
                 'key'     => '_wpinv_vat_rule',
@@ -645,94 +645,94 @@  discard block
 block discarded – undo
645 645
                 'value'   => sanitize_text_field( $_GET['type'] ),
646 646
                 'compare' => '='
647 647
             );
648
-		}
649
-
650
-	}
651
-
652
-	/**
653
-	 * Reorders items.
654
-	 */
655
-	public static function reorder_items( $vars ) {
656
-		global $typenow;
657
-
658
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
659
-			return $vars;
660
-		}
661
-
662
-		// By item type.
663
-		if ( 'type' == $vars['orderby'] ) {
664
-			return array_merge(
665
-				$vars,
666
-				array(
667
-					'meta_key' => '_wpinv_type',
668
-					'orderby'  => 'meta_value'
669
-				)
670
-			);
671
-		}
672
-
673
-		// By vat class.
674
-		if ( 'vat_class' == $vars['orderby'] ) {
675
-			return array_merge(
676
-				$vars,
677
-				array(
678
-					'meta_key' => '_wpinv_vat_class',
679
-					'orderby'  => 'meta_value'
680
-				)
681
-			);
682
-		}
683
-
684
-		// By vat rule.
685
-		if ( 'vat_rule' == $vars['orderby'] ) {
686
-			return array_merge(
687
-				$vars,
688
-				array(
689
-					'meta_key' => '_wpinv_vat_rule',
690
-					'orderby'  => 'meta_value'
691
-				)
692
-			);
693
-		}
694
-
695
-		// By price.
696
-		if ( 'price' == $vars['orderby'] ) {
697
-			return array_merge(
698
-				$vars,
699
-				array(
700
-					'meta_key' => '_wpinv_price',
701
-					'orderby'  => 'meta_value_num'
702
-				)
703
-			);
704
-		}
705
-
706
-		return $vars;
707
-
708
-	}
709
-
710
-	/**
711
-	 * Fired when deleting a post.
712
-	 */
713
-	public static function delete_post( $post_id ) {
714
-
715
-		switch ( get_post_type( $post_id ) ) {
716
-
717
-			case 'wpi_item' :
718
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
719
-				break;
720
-
721
-			case 'wpi_payment_form' :
722
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
723
-				break;
724
-
725
-			case 'wpi_discount' :
726
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
727
-				break;
728
-
729
-			case 'wpi_invoice' :
730
-				$invoice = new WPInv_Invoice( $post_id );
731
-				do_action( "getpaid_before_delete_invoice", $invoice );
732
-				$invoice->get_data_store()->delete_items( $invoice );
733
-				$invoice->get_data_store()->delete_special_fields( $invoice );
734
-				break;
735
-		}
736
-	}
648
+        }
649
+
650
+    }
651
+
652
+    /**
653
+     * Reorders items.
654
+     */
655
+    public static function reorder_items( $vars ) {
656
+        global $typenow;
657
+
658
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
659
+            return $vars;
660
+        }
661
+
662
+        // By item type.
663
+        if ( 'type' == $vars['orderby'] ) {
664
+            return array_merge(
665
+                $vars,
666
+                array(
667
+                    'meta_key' => '_wpinv_type',
668
+                    'orderby'  => 'meta_value'
669
+                )
670
+            );
671
+        }
672
+
673
+        // By vat class.
674
+        if ( 'vat_class' == $vars['orderby'] ) {
675
+            return array_merge(
676
+                $vars,
677
+                array(
678
+                    'meta_key' => '_wpinv_vat_class',
679
+                    'orderby'  => 'meta_value'
680
+                )
681
+            );
682
+        }
683
+
684
+        // By vat rule.
685
+        if ( 'vat_rule' == $vars['orderby'] ) {
686
+            return array_merge(
687
+                $vars,
688
+                array(
689
+                    'meta_key' => '_wpinv_vat_rule',
690
+                    'orderby'  => 'meta_value'
691
+                )
692
+            );
693
+        }
694
+
695
+        // By price.
696
+        if ( 'price' == $vars['orderby'] ) {
697
+            return array_merge(
698
+                $vars,
699
+                array(
700
+                    'meta_key' => '_wpinv_price',
701
+                    'orderby'  => 'meta_value_num'
702
+                )
703
+            );
704
+        }
705
+
706
+        return $vars;
707
+
708
+    }
709
+
710
+    /**
711
+     * Fired when deleting a post.
712
+     */
713
+    public static function delete_post( $post_id ) {
714
+
715
+        switch ( get_post_type( $post_id ) ) {
716
+
717
+            case 'wpi_item' :
718
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
719
+                break;
720
+
721
+            case 'wpi_payment_form' :
722
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
723
+                break;
724
+
725
+            case 'wpi_discount' :
726
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
727
+                break;
728
+
729
+            case 'wpi_invoice' :
730
+                $invoice = new WPInv_Invoice( $post_id );
731
+                do_action( "getpaid_before_delete_invoice", $invoice );
732
+                $invoice->get_data_store()->delete_items( $invoice );
733
+                $invoice->get_data_store()->delete_special_fields( $invoice );
734
+                break;
735
+        }
736
+    }
737 737
 
738 738
 }
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@
 block discarded – undo
181 181
     $message = wpinv_email_style_body( $message );
182 182
     $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
183 183
 
184
-	return $mailer->send(
184
+    return $mailer->send(
185 185
         $to,
186 186
         $subject,
187 187
         $message,
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +371 added lines, -371 removed lines patch added patch discarded remove patch
@@ -12,423 +12,423 @@
 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'                   => 'new_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_invoice'                   => 'user_invoice',
40
-				'getpaid_new_customer_note'             => 'user_note',
41
-				'getpaid_daily_maintenance'             => 'overdue',
42
-
43
-			)
44
-		);
45
-
46
-		$this->init_hooks();
47
-
48
-	}
49
-
50
-	/**
51
-	 * Registers email hooks.
52
-	 */
53
-	public function init_hooks() {
54
-
55
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
56
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
57
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
58
-
59
-			$email = new GetPaid_Notification_Email( $email_type );
60
-
61
-			if ( ! $email->is_active() ) {
62
-				continue;
63
-			}
64
-
65
-			if ( method_exists( $this, $email_type ) ) {
66
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
67
-				continue;
68
-			}
69
-
70
-			do_action( 'getpaid_invoice_notification_email_register_hook', $email );
71
-
72
-		}
73
-
74
-	}
75
-
76
-	/**
77
-	 * Filters invoice merge tags.
78
-	 *
79
-	 * @param array $merge_tags
80
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
81
-	 */
82
-	public function invoice_merge_tags( $merge_tags, $object ) {
83
-
84
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
85
-			return array_merge(
86
-				$merge_tags,
87
-				$this->get_invoice_merge_tags( $object )
88
-			);
89
-		}
90
-
91
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
92
-			return array_merge(
93
-				$merge_tags,
94
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
95
-			);
96
-		}
97
-
98
-		return $merge_tags;
99
-
100
-	}
101
-
102
-	/**
103
-	 * Generates invoice merge tags.
104
-	 *
105
-	 * @param WPInv_Invoice $invoice
106
-	 * @return array
107
-	 */
108
-	public function get_invoice_merge_tags( $invoice ) {
109
-
110
-		// Abort if it does not exist.
111
-		if ( ! $invoice->get_id() ) {
112
-			return array();
113
-		}
114
-
115
-		return array(
116
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
117
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
118
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
119
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
120
-			'{email}'               => sanitize_email( $invoice->get_email() ),
121
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
122
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
123
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
124
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
125
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
126
-			'{invoice_date}'        => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
127
-			'{invoice_due_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
128
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
129
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
130
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
131
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
132
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
133
-		);
134
-
135
-	}
136
-
137
-	/**
138
-	 * Helper function to send an email.
139
-	 *
140
-	 * @param WPInv_Invoice $invoice
141
-	 * @param GetPaid_Notification_Email $email
142
-	 * @param string $type
143
-	 * @param string|array $recipients
144
-	 * @param array $extra_args Extra template args.
145
-	 */
146
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
147
-
148
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
149
-
150
-		$mailer     = new GetPaid_Notification_Email_Sender();
151
-		$merge_tags = $email->get_merge_tags();
152
-
153
-		$result = $mailer->send(
154
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
155
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
156
-			$email->get_content( $merge_tags, $extra_args ),
157
-			$email->get_attachments()
158
-		);
159
-
160
-		// Maybe send a copy to the admin.
161
-		if ( $email->include_admin_bcc() ) {
162
-			$mailer->send(
163
-				wpinv_get_admin_email(),
164
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
165
-				$email->get_content( $merge_tags ),
166
-				$email->get_attachments()
167
-			);
168
-		}
169
-
170
-		if ( ! $result ) {
171
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
172
-		}
173
-
174
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
175
-
176
-		return $result;
177
-	}
178
-
179
-	/**
180
-	 * Also send emails to any cc users.
181
-	 *
182
-	 * @param array $recipients
183
-	 * @param GetPaid_Notification_Email $email
184
-	 */
185
-	public function filter_email_recipients( $recipients, $email ) {
186
-
187
-		if ( ! $email->is_admin_email() ) {
188
-			$cc = $email->object->get_email_cc();
189
-
190
-			if ( ! empty( $cc ) ) {
191
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
192
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
193
-			}
194
-
195
-		}
196
-
197
-		return $recipients;
198
-
199
-	}
200
-
201
-	/**
202
-	 * Sends a new invoice notification.
203
-	 *
204
-	 * @param WPInv_Invoice $invoice
205
-	 */
206
-	public function new_invoice( $invoice ) {
207
-
208
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
209
-		$recipient = wpinv_get_admin_email();
210
-
211
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
212
-
213
-	}
214
-
215
-	/**
216
-	 * Sends a cancelled invoice notification.
217
-	 *
218
-	 * @param WPInv_Invoice $invoice
219
-	 */
220
-	public function cancelled_invoice( $invoice ) {
221
-
222
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
223
-		$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'                   => 'new_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_invoice'                   => 'user_invoice',
40
+                'getpaid_new_customer_note'             => 'user_note',
41
+                'getpaid_daily_maintenance'             => 'overdue',
42
+
43
+            )
44
+        );
45
+
46
+        $this->init_hooks();
47
+
48
+    }
49
+
50
+    /**
51
+     * Registers email hooks.
52
+     */
53
+    public function init_hooks() {
54
+
55
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
56
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
57
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
58
+
59
+            $email = new GetPaid_Notification_Email( $email_type );
60
+
61
+            if ( ! $email->is_active() ) {
62
+                continue;
63
+            }
64
+
65
+            if ( method_exists( $this, $email_type ) ) {
66
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
67
+                continue;
68
+            }
69
+
70
+            do_action( 'getpaid_invoice_notification_email_register_hook', $email );
71
+
72
+        }
73
+
74
+    }
75
+
76
+    /**
77
+     * Filters invoice merge tags.
78
+     *
79
+     * @param array $merge_tags
80
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
81
+     */
82
+    public function invoice_merge_tags( $merge_tags, $object ) {
83
+
84
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
85
+            return array_merge(
86
+                $merge_tags,
87
+                $this->get_invoice_merge_tags( $object )
88
+            );
89
+        }
90
+
91
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
92
+            return array_merge(
93
+                $merge_tags,
94
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
95
+            );
96
+        }
97
+
98
+        return $merge_tags;
99
+
100
+    }
101
+
102
+    /**
103
+     * Generates invoice merge tags.
104
+     *
105
+     * @param WPInv_Invoice $invoice
106
+     * @return array
107
+     */
108
+    public function get_invoice_merge_tags( $invoice ) {
109
+
110
+        // Abort if it does not exist.
111
+        if ( ! $invoice->get_id() ) {
112
+            return array();
113
+        }
114
+
115
+        return array(
116
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
117
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
118
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
119
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
120
+            '{email}'               => sanitize_email( $invoice->get_email() ),
121
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
122
+            '{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
123
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
124
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
125
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
126
+            '{invoice_date}'        => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
127
+            '{invoice_due_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
128
+            '{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
129
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
130
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
131
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
132
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
133
+        );
134
+
135
+    }
136
+
137
+    /**
138
+     * Helper function to send an email.
139
+     *
140
+     * @param WPInv_Invoice $invoice
141
+     * @param GetPaid_Notification_Email $email
142
+     * @param string $type
143
+     * @param string|array $recipients
144
+     * @param array $extra_args Extra template args.
145
+     */
146
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
147
+
148
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
149
+
150
+        $mailer     = new GetPaid_Notification_Email_Sender();
151
+        $merge_tags = $email->get_merge_tags();
152
+
153
+        $result = $mailer->send(
154
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
155
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
156
+            $email->get_content( $merge_tags, $extra_args ),
157
+            $email->get_attachments()
158
+        );
159
+
160
+        // Maybe send a copy to the admin.
161
+        if ( $email->include_admin_bcc() ) {
162
+            $mailer->send(
163
+                wpinv_get_admin_email(),
164
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
165
+                $email->get_content( $merge_tags ),
166
+                $email->get_attachments()
167
+            );
168
+        }
169
+
170
+        if ( ! $result ) {
171
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
172
+        }
173
+
174
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
175
+
176
+        return $result;
177
+    }
178
+
179
+    /**
180
+     * Also send emails to any cc users.
181
+     *
182
+     * @param array $recipients
183
+     * @param GetPaid_Notification_Email $email
184
+     */
185
+    public function filter_email_recipients( $recipients, $email ) {
186
+
187
+        if ( ! $email->is_admin_email() ) {
188
+            $cc = $email->object->get_email_cc();
189
+
190
+            if ( ! empty( $cc ) ) {
191
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
192
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
193
+            }
194
+
195
+        }
196
+
197
+        return $recipients;
198
+
199
+    }
200
+
201
+    /**
202
+     * Sends a new invoice notification.
203
+     *
204
+     * @param WPInv_Invoice $invoice
205
+     */
206
+    public function new_invoice( $invoice ) {
207
+
208
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
209
+        $recipient = wpinv_get_admin_email();
210
+
211
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
212
+
213
+    }
214
+
215
+    /**
216
+     * Sends a cancelled invoice notification.
217
+     *
218
+     * @param WPInv_Invoice $invoice
219
+     */
220
+    public function cancelled_invoice( $invoice ) {
221
+
222
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
223
+        $recipient = wpinv_get_admin_email();
224 224
 
225
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
225
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
226 226
 
227
-	}
227
+    }
228 228
 
229
-	/**
230
-	 * Sends a failed invoice notification.
231
-	 *
232
-	 * @param WPInv_Invoice $invoice
233
-	 */
234
-	public function failed_invoice( $invoice ) {
229
+    /**
230
+     * Sends a failed invoice notification.
231
+     *
232
+     * @param WPInv_Invoice $invoice
233
+     */
234
+    public function failed_invoice( $invoice ) {
235 235
 
236
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
237
-		$recipient = wpinv_get_admin_email();
238
-
239
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
236
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
237
+        $recipient = wpinv_get_admin_email();
238
+
239
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
240 240
 
241
-	}
241
+    }
242 242
 
243
-	/**
244
-	 * Sends a notification whenever an invoice is put on hold.
245
-	 *
246
-	 * @param WPInv_Invoice $invoice
247
-	 */
248
-	public function onhold_invoice( $invoice ) {
243
+    /**
244
+     * Sends a notification whenever an invoice is put on hold.
245
+     *
246
+     * @param WPInv_Invoice $invoice
247
+     */
248
+    public function onhold_invoice( $invoice ) {
249 249
 
250
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
251
-		$recipient = $invoice->get_email();
250
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
251
+        $recipient = $invoice->get_email();
252 252
 
253
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
253
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
254 254
 
255
-	}
255
+    }
256 256
 
257
-	/**
258
-	 * Sends a notification whenever an invoice is marked as processing payment.
259
-	 *
260
-	 * @param WPInv_Invoice $invoice
261
-	 */
262
-	public function processing_invoice( $invoice ) {
257
+    /**
258
+     * Sends a notification whenever an invoice is marked as processing payment.
259
+     *
260
+     * @param WPInv_Invoice $invoice
261
+     */
262
+    public function processing_invoice( $invoice ) {
263 263
 
264
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
265
-		$recipient = $invoice->get_email();
264
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
265
+        $recipient = $invoice->get_email();
266 266
 
267
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
267
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
268 268
 
269
-	}
269
+    }
270 270
 
271
-	/**
272
-	 * Sends a notification whenever an invoice is paid.
273
-	 *
274
-	 * @param WPInv_Invoice $invoice
275
-	 */
276
-	public function completed_invoice( $invoice ) {
271
+    /**
272
+     * Sends a notification whenever an invoice is paid.
273
+     *
274
+     * @param WPInv_Invoice $invoice
275
+     */
276
+    public function completed_invoice( $invoice ) {
277 277
 
278
-		// (Maybe) abort if it is a renewal invoice.
279
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
280
-			return;
281
-		}
278
+        // (Maybe) abort if it is a renewal invoice.
279
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
280
+            return;
281
+        }
282 282
 
283
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
-		$recipient = $invoice->get_email();
283
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
+        $recipient = $invoice->get_email();
285 285
 
286
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
286
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287 287
 
288
-	}
288
+    }
289 289
 
290
-	/**
291
-	 * Sends a notification whenever an invoice is refunded.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice
294
-	 */
295
-	public function refunded_invoice( $invoice ) {
290
+    /**
291
+     * Sends a notification whenever an invoice is refunded.
292
+     *
293
+     * @param WPInv_Invoice $invoice
294
+     */
295
+    public function refunded_invoice( $invoice ) {
296 296
 
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
-		$recipient = $invoice->get_email();
297
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+        $recipient = $invoice->get_email();
299 299
 
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
300
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301 301
 
302
-	}
302
+    }
303 303
 
304
-	/**
305
-	 * Notifies a user about new invoices
306
-	 *
307
-	 * @param WPInv_Invoice $invoice
308
-	 */
309
-	public function user_invoice( $invoice ) {
304
+    /**
305
+     * Notifies a user about new invoices
306
+     *
307
+     * @param WPInv_Invoice $invoice
308
+     */
309
+    public function user_invoice( $invoice ) {
310 310
 
311
-		// Only send this email for invoices created via the admin page.
312
-		if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) {
313
-			return;
314
-		}
311
+        // Only send this email for invoices created via the admin page.
312
+        if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) {
313
+            return;
314
+        }
315 315
 
316
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
317
-		$recipient = $invoice->get_email();
316
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
317
+        $recipient = $invoice->get_email();
318 318
 
319
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
319
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
320 320
 
321
-	}
321
+    }
322 322
 
323
-	/**
324
-	 * Checks if an invoice is a payment form invoice.
325
-	 *
326
-	 * @param int $invoice
327
-	 * @return bool
328
-	 */
329
-	public function is_payment_form_invoice( $invoice ) {
330
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
331
-	}
323
+    /**
324
+     * Checks if an invoice is a payment form invoice.
325
+     *
326
+     * @param int $invoice
327
+     * @return bool
328
+     */
329
+    public function is_payment_form_invoice( $invoice ) {
330
+        return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
331
+    }
332 332
 
333
-	/**
334
-	 * Notifies admin about new invoice notes
335
-	 *
336
-	 * @param WPInv_Invoice $invoice
337
-	 * @param string $note
338
-	 */
339
-	public function user_note( $invoice, $note ) {
333
+    /**
334
+     * Notifies admin about new invoice notes
335
+     *
336
+     * @param WPInv_Invoice $invoice
337
+     * @param string $note
338
+     */
339
+    public function user_note( $invoice, $note ) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
-		$recipient = $invoice->get_email();
343
-
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
345
-
346
-	}
341
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
+        $recipient = $invoice->get_email();
343
+
344
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
345
+
346
+    }
347 347
 
348
-	/**
349
-	 * (Force) Sends overdue notices.
350
-	 *
351
-	 * @param WPInv_Invoice $invoice
352
-	 */
353
-	public function force_send_overdue_notice( $invoice ) {
354
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
355
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
356
-	}
357
-
358
-	/**
359
-	 * Sends overdue notices.
360
-	 *
361
-	 * @TODO: Create an invoices query class.
362
-	 */
363
-	public function overdue() {
364
-		global $wpdb;
365
-
366
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
367
-
368
-		// Fetch reminder days.
369
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
370
-
371
-		// Abort if non is set.
372
-		if ( empty( $reminder_days ) ) {
373
-			return;
374
-		}
375
-
376
-		// Retrieve date query.
377
-		$date_query = $this->get_date_query( $reminder_days );
378
-
379
-		// Invoices table.
380
-		$table = $wpdb->prefix . 'getpaid_invoices';
381
-
382
-		// Fetch invoices.
383
-		$invoices  = $wpdb->get_col(
384
-			"SELECT posts.ID FROM $wpdb->posts as posts
348
+    /**
349
+     * (Force) Sends overdue notices.
350
+     *
351
+     * @param WPInv_Invoice $invoice
352
+     */
353
+    public function force_send_overdue_notice( $invoice ) {
354
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
355
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
356
+    }
357
+
358
+    /**
359
+     * Sends overdue notices.
360
+     *
361
+     * @TODO: Create an invoices query class.
362
+     */
363
+    public function overdue() {
364
+        global $wpdb;
365
+
366
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
367
+
368
+        // Fetch reminder days.
369
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
370
+
371
+        // Abort if non is set.
372
+        if ( empty( $reminder_days ) ) {
373
+            return;
374
+        }
375
+
376
+        // Retrieve date query.
377
+        $date_query = $this->get_date_query( $reminder_days );
378
+
379
+        // Invoices table.
380
+        $table = $wpdb->prefix . 'getpaid_invoices';
381
+
382
+        // Fetch invoices.
383
+        $invoices  = $wpdb->get_col(
384
+            "SELECT posts.ID FROM $wpdb->posts as posts
385 385
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
386 386
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
387 387
 
388
-		foreach ( $invoices as $invoice ) {
388
+        foreach ( $invoices as $invoice ) {
389 389
 
390
-			// Only send this email for invoices created via the admin page.
391
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
392
-				$invoice       = new WPInv_Invoice( $invoice );
393
-				$email->object = $invoice;
390
+            // Only send this email for invoices created via the admin page.
391
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
392
+                $invoice       = new WPInv_Invoice( $invoice );
393
+                $email->object = $invoice;
394 394
 
395
-				if ( $invoice->needs_payment() ) {
396
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
397
-				}
395
+                if ( $invoice->needs_payment() ) {
396
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
397
+                }
398 398
 
399
-			}
399
+            }
400 400
 
401
-		}
401
+        }
402 402
 
403
-	}
403
+    }
404 404
 
405
-	/**
406
-	 * Calculates the date query for an invoices query
407
-	 *
408
-	 * @param array $reminder_days
409
-	 * @return string
410
-	 */
411
-	public function get_date_query( $reminder_days ) {
405
+    /**
406
+     * Calculates the date query for an invoices query
407
+     *
408
+     * @param array $reminder_days
409
+     * @return string
410
+     */
411
+    public function get_date_query( $reminder_days ) {
412 412
 
413
-		$date_query = array(
414
-			'relation'  => 'OR'
415
-		);
413
+        $date_query = array(
414
+            'relation'  => 'OR'
415
+        );
416 416
 
417
-		foreach ( $reminder_days as $days ) {
418
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
417
+        foreach ( $reminder_days as $days ) {
418
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
419 419
 
420
-			$date_query[] = array(
421
-				'year'  => $date['year'],
422
-				'month' => $date['month'],
423
-				'day'   => $date['day'],
424
-			);
420
+            $date_query[] = array(
421
+                'year'  => $date['year'],
422
+                'month' => $date['month'],
423
+                'day'   => $date['day'],
424
+            );
425 425
 
426
-		}
426
+        }
427 427
 
428
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
428
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
429 429
 
430
-		return $date_query->get_sql();
430
+        return $date_query->get_sql();
431 431
 
432
-	}
432
+    }
433 433
 
434 434
 }
Please login to merge, or discard this patch.
includes/class-getpaid-subscription-notification-emails.php 1 patch
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 );
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}' => strtolower( sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ) ),
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 );
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}' => strtolower( sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ) ),
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.
includes/class-getpaid-daily-maintenance.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15 15
     /**
16
-	 * Class constructor.
17
-	 */
16
+     * Class constructor.
17
+     */
18 18
     public function __construct(){
19 19
 
20 20
         // Clear deprecated events.
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
     }
31 31
 
32 32
     /**
33
-	 * Schedules a cron to run every day at 7 a.m
33
+     * Schedules a cron to run every day at 7 a.m
34 34
      *
35
-	 */
35
+     */
36 36
     public function maybe_create_scheduled_event() {
37 37
 
38 38
         if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
     }
44 44
 
45 45
     /**
46
-	 * Clears deprecated events.
46
+     * Clears deprecated events.
47 47
      *
48
-	 */
48
+     */
49 49
     public function maybe_clear_deprecated_events() {
50 50
 
51 51
         if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
     }
58 58
 
59 59
     /**
60
-	 * Fires the old hook for backwards compatibility.
60
+     * Fires the old hook for backwards compatibility.
61 61
      *
62
-	 */
62
+     */
63 63
     public function backwards_compat() {
64 64
         do_action( 'wpinv_register_schedule_event_daily' );
65 65
     }
66 66
 
67 67
     /**
68
-	 * Expires expired subscriptions.
68
+     * Expires expired subscriptions.
69 69
      *
70
-	 */
70
+     */
71 71
     public function maybe_expire_subscriptions() {
72 72
 
73 73
         // Fetch expired subscriptions (skips those that expire today).
74 74
         $args  = array(
75 75
             'number'             => -1,
76
-			'count_total'        => false,
77
-			'status'             => 'trialling active failing cancelled',
76
+            'count_total'        => false,
77
+            'status'             => 'trialling active failing cancelled',
78 78
             'date_expires_query' => array(
79 79
                 'before'    => 'today',
80 80
                 'inclusive' => false,
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +497 added lines, -497 removed lines patch added patch discarded remove patch
@@ -14,440 +14,440 @@  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->form_elements = new WPInv_Payment_Form_Elements();
94
-		$this->tax           = new WPInv_EUVat();
95
-		$this->tax->init();
96
-		$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
97
-
98
-		// Init other objects.
99
-		$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
100
-		$this->set( 'session', new WPInv_Session_Handler() );
101
-		$this->set( 'notes', new WPInv_Notes() );
102
-		$this->set( 'api', new WPInv_API() );
103
-		$this->set( 'post_types', new GetPaid_Post_Types() );
104
-		$this->set( 'template', new GetPaid_Template() );
105
-		$this->set( 'admin', new GetPaid_Admin() );
106
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
107
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
108
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
109
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
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( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
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
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
199
-
200
-		// Load functions.
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
206
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
207
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
208
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-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
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
245
-
246
-		/**
247
-		 * Load the tax class.
248
-		 */
249
-		if ( ! class_exists( 'WPInv_EUVat' ) ) {
250
-			require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
251
-		}
252
-
253
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
254
-		if ( !empty( $gateways ) ) {
255
-			foreach ( $gateways as $gateway ) {
256
-				if ( $gateway == 'manual' ) {
257
-					continue;
258
-				}
259
-
260
-				$gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
261
-
262
-				if ( file_exists( $gateway_file ) ) {
263
-					require_once( $gateway_file );
264
-				}
265
-			}
266
-		}
267
-
268
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
269
-			GetPaid_Post_Types_Admin::init();
270
-
271
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
272
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
273
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
274
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
275
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
276
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
277
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
278
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
279
-			// load the user class only on the users.php page
280
-			global $pagenow;
281
-			if($pagenow=='users.php'){
282
-				new WPInv_Admin_Users();
283
-			}
284
-		}
285
-
286
-		// Register cli commands
287
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
288
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
289
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
290
-		}
291
-
292
-		// include css inliner
293
-		if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
294
-			include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
295
-		}
296
-
297
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
298
-	}
299
-
300
-	/**
301
-	 * Class autoloader
302
-	 *
303
-	 * @param       string $class_name The name of the class to load.
304
-	 * @access      public
305
-	 * @since       1.0.19
306
-	 * @return      void
307
-	 */
308
-	public function autoload( $class_name ) {
309
-
310
-		// Normalize the class name...
311
-		$class_name  = strtolower( $class_name );
312
-
313
-		// ... and make sure it is our class.
314
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
315
-			return;
316
-		}
317
-
318
-		// Next, prepare the file name from the class.
319
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
320
-
321
-		// Base path of the classes.
322
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
323
-
324
-		// And an array of possible locations in order of importance.
325
-		$locations = array(
326
-			"$plugin_path/includes",
327
-			"$plugin_path/includes/data-stores",
328
-			"$plugin_path/includes/gateways",
329
-			"$plugin_path/includes/api",
330
-			"$plugin_path/includes/admin",
331
-			"$plugin_path/includes/admin/meta-boxes",
332
-		);
333
-
334
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
335
-
336
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
337
-				include trailingslashit( $location ) . $file_name;
338
-				break;
339
-			}
340
-
341
-		}
342
-
343
-	}
344
-
345
-	/**
346
-	 * Inits hooks etc.
347
-	 */
348
-	public function init() {
349
-
350
-		// Fires before getpaid inits.
351
-		do_action( 'before_getpaid_init', $this );
352
-
353
-		// Load default gateways.
354
-		$gateways = apply_filters(
355
-			'getpaid_default_gateways',
356
-			array(
357
-				'manual'        => 'GetPaid_Manual_Gateway',
358
-				'paypal'        => 'GetPaid_Paypal_Gateway',
359
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
360
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
361
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
362
-			)
363
-		);
364
-
365
-		foreach ( $gateways as $id => $class ) {
366
-			$this->gateways[ $id ] = new $class();
367
-		}
368
-
369
-		// Fires after getpaid inits.
370
-		do_action( 'getpaid_init', $this );
371
-
372
-	}
373
-
374
-	/**
375
-	 * Checks if this is an IPN request and processes it.
376
-	 */
377
-	public function maybe_process_ipn() {
378
-
379
-		// Ensure that this is an IPN request.
380
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
381
-			return;
382
-		}
383
-
384
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
385
-
386
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
387
-		do_action( "wpinv_verify_{$gateway}_ipn" );
388
-		exit;
389
-
390
-	}
391
-
392
-	public function enqueue_scripts() {
393
-		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
394
-
395
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
396
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
397
-		wp_enqueue_style( 'wpinv_front_style' );
398
-
399
-		// Register scripts
400
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
401
-		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' ) );
402
-
403
-		$localize                         = array();
404
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
405
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
406
-		$localize['currency_symbol']      = wpinv_currency_symbol();
407
-		$localize['currency_pos']         = wpinv_currency_position();
408
-		$localize['thousand_sep']         = wpinv_thousands_separator();
409
-		$localize['decimal_sep']          = wpinv_decimal_separator();
410
-		$localize['decimals']             = wpinv_decimals();
411
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
412
-		$localize['UseTaxes']             = wpinv_use_taxes();
413
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
414
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
415
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
416
-
417
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
418
-
419
-		wp_enqueue_script( 'jquery-blockui' );
420
-		$autofill_api = wpinv_get_option('address_autofill_api');
421
-		$autofill_active = wpinv_get_option('address_autofill_active');
422
-		if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
423
-			if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
424
-				wp_dequeue_script( 'google-maps-api' );
425
-			}
426
-			wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
427
-			wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
428
-		}
429
-
430
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
431
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
432
-
433
-		wp_enqueue_script( 'wpinv-front-script' );
434
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
435
-
436
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
437
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
438
-	}
439
-
440
-	public function wpinv_actions() {
441
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
442
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
443
-		}
444
-	}
445
-
446
-	/**
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->form_elements = new WPInv_Payment_Form_Elements();
94
+        $this->tax           = new WPInv_EUVat();
95
+        $this->tax->init();
96
+        $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
97
+
98
+        // Init other objects.
99
+        $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
100
+        $this->set( 'session', new WPInv_Session_Handler() );
101
+        $this->set( 'notes', new WPInv_Notes() );
102
+        $this->set( 'api', new WPInv_API() );
103
+        $this->set( 'post_types', new GetPaid_Post_Types() );
104
+        $this->set( 'template', new GetPaid_Template() );
105
+        $this->set( 'admin', new GetPaid_Admin() );
106
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
107
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
108
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
109
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
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( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
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
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
199
+
200
+        // Load functions.
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
205
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
206
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
207
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
208
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-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
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
245
+
246
+        /**
247
+         * Load the tax class.
248
+         */
249
+        if ( ! class_exists( 'WPInv_EUVat' ) ) {
250
+            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
251
+        }
252
+
253
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
254
+        if ( !empty( $gateways ) ) {
255
+            foreach ( $gateways as $gateway ) {
256
+                if ( $gateway == 'manual' ) {
257
+                    continue;
258
+                }
259
+
260
+                $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
261
+
262
+                if ( file_exists( $gateway_file ) ) {
263
+                    require_once( $gateway_file );
264
+                }
265
+            }
266
+        }
267
+
268
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
269
+            GetPaid_Post_Types_Admin::init();
270
+
271
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
272
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
273
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
274
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
275
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
276
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
277
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
278
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
279
+            // load the user class only on the users.php page
280
+            global $pagenow;
281
+            if($pagenow=='users.php'){
282
+                new WPInv_Admin_Users();
283
+            }
284
+        }
285
+
286
+        // Register cli commands
287
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
288
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
289
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
290
+        }
291
+
292
+        // include css inliner
293
+        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
294
+            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
295
+        }
296
+
297
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
298
+    }
299
+
300
+    /**
301
+     * Class autoloader
302
+     *
303
+     * @param       string $class_name The name of the class to load.
304
+     * @access      public
305
+     * @since       1.0.19
306
+     * @return      void
307
+     */
308
+    public function autoload( $class_name ) {
309
+
310
+        // Normalize the class name...
311
+        $class_name  = strtolower( $class_name );
312
+
313
+        // ... and make sure it is our class.
314
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
315
+            return;
316
+        }
317
+
318
+        // Next, prepare the file name from the class.
319
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
320
+
321
+        // Base path of the classes.
322
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
323
+
324
+        // And an array of possible locations in order of importance.
325
+        $locations = array(
326
+            "$plugin_path/includes",
327
+            "$plugin_path/includes/data-stores",
328
+            "$plugin_path/includes/gateways",
329
+            "$plugin_path/includes/api",
330
+            "$plugin_path/includes/admin",
331
+            "$plugin_path/includes/admin/meta-boxes",
332
+        );
333
+
334
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
335
+
336
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
337
+                include trailingslashit( $location ) . $file_name;
338
+                break;
339
+            }
340
+
341
+        }
342
+
343
+    }
344
+
345
+    /**
346
+     * Inits hooks etc.
347
+     */
348
+    public function init() {
349
+
350
+        // Fires before getpaid inits.
351
+        do_action( 'before_getpaid_init', $this );
352
+
353
+        // Load default gateways.
354
+        $gateways = apply_filters(
355
+            'getpaid_default_gateways',
356
+            array(
357
+                'manual'        => 'GetPaid_Manual_Gateway',
358
+                'paypal'        => 'GetPaid_Paypal_Gateway',
359
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
360
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
361
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
362
+            )
363
+        );
364
+
365
+        foreach ( $gateways as $id => $class ) {
366
+            $this->gateways[ $id ] = new $class();
367
+        }
368
+
369
+        // Fires after getpaid inits.
370
+        do_action( 'getpaid_init', $this );
371
+
372
+    }
373
+
374
+    /**
375
+     * Checks if this is an IPN request and processes it.
376
+     */
377
+    public function maybe_process_ipn() {
378
+
379
+        // Ensure that this is an IPN request.
380
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
381
+            return;
382
+        }
383
+
384
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
385
+
386
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
387
+        do_action( "wpinv_verify_{$gateway}_ipn" );
388
+        exit;
389
+
390
+    }
391
+
392
+    public function enqueue_scripts() {
393
+        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
394
+
395
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
396
+        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
397
+        wp_enqueue_style( 'wpinv_front_style' );
398
+
399
+        // Register scripts
400
+        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
401
+        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' ) );
402
+
403
+        $localize                         = array();
404
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
405
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
406
+        $localize['currency_symbol']      = wpinv_currency_symbol();
407
+        $localize['currency_pos']         = wpinv_currency_position();
408
+        $localize['thousand_sep']         = wpinv_thousands_separator();
409
+        $localize['decimal_sep']          = wpinv_decimal_separator();
410
+        $localize['decimals']             = wpinv_decimals();
411
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
412
+        $localize['UseTaxes']             = wpinv_use_taxes();
413
+        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
414
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
415
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
416
+
417
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
418
+
419
+        wp_enqueue_script( 'jquery-blockui' );
420
+        $autofill_api = wpinv_get_option('address_autofill_api');
421
+        $autofill_active = wpinv_get_option('address_autofill_active');
422
+        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
423
+            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
424
+                wp_dequeue_script( 'google-maps-api' );
425
+            }
426
+            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
427
+            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
428
+        }
429
+
430
+        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
431
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
432
+
433
+        wp_enqueue_script( 'wpinv-front-script' );
434
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
435
+
436
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
437
+        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
438
+    }
439
+
440
+    public function wpinv_actions() {
441
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
442
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
443
+        }
444
+    }
445
+
446
+    /**
447 447
      * Fires an action after verifying that a user can fire them.
448
-	 *
449
-	 * Note: If the action is on an invoice, subscription etc, esure that the
450
-	 * current user owns the invoice/subscription.
448
+     *
449
+     * Note: If the action is on an invoice, subscription etc, esure that the
450
+     * current user owns the invoice/subscription.
451 451
      */
452 452
     public function maybe_do_authenticated_action() {
453 453
 
@@ -458,82 +458,82 @@  discard block
 block discarded – undo
458 458
 
459 459
     }
460 460
 
461
-	public function pre_get_posts( $wp_query ) {
462
-		if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
463
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
464
-		}
465
-
466
-		return $wp_query;
467
-	}
468
-
469
-	public function bp_invoicing_init() {
470
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
471
-	}
472
-
473
-	/**
474
-	 * Register widgets
475
-	 *
476
-	 */
477
-	public function register_widgets() {
478
-		$widgets = apply_filters(
479
-			'getpaid_widget_classes',
480
-			array(
481
-				'WPInv_Checkout_Widget',
482
-				'WPInv_History_Widget',
483
-				'WPInv_Receipt_Widget',
484
-				'WPInv_Subscriptions_Widget',
485
-				'WPInv_Buy_Item_Widget',
486
-				'WPInv_Messages_Widget',
487
-				'WPInv_GetPaid_Widget'
488
-			)
489
-		);
490
-
491
-		foreach ( $widgets as $widget ) {
492
-			register_widget( $widget );
493
-		}
461
+    public function pre_get_posts( $wp_query ) {
462
+        if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
463
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
464
+        }
465
+
466
+        return $wp_query;
467
+    }
468
+
469
+    public function bp_invoicing_init() {
470
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
471
+    }
472
+
473
+    /**
474
+     * Register widgets
475
+     *
476
+     */
477
+    public function register_widgets() {
478
+        $widgets = apply_filters(
479
+            'getpaid_widget_classes',
480
+            array(
481
+                'WPInv_Checkout_Widget',
482
+                'WPInv_History_Widget',
483
+                'WPInv_Receipt_Widget',
484
+                'WPInv_Subscriptions_Widget',
485
+                'WPInv_Buy_Item_Widget',
486
+                'WPInv_Messages_Widget',
487
+                'WPInv_GetPaid_Widget'
488
+            )
489
+        );
490
+
491
+        foreach ( $widgets as $widget ) {
492
+            register_widget( $widget );
493
+        }
494 494
 		
495
-	}
495
+    }
496 496
 
497
-	/**
498
-	 * Remove our pages from yoast sitemaps.
499
-	 *
500
-	 * @since 1.0.19
501
-	 * @param int[] $excluded_posts_ids
502
-	 */
503
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
497
+    /**
498
+     * Remove our pages from yoast sitemaps.
499
+     *
500
+     * @since 1.0.19
501
+     * @param int[] $excluded_posts_ids
502
+     */
503
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
504 504
 
505
-		// Ensure that we have an array.
506
-		if ( ! is_array( $excluded_posts_ids ) ) {
507
-			$excluded_posts_ids = array();
508
-		}
505
+        // Ensure that we have an array.
506
+        if ( ! is_array( $excluded_posts_ids ) ) {
507
+            $excluded_posts_ids = array();
508
+        }
509 509
 
510
-		// Prepare our pages.
511
-		$our_pages = array();
510
+        // Prepare our pages.
511
+        $our_pages = array();
512 512
 
513
-		// Checkout page.
514
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
513
+        // Checkout page.
514
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
515 515
 
516
-		// Success page.
517
-		$our_pages[] = wpinv_get_option( 'success_page', false );
516
+        // Success page.
517
+        $our_pages[] = wpinv_get_option( 'success_page', false );
518 518
 
519
-		// Failure page.
520
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
519
+        // Failure page.
520
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
521 521
 
522
-		// History page.
523
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
522
+        // History page.
523
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
524 524
 
525
-		// Subscriptions page.
526
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
525
+        // Subscriptions page.
526
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
527 527
 
528
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
528
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
529 529
 
530
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
531
-		return array_unique( $excluded_posts_ids );
530
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
531
+        return array_unique( $excluded_posts_ids );
532 532
 
533
-	}
533
+    }
534 534
 
535
-	public function wp_footer() {
536
-		echo '
535
+    public function wp_footer() {
536
+        echo '
537 537
 			<div class="bsui">
538 538
 				<div  id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog">
539 539
 					<div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;">
@@ -544,6 +544,6 @@  discard block
 block discarded – undo
544 544
 				</div>
545 545
 			</div>
546 546
 		';
547
-	}
547
+    }
548 548
 
549 549
 }
Please login to merge, or discard this patch.