Passed
Pull Request — master (#126)
by Kiran
03:53
created
includes/class-wpinv-shortcodes.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -21,6 +21,9 @@
 block discarded – undo
21 21
         add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' );
22 22
     }
23 23
 
24
+    /**
25
+     * @param string[] $function
26
+     */
24 27
     public static function shortcode_wrapper(
25 28
         $function,
26 29
         $atts    = array(),
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
             'wpinv_buy'  => __CLASS__ . '::buy',
16 16
         );
17 17
 
18
-        foreach ( $shortcodes as $shortcode => $function ) {
19
-            add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function );
18
+        foreach ($shortcodes as $shortcode => $function) {
19
+            add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function);
20 20
         }
21 21
         
22
-        add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' );
22
+        add_shortcode('wpinv_messages', __CLASS__ . '::messages');
23 23
     }
24 24
 
25 25
     public static function shortcode_wrapper(
@@ -33,25 +33,25 @@  discard block
 block discarded – undo
33 33
     ) {
34 34
         ob_start();
35 35
 
36
-        echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before'];
37
-        call_user_func( $function, $atts );
38
-        echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
36
+        echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before'];
37
+        call_user_func($function, $atts);
38
+        echo empty($wrapper['after']) ? '</div>' : $wrapper['after'];
39 39
 
40 40
         return ob_get_clean();
41 41
     }
42 42
 
43
-    public static function checkout( $atts = array(), $content = null ) {
44
-        return wpinv_checkout_form( $atts, $content );
43
+    public static function checkout($atts = array(), $content = null) {
44
+        return wpinv_checkout_form($atts, $content);
45 45
     }
46 46
 
47
-    public static function messages( $atts, $content = null ) {
47
+    public static function messages($atts, $content = null) {
48 48
         ob_start();
49 49
         wpinv_print_errors();
50 50
         return '<div class="wpinv">' . ob_get_clean() . '</div>';
51 51
     }
52 52
     
53
-    public static function history( $atts, $content = null ) {
54
-        return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts );
53
+    public static function history($atts, $content = null) {
54
+        return self::shortcode_wrapper(array(__CLASS__, 'history_output'), $atts);
55 55
     }
56 56
 
57 57
     /**
@@ -59,28 +59,28 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @param array $atts
61 61
      */
62
-    public static function history_output( $atts ) {
63
-        do_action( 'wpinv_before_user_invoice_history' );
64
-        wpinv_get_template_part( 'wpinv-invoice-history', $atts );
65
-        do_action( 'wpinv_after_user_invoice_history' );
62
+    public static function history_output($atts) {
63
+        do_action('wpinv_before_user_invoice_history');
64
+        wpinv_get_template_part('wpinv-invoice-history', $atts);
65
+        do_action('wpinv_after_user_invoice_history');
66 66
     }
67 67
     
68
-    public static function receipt( $atts, $content = null ) {
69
-        return wpinv_payment_receipt( $atts, $content );
68
+    public static function receipt($atts, $content = null) {
69
+        return wpinv_payment_receipt($atts, $content);
70 70
     }
71 71
 
72
-    public static function buy( $atts, $content = null ) {
73
-        $a = shortcode_atts( array(
72
+    public static function buy($atts, $content = null) {
73
+        $a = shortcode_atts(array(
74 74
             'items' => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity
75
-            'title' => __('Buy Now', 'invoicing' ), // the button title
75
+            'title' => __('Buy Now', 'invoicing'), // the button title
76 76
             'post_id' => '', // any related post_id
77
-        ), $atts );
77
+        ), $atts);
78 78
         
79 79
         $post_id = isset($a['post_id']) ? (int)$a['post_id'] : '';
80 80
 
81 81
         $html = '<div class="wpi-buy-button-wrapper">';
82
-        $html .= '<input type="submit" name="submit" class="button button-primary wpi-buy-button" value="'.$a['title'].'" onclick="wpi_buy(\''.$a['items'].'\','.$post_id.');" />';
83
-        $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false );
82
+        $html .= '<input type="submit" name="submit" class="button button-primary wpi-buy-button" value="' . $a['title'] . '" onclick="wpi_buy(\'' . $a['items'] . '\',' . $post_id . ');" />';
83
+        $html .= wp_nonce_field('wpinv_buy_items', 'wpinv_buy_nonce', true, false);
84 84
         $html .= '</div>';
85 85
 
86 86
 
Please login to merge, or discard this patch.
templates/wpinv-invoice-history.php 3 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 if ( !( $user_id = get_current_user_id() ) ) {
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 		<tbody>
32 32
 			<?php foreach ( $user_invoices->invoices as $invoice ) {
33
-				?>
33
+                ?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35 35
 					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36 36
 						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
@@ -53,31 +53,31 @@  discard block
 block discarded – undo
53 53
 
54 54
 							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
55 55
 								<?php
56
-									$actions = array(
57
-										'pay'    => array(
58
-											'url'  => $invoice->get_checkout_payment_url(),
59
-											'name' => __( 'Pay Now', 'invoicing' ),
56
+                                    $actions = array(
57
+                                        'pay'    => array(
58
+                                            'url'  => $invoice->get_checkout_payment_url(),
59
+                                            'name' => __( 'Pay Now', 'invoicing' ),
60 60
                                             'class' => 'btn-success'
61
-										),
61
+                                        ),
62 62
                                         'print'   => array(
63
-											'url'  => $invoice->get_view_url(),
64
-											'name' => __( 'Print', 'invoicing' ),
63
+                                            'url'  => $invoice->get_view_url(),
64
+                                            'name' => __( 'Print', 'invoicing' ),
65 65
                                             'class' => 'btn-primary',
66 66
                                             'attrs' => 'target="_blank"'
67
-										)
68
-									);
67
+                                        )
68
+                                    );
69 69
 
70
-									if ( ! $invoice->needs_payment() ) {
71
-										unset( $actions['pay'] );
72
-									}
70
+                                    if ( ! $invoice->needs_payment() ) {
71
+                                        unset( $actions['pay'] );
72
+                                    }
73 73
 
74
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
-										foreach ( $actions as $key => $action ) {
76
-											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
74
+                                    if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
+                                        foreach ( $actions as $key => $action ) {
76
+                                            $class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
77 77
                                             echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
78
-										}
79
-									}
80
-								?>
78
+                                        }
79
+                                    }
80
+                                ?>
81 81
 							<?php endif; ?>
82 82
 						</td>
83 83
 					<?php endforeach; ?>
@@ -91,22 +91,22 @@  discard block
 block discarded – undo
91 91
 	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
92 92
 		<div class="invoicing-Pagination">
93 93
 			<?php
94
-			$big = 999999;
95
-
96
-			if (get_query_var('paged'))
97
-				$current_page = get_query_var('paged');
98
-			elseif (get_query_var('page'))
99
-				$current_page = get_query_var('page');
100
-			else
101
-				$current_page = 1;
102
-
103
-			echo paginate_links( array(
104
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
105
-				'format'  => '?paged=%#%',
106
-				'current' => max( 1, $current_page ),
107
-				'total'   => $user_invoices->max_num_pages,
108
-			) );
109
-			?>
94
+            $big = 999999;
95
+
96
+            if (get_query_var('paged'))
97
+                $current_page = get_query_var('paged');
98
+            elseif (get_query_var('page'))
99
+                $current_page = get_query_var('page');
100
+            else
101
+                $current_page = 1;
102
+
103
+            echo paginate_links( array(
104
+                'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
105
+                'format'  => '?paged=%#%',
106
+                'current' => max( 1, $current_page ),
107
+                'total'   => $user_invoices->max_num_pages,
108
+            ) );
109
+            ?>
110 110
 		</div>
111 111
 	<?php endif; ?>
112 112
 
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -1,80 +1,80 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( !( $user_id = get_current_user_id() ) ) {
6
+if (!($user_id = get_current_user_id())) {
7 7
     ?>
8
-    <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div>
8
+    <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div>
9 9
     <?php
10 10
     return;
11 11
 }
12 12
 
13 13
 global $current_page;
14
-$current_page   = empty( $current_page ) ? 1 : absint( $current_page );
15
-$query          = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) );
16
-$user_invoices  = wpinv_get_invoices( $query );
14
+$current_page   = empty($current_page) ? 1 : absint($current_page);
15
+$query          = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true));
16
+$user_invoices  = wpinv_get_invoices($query);
17 17
 $has_invoices   = 0 < $user_invoices->total;
18 18
     
19
-do_action( 'wpinv_before_user_invoices', $has_invoices ); ?>
19
+do_action('wpinv_before_user_invoices', $has_invoices); ?>
20 20
 
21
-<?php if ( $has_invoices ) { ?>
21
+<?php if ($has_invoices) { ?>
22 22
 	<table class="table table-bordered table-hover wpi-user-invoices">
23 23
 		<thead>
24 24
 			<tr>
25
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
26
-					<th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
25
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
26
+					<th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
27 27
 				<?php endforeach; ?>
28 28
 			</tr>
29 29
 		</thead>
30 30
 
31 31
 		<tbody>
32
-			<?php foreach ( $user_invoices->invoices as $invoice ) {
32
+			<?php foreach ($user_invoices->invoices as $invoice) {
33 33
 				?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35
-					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36
-						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
37
-							<?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
38
-								<?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
39
-
40
-							<?php elseif ( 'invoice-number' === $column_id ) : ?>
41
-								<a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
42
-									<?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
35
+					<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
36
+						<td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
37
+							<?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
38
+								<?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
39
+
40
+							<?php elseif ('invoice-number' === $column_id) : ?>
41
+								<a href="<?php echo esc_url($invoice->get_view_url()); ?>">
42
+									<?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
43 43
 								</a>
44 44
 
45
-							<?php elseif ( 'invoice-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s' ); ?>
46
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
45
+							<?php elseif ('invoice-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s'); ?>
46
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
47 47
 
48
-							<?php elseif ( 'invoice-status' === $column_id ) : ?>
49
-								<?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
48
+							<?php elseif ('invoice-status' === $column_id) : ?>
49
+								<?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
50 50
 
51
-							<?php elseif ( 'invoice-total' === $column_id ) : ?>
52
-								<?php echo $invoice->get_total( true ); ?>
51
+							<?php elseif ('invoice-total' === $column_id) : ?>
52
+								<?php echo $invoice->get_total(true); ?>
53 53
 
54
-							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
54
+							<?php elseif ('invoice-actions' === $column_id) : ?>
55 55
 								<?php
56 56
 									$actions = array(
57 57
 										'pay'    => array(
58 58
 											'url'  => $invoice->get_checkout_payment_url(),
59
-											'name' => __( 'Pay Now', 'invoicing' ),
59
+											'name' => __('Pay Now', 'invoicing'),
60 60
                                             'class' => 'btn-success'
61 61
 										),
62 62
                                         'print'   => array(
63 63
 											'url'  => $invoice->get_view_url(),
64
-											'name' => __( 'Print', 'invoicing' ),
64
+											'name' => __('Print', 'invoicing'),
65 65
                                             'class' => 'btn-primary',
66 66
                                             'attrs' => 'target="_blank"'
67 67
 										)
68 68
 									);
69 69
 
70
-									if ( ! $invoice->needs_payment() ) {
71
-										unset( $actions['pay'] );
70
+									if (!$invoice->needs_payment()) {
71
+										unset($actions['pay']);
72 72
 									}
73 73
 
74
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
-										foreach ( $actions as $key => $action ) {
74
+									if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
75
+										foreach ($actions as $key => $action) {
76 76
 											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
77
-                                            echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
77
+                                            echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
78 78
 										}
79 79
 									}
80 80
 								?>
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 		</tbody>
87 87
 	</table>
88 88
 
89
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
89
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
90 90
 
91
-	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
91
+	<?php if (1 < $user_invoices->max_num_pages) : ?>
92 92
 		<div class="invoicing-Pagination">
93 93
 			<?php
94 94
 			$big = 999999;
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
 			else
101 101
 				$current_page = 1;
102 102
 
103
-			echo paginate_links( array(
104
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
103
+			echo paginate_links(array(
104
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
105 105
 				'format'  => '?paged=%#%',
106
-				'current' => max( 1, $current_page ),
106
+				'current' => max(1, $current_page),
107 107
 				'total'   => $user_invoices->max_num_pages,
108
-			) );
108
+			));
109 109
 			?>
110 110
 		</div>
111 111
 	<?php endif; ?>
112 112
 
113 113
 <?php } else { ?>
114 114
 	<div class="wpinv-empty alert-info">
115
-		<?php _e( 'No invoice has been made yet.', 'invoicing' ); ?>
115
+		<?php _e('No invoice has been made yet.', 'invoicing'); ?>
116 116
 	</div>
117 117
 <?php } ?>
118 118
 
119
-<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?>
119
+<?php do_action('wpinv_after_user_invoices', $has_invoices); ?>
Please login to merge, or discard this patch.
Braces   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -93,12 +93,13 @@
 block discarded – undo
93 93
 			<?php
94 94
 			$big = 999999;
95 95
 
96
-			if (get_query_var('paged'))
97
-				$current_page = get_query_var('paged');
98
-			elseif (get_query_var('page'))
99
-				$current_page = get_query_var('page');
100
-			else
101
-				$current_page = 1;
96
+			if (get_query_var('paged')) {
97
+							$current_page = get_query_var('paged');
98
+			} elseif (get_query_var('page')) {
99
+							$current_page = get_query_var('page');
100
+			} else {
101
+							$current_page = 1;
102
+			}
102 103
 
103 104
 			echo paginate_links( array(
104 105
 				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -11,45 +11,45 @@
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
     
16
-    if ( $wpi_version == WPINV_VERSION ) {
16
+    if ($wpi_version == WPINV_VERSION) {
17 17
         return;
18 18
     }
19 19
     
20
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
20
+    if (version_compare($wpi_version, '0.0.5', '<')) {
21 21
         wpinv_v005_upgrades();
22 22
     }
23 23
     
24
-    update_option( 'wpinv_version', WPINV_VERSION );
24
+    update_option('wpinv_version', WPINV_VERSION);
25 25
 }
26
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
26
+add_action('admin_init', 'wpinv_automatic_upgrade');
27 27
 
28 28
 function wpinv_v005_upgrades() {
29 29
     global $wpdb;
30 30
     
31 31
     // Invoices status
32
-    $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
33
-    if ( !empty( $results ) ) {
34
-        $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
32
+    $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
33
+    if (!empty($results)) {
34
+        $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
35 35
         
36 36
         // Clean post cache
37
-        foreach ( $results as $row ) {
38
-            clean_post_cache( $row->ID );
37
+        foreach ($results as $row) {
38
+            clean_post_cache($row->ID);
39 39
         }
40 40
     }
41 41
     
42 42
     // Item meta key changes
43 43
     $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
44
-    $results = $wpdb->get_results( $query );
44
+    $results = $wpdb->get_results($query);
45 45
     
46
-    if ( !empty( $results ) ) {
47
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
48
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
49
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
46
+    if (!empty($results)) {
47
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
48
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
49
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
50 50
         
51
-        foreach ( $results as $row ) {
52
-            clean_post_cache( $row->post_id );
51
+        foreach ($results as $row) {
52
+            clean_post_cache($row->post_id);
53 53
         }
54 54
     }
55 55
 
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Spacing   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        @header( 'X-Robots-Tag: noindex' );
53
+        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -77,39 +77,39 @@  discard block
 block discarded – undo
77 77
             'buy_items' => true,
78 78
         );
79 79
 
80
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
81
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
80
+        foreach ($ajax_events as $ajax_event => $nopriv) {
81
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
82 82
             
83
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
84
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
83
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
84
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
85 85
             }
86 86
 
87
-            if ( $nopriv ) {
88
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
87
+            if ($nopriv) {
88
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
89 89
 
90
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
90
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
91 91
             }
92 92
         }
93 93
     }
94 94
     
95 95
     public static function add_note() {
96
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
96
+        check_ajax_referer('add-invoice-note', '_nonce');
97 97
 
98
-        if ( !current_user_can( 'manage_options' ) ) {
98
+        if (!current_user_can('manage_options')) {
99 99
             die(-1);
100 100
         }
101 101
 
102
-        $post_id   = absint( $_POST['post_id'] );
103
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
104
-        $note_type = sanitize_text_field( $_POST['note_type'] );
102
+        $post_id   = absint($_POST['post_id']);
103
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
104
+        $note_type = sanitize_text_field($_POST['note_type']);
105 105
 
106 106
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
107 107
 
108
-        if ( $post_id > 0 ) {
109
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
108
+        if ($post_id > 0) {
109
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
110 110
 
111
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
112
-                wpinv_get_invoice_note_line_item( $note_id );
111
+            if ($note_id > 0 && !is_wp_error($note_id)) {
112
+                wpinv_get_invoice_note_line_item($note_id);
113 113
             }
114 114
         }
115 115
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
     }
118 118
 
119 119
     public static function delete_note() {
120
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
120
+        check_ajax_referer('delete-invoice-note', '_nonce');
121 121
 
122
-        if ( !current_user_can( 'manage_options' ) ) {
122
+        if (!current_user_can('manage_options')) {
123 123
             die(-1);
124 124
         }
125 125
 
126 126
         $note_id = (int)$_POST['note_id'];
127 127
 
128
-        if ( $note_id > 0 ) {
129
-            wp_delete_comment( $note_id, true );
128
+        if ($note_id > 0) {
129
+            wp_delete_comment($note_id, true);
130 130
         }
131 131
 
132 132
         die();
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
     }
140 140
     
141 141
     public static function checkout() {
142
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
143
-            define( 'WPINV_CHECKOUT', true );
142
+        if (!defined('WPINV_CHECKOUT')) {
143
+            define('WPINV_CHECKOUT', true);
144 144
         }
145 145
 
146 146
         wpinv_process_checkout();
@@ -149,53 +149,53 @@  discard block
 block discarded – undo
149 149
     
150 150
     public static function add_invoice_item() {
151 151
         global $wpi_userID, $wpinv_ip_address_country;
152
-        check_ajax_referer( 'invoice-item', '_nonce' );
153
-        if ( !current_user_can( 'manage_options' ) ) {
152
+        check_ajax_referer('invoice-item', '_nonce');
153
+        if (!current_user_can('manage_options')) {
154 154
             die(-1);
155 155
         }
156 156
         
157
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
158
-        $invoice_id = absint( $_POST['invoice_id'] );
157
+        $item_id    = sanitize_text_field($_POST['item_id']);
158
+        $invoice_id = absint($_POST['invoice_id']);
159 159
         
160
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
160
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
161 161
             die();
162 162
         }
163 163
         
164
-        $invoice    = wpinv_get_invoice( $invoice_id );
165
-        if ( empty( $invoice ) ) {
164
+        $invoice = wpinv_get_invoice($invoice_id);
165
+        if (empty($invoice)) {
166 166
             die();
167 167
         }
168 168
         
169
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
169
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
170 170
             die(); // Don't allow modify items for paid invoice.
171 171
         }
172 172
         
173
-        if ( !empty( $_POST['user_id'] ) ) {
174
-            $wpi_userID = absint( $_POST['user_id'] ); 
173
+        if (!empty($_POST['user_id'])) {
174
+            $wpi_userID = absint($_POST['user_id']); 
175 175
         }
176 176
 
177
-        $item = new WPInv_Item( $item_id );
178
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
177
+        $item = new WPInv_Item($item_id);
178
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
179 179
             die();
180 180
         }
181 181
         
182 182
         // Validate item before adding to invoice because recurring item must be paid individually.
183
-        if ( !empty( $invoice->cart_details ) ) {
183
+        if (!empty($invoice->cart_details)) {
184 184
             $valid = true;
185 185
             
186
-            if ( $recurring_item = $invoice->get_recurring() ) {
187
-                if ( $recurring_item != $item_id ) {
186
+            if ($recurring_item = $invoice->get_recurring()) {
187
+                if ($recurring_item != $item_id) {
188 188
                     $valid = false;
189 189
                 }
190
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
190
+            } else if (wpinv_is_recurring_item($item_id)) {
191 191
                 $valid = false;
192 192
             }
193 193
             
194
-            if ( !$valid ) {
194
+            if (!$valid) {
195 195
                 $response               = array();
196 196
                 $response['success']    = false;
197
-                $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
198
-                wp_send_json( $response );
197
+                $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
198
+                wp_send_json($response);
199 199
             }
200 200
         }
201 201
         
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
         
204 204
         $data                   = array();
205 205
         $data['invoice_id']     = $invoice_id;
206
-        $data['cart_discounts'] = $invoice->get_discounts( true );
206
+        $data['cart_discounts'] = $invoice->get_discounts(true);
207 207
         
208
-        wpinv_set_checkout_session( $data );
208
+        wpinv_set_checkout_session($data);
209 209
         
210 210
         $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
211 211
 
@@ -220,21 +220,21 @@  discard block
 block discarded – undo
220 220
             'fees'          => array()
221 221
         );
222 222
 
223
-        $invoice->add_item( $item_id, $args );
223
+        $invoice->add_item($item_id, $args);
224 224
         $invoice->save();
225 225
         
226
-        if ( empty( $_POST['country'] ) ) {
226
+        if (empty($_POST['country'])) {
227 227
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
228 228
         }
229
-        if ( empty( $_POST['state'] ) ) {
229
+        if (empty($_POST['state'])) {
230 230
             $_POST['state'] = $invoice->state;
231 231
         }
232 232
          
233
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
234
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
233
+        $invoice->country   = sanitize_text_field($_POST['country']);
234
+        $invoice->state     = sanitize_text_field($_POST['state']);
235 235
         
236
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
237
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
236
+        $invoice->set('country', sanitize_text_field($_POST['country']));
237
+        $invoice->set('state', sanitize_text_field($_POST['state']));
238 238
         
239 239
         $wpinv_ip_address_country = $invoice->country;
240 240
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         
243 243
         $response                       = array();
244 244
         $response['success']            = true;
245
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
245
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
246 246
         $response['data']['subtotal']   = $invoice->get_subtotal();
247 247
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
248 248
         $response['data']['tax']        = $invoice->get_tax();
@@ -254,40 +254,40 @@  discard block
 block discarded – undo
254 254
         
255 255
         wpinv_set_checkout_session($checkout_session);
256 256
         
257
-        wp_send_json( $response );
257
+        wp_send_json($response);
258 258
     }
259 259
     
260 260
     public static function remove_invoice_item() {
261 261
         global $wpi_userID, $wpinv_ip_address_country;
262 262
         
263
-        check_ajax_referer( 'invoice-item', '_nonce' );
264
-        if ( !current_user_can( 'manage_options' ) ) {
263
+        check_ajax_referer('invoice-item', '_nonce');
264
+        if (!current_user_can('manage_options')) {
265 265
             die(-1);
266 266
         }
267 267
         
268
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
269
-        $invoice_id = absint( $_POST['invoice_id'] );
270
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
268
+        $item_id    = sanitize_text_field($_POST['item_id']);
269
+        $invoice_id = absint($_POST['invoice_id']);
270
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
271 271
         
272
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
272
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
273 273
             die();
274 274
         }
275 275
 
276
-        $invoice    = wpinv_get_invoice( $invoice_id );
277
-        if ( empty( $invoice ) ) {
276
+        $invoice = wpinv_get_invoice($invoice_id);
277
+        if (empty($invoice)) {
278 278
             die();
279 279
         }
280 280
         
281
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
281
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
282 282
             die(); // Don't allow modify items for paid invoice.
283 283
         }
284 284
         
285
-        if ( !empty( $_POST['user_id'] ) ) {
286
-            $wpi_userID = absint( $_POST['user_id'] ); 
285
+        if (!empty($_POST['user_id'])) {
286
+            $wpi_userID = absint($_POST['user_id']); 
287 287
         }
288 288
 
289
-        $item       = new WPInv_Item( $item_id );
290
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
289
+        $item = new WPInv_Item($item_id);
290
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
291 291
             die();
292 292
         }
293 293
         
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
         
296 296
         $data                   = array();
297 297
         $data['invoice_id']     = $invoice_id;
298
-        $data['cart_discounts'] = $invoice->get_discounts( true );
298
+        $data['cart_discounts'] = $invoice->get_discounts(true);
299 299
         
300
-        wpinv_set_checkout_session( $data );
300
+        wpinv_set_checkout_session($data);
301 301
 
302 302
         $args = array(
303 303
             'id'         => $item_id,
@@ -305,21 +305,21 @@  discard block
 block discarded – undo
305 305
             'cart_index' => $cart_index
306 306
         );
307 307
 
308
-        $invoice->remove_item( $item_id, $args );
308
+        $invoice->remove_item($item_id, $args);
309 309
         $invoice->save();
310 310
         
311
-        if ( empty( $_POST['country'] ) ) {
311
+        if (empty($_POST['country'])) {
312 312
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
313 313
         }
314
-        if ( empty( $_POST['state'] ) ) {
314
+        if (empty($_POST['state'])) {
315 315
             $_POST['state'] = $invoice->state;
316 316
         }
317 317
          
318
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
319
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
318
+        $invoice->country   = sanitize_text_field($_POST['country']);
319
+        $invoice->state     = sanitize_text_field($_POST['state']);
320 320
         
321
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
322
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
321
+        $invoice->set('country', sanitize_text_field($_POST['country']));
322
+        $invoice->set('state', sanitize_text_field($_POST['state']));
323 323
         
324 324
         $wpinv_ip_address_country = $invoice->country;
325 325
         
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         
328 328
         $response                       = array();
329 329
         $response['success']            = true;
330
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
330
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
331 331
         $response['data']['subtotal']   = $invoice->get_subtotal();
332 332
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
333 333
         $response['data']['tax']        = $invoice->get_tax();
@@ -339,40 +339,40 @@  discard block
 block discarded – undo
339 339
         
340 340
         wpinv_set_checkout_session($checkout_session);
341 341
         
342
-        wp_send_json( $response );
342
+        wp_send_json($response);
343 343
     }
344 344
     
345 345
     public static function create_invoice_item() {
346
-        check_ajax_referer( 'invoice-item', '_nonce' );
347
-        if ( !current_user_can( 'manage_options' ) ) {
346
+        check_ajax_referer('invoice-item', '_nonce');
347
+        if (!current_user_can('manage_options')) {
348 348
             die(-1);
349 349
         }
350 350
         
351
-        $invoice_id = absint( $_POST['invoice_id'] );
351
+        $invoice_id = absint($_POST['invoice_id']);
352 352
 
353 353
         // Find the item
354
-        if ( !is_numeric( $invoice_id ) ) {
354
+        if (!is_numeric($invoice_id)) {
355 355
             die();
356 356
         }        
357 357
         
358
-        $invoice     = wpinv_get_invoice( $invoice_id );
359
-        if ( empty( $invoice ) ) {
358
+        $invoice = wpinv_get_invoice($invoice_id);
359
+        if (empty($invoice)) {
360 360
             die();
361 361
         }
362 362
         
363 363
         // Validate item before adding to invoice because recurring item must be paid individually.
364
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
364
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
365 365
             $response               = array();
366 366
             $response['success']    = false;
367
-            $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
368
-            wp_send_json( $response );
367
+            $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
368
+            wp_send_json($response);
369 369
         }        
370 370
         
371 371
         $save_item = $_POST['_wpinv_quick'];
372 372
         
373 373
         $meta               = array();
374 374
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
375
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
375
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
376 376
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
377 377
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
378 378
         
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
         $data['meta']           = $meta;
383 383
         
384 384
         $item = new WPInv_Item();
385
-        $item->create( $data );
385
+        $item->create($data);
386 386
         
387
-        if ( !empty( $item ) ) {
387
+        if (!empty($item)) {
388 388
             $_POST['item_id']   = $item->ID;
389 389
             $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
390 390
             
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
     }
395 395
     
396 396
     public static function get_billing_details() {
397
-        check_ajax_referer( 'get-billing-details', '_nonce' );
397
+        check_ajax_referer('get-billing-details', '_nonce');
398 398
         
399
-        if ( !current_user_can( 'manage_options' ) ) {
399
+        if (!current_user_can('manage_options')) {
400 400
             die(-1);
401 401
         }
402 402
 
403 403
         $user_id            = (int)$_POST['user_id'];
404 404
         $billing_details    = wpinv_get_user_address($user_id);
405
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
405
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
406 406
         
407 407
         if (isset($billing_details['user_id'])) {
408 408
             unset($billing_details['user_id']);
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
         $response['success']                    = true;
417 417
         $response['data']['billing_details']    = $billing_details;
418 418
         
419
-        wp_send_json( $response );
419
+        wp_send_json($response);
420 420
     }
421 421
     
422 422
     public static function admin_recalculate_totals() {
423 423
         global $wpi_userID, $wpinv_ip_address_country;
424 424
         
425
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
426
-        if ( !current_user_can( 'manage_options' ) ) {
425
+        check_ajax_referer('wpinv-nonce', '_nonce');
426
+        if (!current_user_can('manage_options')) {
427 427
             die(-1);
428 428
         }
429 429
         
430
-        $invoice_id = absint( $_POST['invoice_id'] );        
431
-        $invoice    = wpinv_get_invoice( $invoice_id );
432
-        if ( empty( $invoice ) ) {
430
+        $invoice_id = absint($_POST['invoice_id']);        
431
+        $invoice    = wpinv_get_invoice($invoice_id);
432
+        if (empty($invoice)) {
433 433
             die();
434 434
         }
435 435
         
@@ -437,23 +437,23 @@  discard block
 block discarded – undo
437 437
         
438 438
         $data                   = array();
439 439
         $data['invoice_id']     = $invoice_id;
440
-        $data['cart_discounts'] = $invoice->get_discounts( true );
440
+        $data['cart_discounts'] = $invoice->get_discounts(true);
441 441
         
442
-        wpinv_set_checkout_session( $data );
442
+        wpinv_set_checkout_session($data);
443 443
         
444
-        if ( !empty( $_POST['user_id'] ) ) {
445
-            $wpi_userID = absint( $_POST['user_id'] ); 
444
+        if (!empty($_POST['user_id'])) {
445
+            $wpi_userID = absint($_POST['user_id']); 
446 446
         }
447 447
         
448
-        if ( empty( $_POST['country'] ) ) {
448
+        if (empty($_POST['country'])) {
449 449
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
450 450
         }
451 451
             
452
-        $invoice->country = sanitize_text_field( $_POST['country'] );
453
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
454
-        if ( isset( $_POST['state'] ) ) {
455
-            $invoice->state = sanitize_text_field( $_POST['state'] );
456
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
452
+        $invoice->country = sanitize_text_field($_POST['country']);
453
+        $invoice->set('country', sanitize_text_field($_POST['country']));
454
+        if (isset($_POST['state'])) {
455
+            $invoice->state = sanitize_text_field($_POST['state']);
456
+            $invoice->set('state', sanitize_text_field($_POST['state']));
457 457
         }
458 458
         
459 459
         $wpinv_ip_address_country = $invoice->country;
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         
463 463
         $response                       = array();
464 464
         $response['success']            = true;
465
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
465
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
466 466
         $response['data']['subtotal']   = $invoice->get_subtotal();
467 467
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
468 468
         $response['data']['tax']        = $invoice->get_tax();
@@ -474,25 +474,25 @@  discard block
 block discarded – undo
474 474
         
475 475
         wpinv_set_checkout_session($checkout_session);
476 476
         
477
-        wp_send_json( $response );
477
+        wp_send_json($response);
478 478
     }
479 479
     
480 480
     public static function admin_apply_discount() {
481 481
         global $wpi_userID;
482 482
         
483
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
484
-        if ( !current_user_can( 'manage_options' ) ) {
483
+        check_ajax_referer('wpinv-nonce', '_nonce');
484
+        if (!current_user_can('manage_options')) {
485 485
             die(-1);
486 486
         }
487 487
         
488
-        $invoice_id = absint( $_POST['invoice_id'] );
489
-        $discount_code = sanitize_text_field( $_POST['code'] );
490
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
488
+        $invoice_id = absint($_POST['invoice_id']);
489
+        $discount_code = sanitize_text_field($_POST['code']);
490
+        if (empty($invoice_id) || empty($discount_code)) {
491 491
             die();
492 492
         }
493 493
         
494
-        $invoice = wpinv_get_invoice( $invoice_id );
495
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
494
+        $invoice = wpinv_get_invoice($invoice_id);
495
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
496 496
             die();
497 497
         }
498 498
         
@@ -500,49 +500,49 @@  discard block
 block discarded – undo
500 500
         
501 501
         $data                   = array();
502 502
         $data['invoice_id']     = $invoice_id;
503
-        $data['cart_discounts'] = $invoice->get_discounts( true );
503
+        $data['cart_discounts'] = $invoice->get_discounts(true);
504 504
         
505
-        wpinv_set_checkout_session( $data );
505
+        wpinv_set_checkout_session($data);
506 506
         
507 507
         $response               = array();
508 508
         $response['success']    = false;
509
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
509
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
510 510
         $response['data']['code'] = $discount_code;
511 511
         
512
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
513
-            $discounts = wpinv_set_cart_discount( $discount_code );
512
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
513
+            $discounts = wpinv_set_cart_discount($discount_code);
514 514
             
515 515
             $response['success'] = true;
516
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
517
-        }  else {
516
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
517
+        } else {
518 518
             $errors = wpinv_get_errors();
519
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
519
+            if (!empty($errors['wpinv-discount-error'])) {
520 520
                 $response['msg'] = $errors['wpinv-discount-error'];
521 521
             }
522
-            wpinv_unset_error( 'wpinv-discount-error' );
522
+            wpinv_unset_error('wpinv-discount-error');
523 523
         }
524 524
         
525 525
         wpinv_set_checkout_session($checkout_session);
526 526
         
527
-        wp_send_json( $response );
527
+        wp_send_json($response);
528 528
     }
529 529
     
530 530
     public static function admin_remove_discount() {
531 531
         global $wpi_userID;
532 532
         
533
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
534
-        if ( !current_user_can( 'manage_options' ) ) {
533
+        check_ajax_referer('wpinv-nonce', '_nonce');
534
+        if (!current_user_can('manage_options')) {
535 535
             die(-1);
536 536
         }
537 537
         
538
-        $invoice_id = absint( $_POST['invoice_id'] );
539
-        $discount_code = sanitize_text_field( $_POST['code'] );
540
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
538
+        $invoice_id = absint($_POST['invoice_id']);
539
+        $discount_code = sanitize_text_field($_POST['code']);
540
+        if (empty($invoice_id) || empty($discount_code)) {
541 541
             die();
542 542
         }
543 543
         
544
-        $invoice = wpinv_get_invoice( $invoice_id );
545
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
544
+        $invoice = wpinv_get_invoice($invoice_id);
545
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
546 546
             die();
547 547
         }
548 548
         
@@ -550,38 +550,38 @@  discard block
 block discarded – undo
550 550
         
551 551
         $data                   = array();
552 552
         $data['invoice_id']     = $invoice_id;
553
-        $data['cart_discounts'] = $invoice->get_discounts( true );
553
+        $data['cart_discounts'] = $invoice->get_discounts(true);
554 554
         
555
-        wpinv_set_checkout_session( $data );
555
+        wpinv_set_checkout_session($data);
556 556
         
557 557
         $response               = array();
558 558
         $response['success']    = false;
559 559
         $response['msg']        = NULL;
560 560
         
561
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
561
+        $discounts = wpinv_unset_cart_discount($discount_code);
562 562
         $response['success'] = true;
563
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
563
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
564 564
         
565 565
         wpinv_set_checkout_session($checkout_session);
566 566
         
567
-        wp_send_json( $response );
567
+        wp_send_json($response);
568 568
     }
569 569
     
570 570
     public static function check_email() {
571
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
572
-        if ( !current_user_can( 'manage_options' ) ) {
571
+        check_ajax_referer('wpinv-nonce', '_nonce');
572
+        if (!current_user_can('manage_options')) {
573 573
             die(-1);
574 574
         }
575 575
         
576
-        $email = sanitize_text_field( $_POST['email'] );
576
+        $email = sanitize_text_field($_POST['email']);
577 577
         
578 578
         $response = array();
579
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
579
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
580 580
             $user_id            = $user_data->ID;
581 581
             $user_login         = $user_data->user_login;
582 582
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
583 583
             $billing_details    = wpinv_get_user_address($user_id);
584
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
584
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
585 585
             
586 586
             if (isset($billing_details['user_id'])) {
587 587
                 unset($billing_details['user_id']);
@@ -597,54 +597,54 @@  discard block
 block discarded – undo
597 597
             $response['data']['billing_details']    = $billing_details;
598 598
         }
599 599
         
600
-        wp_send_json( $response );
600
+        wp_send_json($response);
601 601
     }
602 602
     
603 603
     public static function run_tool() {
604
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
605
-        if ( !current_user_can( 'manage_options' ) ) {
604
+        check_ajax_referer('wpinv-nonce', '_nonce');
605
+        if (!current_user_can('manage_options')) {
606 606
             die(-1);
607 607
         }
608 608
         
609
-        $tool = sanitize_text_field( $_POST['tool'] );
609
+        $tool = sanitize_text_field($_POST['tool']);
610 610
         
611
-        do_action( 'wpinv_run_tool' );
611
+        do_action('wpinv_run_tool');
612 612
         
613
-        if ( !empty( $tool ) ) {
614
-            do_action( 'wpinv_tool_' . $tool );
613
+        if (!empty($tool)) {
614
+            do_action('wpinv_tool_' . $tool);
615 615
         }
616 616
     }
617 617
     
618 618
     public static function apply_discount() {
619 619
         global $wpi_userID;
620 620
         
621
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
621
+        check_ajax_referer('wpinv-nonce', '_nonce');
622 622
         
623 623
         $response = array();
624 624
         
625
-        if ( isset( $_POST['code'] ) ) {
626
-            $discount_code = sanitize_text_field( $_POST['code'] );
625
+        if (isset($_POST['code'])) {
626
+            $discount_code = sanitize_text_field($_POST['code']);
627 627
 
628 628
             $response['success']        = false;
629 629
             $response['msg']            = '';
630 630
             $response['data']['code']   = $discount_code;
631 631
             
632 632
             $invoice = wpinv_get_invoice_cart();
633
-            if ( empty( $invoice->ID ) ) {
634
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
635
-                wp_send_json( $response );
633
+            if (empty($invoice->ID)) {
634
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
635
+                wp_send_json($response);
636 636
             }
637 637
 
638 638
             $wpi_userID = $invoice->get_user_id();
639 639
 
640
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
641
-                $discount       = wpinv_get_discount_by_code( $discount_code );
642
-                $discounts      = wpinv_set_cart_discount( $discount_code );
643
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
644
-                $total          = wpinv_get_cart_total( null, $discounts );
645
-                $cart_totals    = wpinv_recalculate_tax( true );
640
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
641
+                $discount       = wpinv_get_discount_by_code($discount_code);
642
+                $discounts      = wpinv_set_cart_discount($discount_code);
643
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
644
+                $total          = wpinv_get_cart_total(null, $discounts);
645
+                $cart_totals    = wpinv_recalculate_tax(true);
646 646
             
647
-                if ( !empty( $cart_totals ) ) {
647
+                if (!empty($cart_totals)) {
648 648
                     $response['success']        = true;
649 649
                     $response['data']           = $cart_totals;
650 650
                     $response['data']['code']   = $discount_code;
@@ -653,29 +653,29 @@  discard block
 block discarded – undo
653 653
                 }
654 654
             } else {
655 655
                 $errors = wpinv_get_errors();
656
-                $response['msg']  = $errors['wpinv-discount-error'];
657
-                wpinv_unset_error( 'wpinv-discount-error' );
656
+                $response['msg'] = $errors['wpinv-discount-error'];
657
+                wpinv_unset_error('wpinv-discount-error');
658 658
             }
659 659
 
660 660
             // Allow for custom discount code handling
661
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
661
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
662 662
         }
663 663
         
664
-        wp_send_json( $response );
664
+        wp_send_json($response);
665 665
     }
666 666
     
667 667
     public static function remove_discount() {
668
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
668
+        check_ajax_referer('wpinv-nonce', '_nonce');
669 669
         
670 670
         $response = array();
671 671
         
672
-        if ( isset( $_POST['code'] ) ) {
673
-            $discount_code  = sanitize_text_field( $_POST['code'] );
674
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
675
-            $total          = wpinv_get_cart_total( null, $discounts );
676
-            $cart_totals    = wpinv_recalculate_tax( true );
672
+        if (isset($_POST['code'])) {
673
+            $discount_code  = sanitize_text_field($_POST['code']);
674
+            $discounts      = wpinv_unset_cart_discount($discount_code);
675
+            $total          = wpinv_get_cart_total(null, $discounts);
676
+            $cart_totals    = wpinv_recalculate_tax(true);
677 677
             
678
-            if ( !empty( $cart_totals ) ) {
678
+            if (!empty($cart_totals)) {
679 679
                 $response['success']        = true;
680 680
                 $response['data']           = $cart_totals;
681 681
                 $response['data']['code']   = $discount_code;
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
             }
685 685
             
686 686
             // Allow for custom discount code handling
687
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
687
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
688 688
         }
689 689
         
690
-        wp_send_json( $response );
690
+        wp_send_json($response);
691 691
     }
692 692
 
693 693
 
@@ -696,20 +696,20 @@  discard block
 block discarded – undo
696 696
      *
697 697
      * @since 1.0.0
698 698
      */
699
-    public function buy_items(){
699
+    public function buy_items() {
700 700
 
701 701
         $user_id = get_current_user_id();
702
-        if(!$user_id ){ // if not logged in then lets redirect to the login page
702
+        if (!$user_id) { // if not logged in then lets redirect to the login page
703 703
 
704 704
             wp_send_json(array(
705
-                'success' => wp_login_url( wp_get_referer() )
705
+                'success' => wp_login_url(wp_get_referer())
706 706
             ));
707
-        }else{
707
+        } else {
708 708
 
709 709
             // only check nonce if logged in as it could be cached when logged out.
710
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
710
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
711 711
                 wp_send_json(array(
712
-                    'error' => __('Security checks failed.','invoicing')
712
+                    'error' => __('Security checks failed.', 'invoicing')
713 713
                 ));
714 714
                 wp_die();
715 715
             }
@@ -717,36 +717,36 @@  discard block
 block discarded – undo
717 717
             // allow to set a custom price through post_id
718 718
             $items = $_POST['items'];
719 719
             $related_post_id = isset($_POST['post_id']) ? (int)$_POST['post_id'] : 0;
720
-            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id,'_wpi_custom_price',true)) : 0;
720
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
721 721
 
722 722
 
723 723
             $cart_items = array();
724
-            if($items){
725
-                $items = explode(',',$items);
726
-                foreach($items as $item){
724
+            if ($items) {
725
+                $items = explode(',', $items);
726
+                foreach ($items as $item) {
727 727
                     $item_id = $item;
728 728
                     $quantity = 1;
729 729
                     if (strpos($item, '|') !== false) {
730
-                        $item_parts = explode('|',$item);
730
+                        $item_parts = explode('|', $item);
731 731
                         $item_id = $item_parts[0];
732 732
                         $quantity = $item_parts[1];
733 733
                     }
734 734
 
735
-                    if($item_id && $quantity){
735
+                    if ($item_id && $quantity) {
736 736
                         $cart_items_arr = array(
737 737
                             'id'            => (int)$item_id,
738 738
                             'quantity'      => (int)$quantity
739 739
                         );
740 740
 
741 741
                         // if there is a related post id then add it to meta
742
-                        if($related_post_id){
742
+                        if ($related_post_id) {
743 743
                             $cart_items_arr['meta'] = array(
744 744
                                 'post_id'   => $related_post_id
745 745
                             );
746 746
                         }
747 747
 
748 748
                         // if there is a custom price then set it.
749
-                        if($custom_item_price){
749
+                        if ($custom_item_price) {
750 750
                             $cart_items_arr['custom_price'] = $custom_item_price;
751 751
 
752 752
                         }
@@ -765,12 +765,12 @@  discard block
 block discarded – undo
765 765
              * @param int $related_post_id The related post id if any.
766 766
              * @since 1.0.0
767 767
              */
768
-            $cart_items = apply_filters('wpinv_buy_cart_items',$cart_items,$related_post_id);
768
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
769 769
 
770 770
 
771 771
             //make sure its not in the cart already, if it is then redirect to checkout.
772 772
             $cart_invoice = wpinv_get_invoice_cart();
773
-            if(isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items)==serialize($cart_items) ){
773
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
774 774
                 wp_send_json(array(
775 775
                     'success' =>  $cart_invoice->get_checkout_payment_url()
776 776
                 ));
@@ -779,25 +779,25 @@  discard block
 block discarded – undo
779 779
 
780 780
 
781 781
             // check if user has invoice with same items waiting to be paid.
782
-            $user_invoices = wpinv_get_users_invoices( $user_id , 1 , false , 'pending' );
783
-            if(!empty($user_invoices)){
782
+            $user_invoices = wpinv_get_users_invoices($user_id, 1, false, 'pending');
783
+            if (!empty($user_invoices)) {
784 784
 
785
-                foreach($user_invoices as $user_invoice){
785
+                foreach ($user_invoices as $user_invoice) {
786 786
                     $user_cart_details = array();
787
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
787
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
788 788
                     $cart_details = $invoice->get_cart_details();
789
-                    if(!empty($cart_details)){
790
-                        foreach($cart_details as $invoice_item){
789
+                    if (!empty($cart_details)) {
790
+                        foreach ($cart_details as $invoice_item) {
791 791
 
792 792
                             $ii_arr = array();
793 793
                             $ii_arr['id'] = (int)$invoice_item['id'];
794 794
                             $ii_arr['quantity'] = (int)$invoice_item['quantity'];
795 795
 
796
-                            if(isset($invoice_item['meta']) && !empty($invoice_item['meta'])){
796
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
797 797
                                 $ii_arr['meta'] = $invoice_item['meta'];
798 798
                             }
799 799
 
800
-                            if(isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])){
800
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
801 801
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
802 802
                             }
803 803
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
                         }
807 807
                     }
808 808
 
809
-                    if(!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)){
809
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
810 810
                         wp_send_json(array(
811 811
                             'success' =>  $invoice->get_checkout_payment_url()
812 812
                         ));
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 
820 820
 
821 821
             // Create invoice and send user to checkout
822
-            if(!empty($cart_items)){
822
+            if (!empty($cart_items)) {
823 823
 
824 824
                 $invoice_data = array(
825 825
                     'status'        =>  'wpi-pending',
@@ -829,26 +829,26 @@  discard block
 block discarded – undo
829 829
                 );
830 830
 
831 831
                 // default invoice args
832
-                $invoice_data['status']  = !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending';
833
-                $invoice_data['user_id'] = !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id();
832
+                $invoice_data['status']  = !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending';
833
+                $invoice_data['user_id'] = !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id();
834 834
 
835
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
835
+                $invoice = wpinv_insert_invoice($invoice_data, true);
836 836
 
837
-                if(isset($invoice->ID)){
837
+                if (isset($invoice->ID)) {
838 838
 
839 839
                     wp_send_json(array(
840 840
                         'success' =>  $invoice->get_checkout_payment_url()
841 841
                     ));
842 842
 
843
-                }else{
843
+                } else {
844 844
                     wp_send_json(array(
845
-                        'error' => __('Invoice failed to create','invoicing')
845
+                        'error' => __('Invoice failed to create', 'invoicing')
846 846
                     ));
847 847
                 }
848 848
 
849
-            }else{
849
+            } else {
850 850
                 wp_send_json(array(
851
-                    'error' => __('Items not valid.','invoicing')
851
+                    'error' => __('Items not valid.', 'invoicing')
852 852
                 ));
853 853
             }
854 854
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
             
515 515
             $response['success'] = true;
516 516
             $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
517
-        }  else {
517
+        } else {
518 518
             $errors = wpinv_get_errors();
519 519
             if ( !empty( $errors['wpinv-discount-error'] ) ) {
520 520
                 $response['msg'] = $errors['wpinv-discount-error'];
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
             wp_send_json(array(
705 705
                 'success' => wp_login_url( wp_get_referer() )
706 706
             ));
707
-        }else{
707
+        } else{
708 708
 
709 709
             // only check nonce if logged in as it could be cached when logged out.
710 710
             if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
@@ -840,13 +840,13 @@  discard block
 block discarded – undo
840 840
                         'success' =>  $invoice->get_checkout_payment_url()
841 841
                     ));
842 842
 
843
-                }else{
843
+                } else{
844 844
                     wp_send_json(array(
845 845
                         'error' => __('Invoice failed to create','invoicing')
846 846
                     ));
847 847
                 }
848 848
 
849
-            }else{
849
+            } else{
850 850
                 wp_send_json(array(
851 851
                     'error' => __('Items not valid.','invoicing')
852 852
                 ));
Please login to merge, or discard this patch.
templates/wpinv-invalid-access.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,56 +1,56 @@
 block discarded – undo
1 1
 <?php 
2
-if ( !defined('ABSPATH') ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit;
4 4
 }
5
-do_action( 'wpinv_invalid_invoice_before_display' ); ?><!DOCTYPE html>
5
+do_action('wpinv_invalid_invoice_before_display'); ?><!DOCTYPE html>
6 6
 <html <?php language_attributes(); ?>>
7 7
 <head>
8 8
     <meta charset="UTF-8">
9 9
     <title><?php wp_title() ?></title>
10
-    <meta charset="<?php bloginfo( 'charset' ); ?>" />
10
+    <meta charset="<?php bloginfo('charset'); ?>" />
11 11
     <meta name="viewport" content="width=device-width,initial-scale=1">
12 12
     <meta name="robots" content="noindex,nofollow">
13
-    <?php do_action( 'wpinv_invalid_invoice_head' ); ?>
13
+    <?php do_action('wpinv_invalid_invoice_head'); ?>
14 14
 </head>
15 15
 <body class="body wpinv wpinv-print wpinv-invalid-invoice">
16
-    <?php do_action( 'wpinv_invalid_invoice_body_start' ); ?>
16
+    <?php do_action('wpinv_invalid_invoice_body_start'); ?>
17 17
     <div class="container wpinv-wrap">
18 18
         <!-- ///// Start Header -->
19 19
         <htmlpageheader name="wpinv-pdf-header">
20
-            <?php do_action( 'wpinv_invalid_invoice_before_header' ); ?>
20
+            <?php do_action('wpinv_invalid_invoice_before_header'); ?>
21 21
             <div class="row wpinv-header">
22 22
                 <div class="col-xs-12 wpinv-business">
23
-                    <a target="_blank" href="<?php echo esc_url( wpinv_get_business_website() ); ?>">
24
-                        <?php if ( $logo = wpinv_get_business_logo() ) { ?>
25
-                        <img class="logo" src="<?php echo esc_url( $logo ); ?>">
23
+                    <a target="_blank" href="<?php echo esc_url(wpinv_get_business_website()); ?>">
24
+                        <?php if ($logo = wpinv_get_business_logo()) { ?>
25
+                        <img class="logo" src="<?php echo esc_url($logo); ?>">
26 26
                         <?php } else { ?>
27
-                        <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1>
27
+                        <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1>
28 28
                         <?php } ?>
29 29
                     </a>
30 30
                 </div>
31 31
             </div>
32
-            <?php do_action( 'wpinv_invalid_invoice_after_header' ); ?>
32
+            <?php do_action('wpinv_invalid_invoice_after_header'); ?>
33 33
         </htmlpageheader>
34 34
         <!-- End Header ///// -->
35 35
         
36
-        <?php do_action( 'wpinv_invalid_invoice_before_content' ); ?>
36
+        <?php do_action('wpinv_invalid_invoice_before_content'); ?>
37 37
 
38
-        <?php do_action( 'wpinv_invalid_invoice_content' ); ?>
38
+        <?php do_action('wpinv_invalid_invoice_content'); ?>
39 39
         
40
-        <?php do_action( 'wpinv_invalid_invoice_after_content' ); ?>
40
+        <?php do_action('wpinv_invalid_invoice_after_content'); ?>
41 41
         
42 42
         <!-- ///// Start Footer -->
43 43
         <htmlpagefooter name="wpinv-pdf-footer">
44
-            <?php do_action( 'wpinv_invalid_invoice_before_footer' ); ?>
44
+            <?php do_action('wpinv_invalid_invoice_before_footer'); ?>
45 45
             <div class="row wpinv-footer">
46 46
                 <div class="col-sm-12">
47 47
                     <div class="footer-text"><?php echo wpinv_get_business_footer(); ?></div>
48 48
                 </div>
49 49
             </div>
50
-            <?php do_action( 'wpinv_invalid_invoice_after_footer' ); ?>
50
+            <?php do_action('wpinv_invalid_invoice_after_footer'); ?>
51 51
         </htmlpagefooter>
52 52
         <!-- End Footer ///// -->
53 53
     </div>
54
-    <?php do_action( 'wpinv_invalid_invoice_body_end' ); ?>
54
+    <?php do_action('wpinv_invalid_invoice_body_end'); ?>
55 55
 </body>
56 56
 </html>
57 57
\ No newline at end of file
Please login to merge, or discard this patch.
uninstall.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -9,58 +9,58 @@
 block discarded – undo
9 9
  */
10 10
 
11 11
 // If uninstall not called from WordPress, then exit.
12
-if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
12
+if (!defined('WP_UNINSTALL_PLUGIN')) {
13 13
     exit;
14 14
 }
15 15
 
16 16
 global $wpdb, $wp_version;
17 17
 
18
-$remove_data = get_option( 'wpinv_remove_data_on_invoice_unistall' );
18
+$remove_data = get_option('wpinv_remove_data_on_invoice_unistall');
19 19
 
20 20
 /*
21 21
  * Only remove ALL product and page data if WPINV_REMOVE_ALL_DATA constant is set to true in user's
22 22
  * wp-config.php. This is to prevent data loss when deleting the plugin from the backend
23 23
  * and to ensure only the site owner can perform this action.
24 24
  */
25
-if ( defined( 'WPINV_REMOVE_ALL_DATA' ) ) {
25
+if (defined('WPINV_REMOVE_ALL_DATA')) {
26 26
     $remove_data = true === WPINV_REMOVE_ALL_DATA ? true : false;
27 27
 }
28 28
 
29
-if ( $remove_data ) {
29
+if ($remove_data) {
30 30
     // Load Invoicing file.
31
-    include_once( 'invoicing.php' );
31
+    include_once('invoicing.php');
32 32
 
33 33
     // Roles + caps.
34
-    include_once( dirname( __FILE__ ) . '/includes/admin/install.php' );
34
+    include_once(dirname(__FILE__) . '/includes/admin/install.php');
35 35
     wpinv_remove_admin_caps();
36 36
     
37
-    $settings = get_option( 'wpinv_settings' );
37
+    $settings = get_option('wpinv_settings');
38 38
     
39 39
     // Delete pages.
40
-    $wpi_pages = array( 'checkout_page', 'success_page', 'failure_page', 'invoice_history_page', 'quote_history_page' );
41
-    foreach ( $wpi_pages as $page ) {
42
-        if ( !empty( $page ) && !empty( $settings[ $page ] ) ) {
43
-            wp_delete_post( $settings[ $page ], true );
40
+    $wpi_pages = array('checkout_page', 'success_page', 'failure_page', 'invoice_history_page', 'quote_history_page');
41
+    foreach ($wpi_pages as $page) {
42
+        if (!empty($page) && !empty($settings[$page])) {
43
+            wp_delete_post($settings[$page], true);
44 44
         }
45 45
     }
46 46
     
47 47
     // Delete posts + data.
48
-    $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'wpi_invoice', 'wpi_item', 'wpi_discount', 'wpi_quote' );" );
49
-    $wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );
48
+    $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'wpi_invoice', 'wpi_item', 'wpi_discount', 'wpi_quote' );");
49
+    $wpdb->query("DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;");
50 50
     
51 51
     // Delete comments.
52
-    $wpdb->query( "DELETE FROM {$wpdb->comments} WHERE comment_type LIKE 'wpinv_note';" );
53
-    $wpdb->query( "DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;" );
52
+    $wpdb->query("DELETE FROM {$wpdb->comments} WHERE comment_type LIKE 'wpinv_note';");
53
+    $wpdb->query("DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;");
54 54
     
55 55
     // Delete user meta.
56
-    $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_wpinv_%' OR meta_key LIKE '%_wpi_invoice%' OR meta_key LIKE '%_wpi_item%' OR meta_key LIKE '%_wpi_discount%' OR meta_key LIKE '_wpi_stripe%' OR meta_key LIKE '%_wpi_quote%';" );
56
+    $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_wpinv_%' OR meta_key LIKE '%_wpi_invoice%' OR meta_key LIKE '%_wpi_item%' OR meta_key LIKE '%_wpi_discount%' OR meta_key LIKE '_wpi_stripe%' OR meta_key LIKE '%_wpi_quote%';");
57 57
     
58 58
     // Cleanup Cron Schedule
59
-    wp_clear_scheduled_hook( 'wp_session_garbage_collection' );
60
-    wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
59
+    wp_clear_scheduled_hook('wp_session_garbage_collection');
60
+    wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily');
61 61
     
62 62
     // Delete options.
63
-    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpinv_%' OR option_name LIKE '_wpinv_%' OR option_name LIKE '\_transient\_wpinv\_%';" );
63
+    $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpinv_%' OR option_name LIKE '_wpinv_%' OR option_name LIKE '\_transient\_wpinv\_%';");
64 64
     
65 65
     // Clear any cached data that has been removed
66 66
     wp_cache_flush();
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 1 patch
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_get_subscriptions( $args = array() ) {
3
-    if ( empty( $args['parent_invoice_id'] ) ) {
2
+function wpinv_get_subscriptions($args = array()) {
3
+    if (empty($args['parent_invoice_id'])) {
4 4
         return false;
5 5
     }
6 6
     
@@ -14,18 +14,18 @@  discard block
 block discarded – undo
14 14
     );
15 15
 
16 16
     $args['post_parent']    = $args['parent_invoice_id'];
17
-    $args                   = wp_parse_args( $args, $defaults );
17
+    $args                   = wp_parse_args($args, $defaults);
18 18
 
19
-    if( $args['numberposts'] < 1 ) {
19
+    if ($args['numberposts'] < 1) {
20 20
         $args['numberposts'] = 999999999999;
21 21
     }
22 22
 
23
-    $posts          = get_posts( $args );
23
+    $posts          = get_posts($args);
24 24
     $subscriptions  = array();
25
-    if ( !empty( $posts ) ) {
26
-        foreach ( $posts as $post ) {
27
-            if ( !empty( $post->ID ) ) {
28
-                $subscriptions[] = wpinv_get_invoice( $post->ID );
25
+    if (!empty($posts)) {
26
+        foreach ($posts as $post) {
27
+            if (!empty($post->ID)) {
28
+                $subscriptions[] = wpinv_get_invoice($post->ID);
29 29
             }
30 30
         }
31 31
     }
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
     
34 34
     return $subscriptions;
35 35
 }
36
-function wpinv_get_subscription( $id = 0, $by_profile_id = false ) {
36
+function wpinv_get_subscription($id = 0, $by_profile_id = false) {
37 37
     global $wpdb;
38 38
 
39
-    if ( empty( $id ) ) {
39
+    if (empty($id)) {
40 40
         return false;
41 41
     }
42 42
 
43
-    $id = esc_sql( $id );
43
+    $id = esc_sql($id);
44 44
 
45
-    $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" );
45
+    $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1");
46 46
 
47
-    if ( $invoice_id != null ) {
48
-        return wpinv_get_invoice( $invoice_id );
47
+    if ($invoice_id != null) {
48
+        return wpinv_get_invoice($invoice_id);
49 49
     }
50 50
 
51 51
     return false;
@@ -55,47 +55,47 @@  discard block
 block discarded – undo
55 55
  * Records a new payment on the subscription
56 56
  * 
57 57
  */
58
-function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) {    
59
-    $args = wp_parse_args( $subscription_args, array(
58
+function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) {    
59
+    $args = wp_parse_args($subscription_args, array(
60 60
         'amount'         => '',
61 61
         'transaction_id' => '',
62 62
         'gateway'        => ''
63
-    ) );
63
+    ));
64 64
 
65
-    if ( wpinv_payment_exists( $args['transaction_id'] ) ) {
65
+    if (wpinv_payment_exists($args['transaction_id'])) {
66 66
         return false;
67 67
     }
68 68
     
69
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
70
-    if ( empty( $parent_invoice ) ) {
69
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
70
+    if (empty($parent_invoice)) {
71 71
         return;
72 72
     }
73 73
 
74 74
     $invoice = new WPInv_Invoice();
75
-    $invoice->set( 'post_type', 'wpi_invoice' );
76
-    $invoice->set( 'parent_invoice', $parent_invoice_id );
77
-    $invoice->set( 'currency', $parent_invoice->get_currency() );
78
-    $invoice->set( 'transaction_id', $args['transaction_id'] );
79
-    $invoice->set( 'key', $parent_invoice->generate_key() );
80
-    $invoice->set( 'ip', $parent_invoice->ip );
81
-    $invoice->set( 'user_id', $parent_invoice->get_user_id() );
82
-    $invoice->set( 'first_name', $parent_invoice->get_first_name() );
83
-    $invoice->set( 'last_name', $parent_invoice->get_last_name() );
84
-    $invoice->set( 'phone', $parent_invoice->phone );
85
-    $invoice->set( 'address', $parent_invoice->address );
86
-    $invoice->set( 'city', $parent_invoice->city );
87
-    $invoice->set( 'country', $parent_invoice->country );
88
-    $invoice->set( 'state', $parent_invoice->state );
89
-    $invoice->set( 'zip', $parent_invoice->zip );
90
-    $invoice->set( 'company', $parent_invoice->company );
91
-    $invoice->set( 'vat_number', $parent_invoice->vat_number );
92
-    $invoice->set( 'vat_rate', $parent_invoice->vat_rate );
93
-    $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed );
94
-
95
-    if ( empty( $args['gateway'] ) ) {
96
-        $invoice->set( 'gateway', $parent_invoice->get_gateway() );
75
+    $invoice->set('post_type', 'wpi_invoice');
76
+    $invoice->set('parent_invoice', $parent_invoice_id);
77
+    $invoice->set('currency', $parent_invoice->get_currency());
78
+    $invoice->set('transaction_id', $args['transaction_id']);
79
+    $invoice->set('key', $parent_invoice->generate_key());
80
+    $invoice->set('ip', $parent_invoice->ip);
81
+    $invoice->set('user_id', $parent_invoice->get_user_id());
82
+    $invoice->set('first_name', $parent_invoice->get_first_name());
83
+    $invoice->set('last_name', $parent_invoice->get_last_name());
84
+    $invoice->set('phone', $parent_invoice->phone);
85
+    $invoice->set('address', $parent_invoice->address);
86
+    $invoice->set('city', $parent_invoice->city);
87
+    $invoice->set('country', $parent_invoice->country);
88
+    $invoice->set('state', $parent_invoice->state);
89
+    $invoice->set('zip', $parent_invoice->zip);
90
+    $invoice->set('company', $parent_invoice->company);
91
+    $invoice->set('vat_number', $parent_invoice->vat_number);
92
+    $invoice->set('vat_rate', $parent_invoice->vat_rate);
93
+    $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed);
94
+
95
+    if (empty($args['gateway'])) {
96
+        $invoice->set('gateway', $parent_invoice->get_gateway());
97 97
     } else {
98
-        $invoice->set( 'gateway', $args['gateway'] );
98
+        $invoice->set('gateway', $args['gateway']);
99 99
     }
100 100
     
101 101
     $recurring_details = $parent_invoice->get_recurring_details();
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
     // increase the earnings for each item in the subscription
104 104
     $items = $recurring_details['cart_details'];
105 105
     
106
-    if ( $items ) {        
106
+    if ($items) {        
107 107
         $add_items      = array();
108 108
         $cart_details   = array();
109 109
         
110
-        foreach ( $items as $item ) {
110
+        foreach ($items as $item) {
111 111
             $add_item             = array();
112 112
             $add_item['id']       = $item['id'];
113 113
             $add_item['quantity'] = $item['quantity'];
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
             break;
118 118
         }
119 119
         
120
-        $invoice->set( 'items', $add_items );
120
+        $invoice->set('items', $add_items);
121 121
         $invoice->cart_details = $cart_details;
122 122
     }
123 123
     
@@ -127,277 +127,277 @@  discard block
 block discarded – undo
127 127
     $tax                = $recurring_details['tax'];
128 128
     $discount           = $recurring_details['discount'];
129 129
     
130
-    if ( $discount > 0 ) {
131
-        $invoice->set( 'discount_code', $parent_invoice->discount_code );
130
+    if ($discount > 0) {
131
+        $invoice->set('discount_code', $parent_invoice->discount_code);
132 132
     }
133 133
     
134
-    $invoice->subtotal = wpinv_round_amount( $subtotal );
135
-    $invoice->tax      = wpinv_round_amount( $tax );
136
-    $invoice->discount = wpinv_round_amount( $discount );
137
-    $invoice->total    = wpinv_round_amount( $total );
134
+    $invoice->subtotal = wpinv_round_amount($subtotal);
135
+    $invoice->tax      = wpinv_round_amount($tax);
136
+    $invoice->discount = wpinv_round_amount($discount);
137
+    $invoice->total    = wpinv_round_amount($total);
138 138
     $invoice->save();
139 139
     
140
-    wpinv_update_payment_status( $invoice->ID, 'publish' );
140
+    wpinv_update_payment_status($invoice->ID, 'publish');
141 141
     sleep(1);
142
-    wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' );
142
+    wpinv_update_payment_status($invoice->ID, 'wpi-renewal');
143 143
     
144
-    $invoice = wpinv_get_invoice( $invoice->ID );
144
+    $invoice = wpinv_get_invoice($invoice->ID);
145 145
     
146
-    $subscription_data                      = wpinv_payment_subscription_data( $parent_invoice );
146
+    $subscription_data                      = wpinv_payment_subscription_data($parent_invoice);
147 147
     $subscription_data['recurring_amount']  = $invoice->get_total();
148
-    $subscription_data['created']           = current_time( 'mysql', 0 );
149
-    $subscription_data['expiration']        = $invoice->get_new_expiration( $subscription_data['item_id'] );
148
+    $subscription_data['created']           = current_time('mysql', 0);
149
+    $subscription_data['expiration']        = $invoice->get_new_expiration($subscription_data['item_id']);
150 150
     
151 151
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
152
-    $invoice->update_subscription( $subscription_data );
152
+    $invoice->update_subscription($subscription_data);
153 153
 
154
-    do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args );
155
-    do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args );
154
+    do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args);
155
+    do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args);
156 156
 
157 157
     return $invoice;
158 158
 }
159 159
 
160
-function wpinv_payment_exists( $txn_id = '' ) {
160
+function wpinv_payment_exists($txn_id = '') {
161 161
     global $wpdb;
162 162
 
163
-    if ( empty( $txn_id ) ) {
163
+    if (empty($txn_id)) {
164 164
         return false;
165 165
     }
166 166
 
167
-    $txn_id = esc_sql( $txn_id );
167
+    $txn_id = esc_sql($txn_id);
168 168
 
169
-    $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" );
169
+    $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1");
170 170
 
171
-    if ( $invoice != null ) {
171
+    if ($invoice != null) {
172 172
         return true;
173 173
     }
174 174
 
175 175
     return false;
176 176
 }
177 177
 
178
-function wpinv_is_subscription_payment( $invoice = '' ) {
179
-    if ( empty( $invoice ) ) {
178
+function wpinv_is_subscription_payment($invoice = '') {
179
+    if (empty($invoice)) {
180 180
         return false;
181 181
     }
182 182
     
183
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
184
-        $invoice = wpinv_get_invoice( $invoice );
183
+    if (!is_object($invoice) && is_scalar($invoice)) {
184
+        $invoice = wpinv_get_invoice($invoice);
185 185
     }
186 186
     
187
-    if ( empty( $invoice ) ) {
187
+    if (empty($invoice)) {
188 188
         return false;
189 189
     }
190 190
         
191
-    if ( $invoice->is_renewal() ) {
191
+    if ($invoice->is_renewal()) {
192 192
         return true;
193 193
     }
194 194
 
195 195
     return false;
196 196
 }
197 197
 
198
-function wpinv_payment_subscription_data( $invoice = '' ) {
199
-    if ( empty( $invoice ) ) {
198
+function wpinv_payment_subscription_data($invoice = '') {
199
+    if (empty($invoice)) {
200 200
         return false;
201 201
     }
202 202
     
203
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
204
-        $invoice = wpinv_get_invoice( $invoice );
203
+    if (!is_object($invoice) && is_scalar($invoice)) {
204
+        $invoice = wpinv_get_invoice($invoice);
205 205
     }
206 206
     
207
-    if ( empty( $invoice ) ) {
207
+    if (empty($invoice)) {
208 208
         return false;
209 209
     }    
210 210
 
211 211
     return $invoice->get_subscription_data();
212 212
 }
213 213
 
214
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
215
-    if ( empty( $invoice ) ) {
214
+function wpinv_payment_link_transaction_id($invoice = '') {
215
+    if (empty($invoice)) {
216 216
         return false;
217 217
     }
218 218
     
219
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
220
-        $invoice = wpinv_get_invoice( $invoice );
219
+    if (!is_object($invoice) && is_scalar($invoice)) {
220
+        $invoice = wpinv_get_invoice($invoice);
221 221
     }
222 222
     
223
-    if ( empty( $invoice ) ) {
223
+    if (empty($invoice)) {
224 224
         return false;
225 225
     }
226 226
 
227
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
227
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
228 228
 }
229 229
 
230
-function wpinv_get_pretty_subscription_period( $period ) {
230
+function wpinv_get_pretty_subscription_period($period) {
231 231
     $frequency = '';
232 232
     //Format period details
233
-    switch ( $period ) {
233
+    switch ($period) {
234 234
         case 'D' :
235 235
         case 'day' :
236
-            $frequency = __( 'Daily', 'invoicing' );
236
+            $frequency = __('Daily', 'invoicing');
237 237
             break;
238 238
         case 'W' :
239 239
         case 'week' :
240
-            $frequency = __( 'Weekly', 'invoicing' );
240
+            $frequency = __('Weekly', 'invoicing');
241 241
             break;
242 242
         case 'M' :
243 243
         case 'month' :
244
-            $frequency = __( 'Monthly', 'invoicing' );
244
+            $frequency = __('Monthly', 'invoicing');
245 245
             break;
246 246
         case 'Y' :
247 247
         case 'year' :
248
-            $frequency = __( 'Yearly', 'invoicing' );
248
+            $frequency = __('Yearly', 'invoicing');
249 249
             break;
250 250
         default :
251
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period );
251
+            $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period);
252 252
             break;
253 253
     }
254 254
 
255 255
     return $frequency;
256 256
 }
257 257
 
258
-function wpinv_get_pretty_subscription_period_name( $period ) {
258
+function wpinv_get_pretty_subscription_period_name($period) {
259 259
     $frequency = '';
260 260
     //Format period details
261
-    switch ( $period ) {
261
+    switch ($period) {
262 262
         case 'D' :
263 263
         case 'day' :
264
-            $frequency = __( 'Day', 'invoicing' );
264
+            $frequency = __('Day', 'invoicing');
265 265
             break;
266 266
         case 'W' :
267 267
         case 'week' :
268
-            $frequency = __( 'Week', 'invoicing' );
268
+            $frequency = __('Week', 'invoicing');
269 269
             break;
270 270
         case 'M' :
271 271
         case 'month' :
272
-            $frequency = __( 'Month', 'invoicing' );
272
+            $frequency = __('Month', 'invoicing');
273 273
             break;
274 274
         case 'Y' :
275 275
         case 'year' :
276
-            $frequency = __( 'Year', 'invoicing' );
276
+            $frequency = __('Year', 'invoicing');
277 277
             break;
278 278
         default :
279
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period );
279
+            $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period);
280 280
             break;
281 281
     }
282 282
 
283 283
     return $frequency;
284 284
 }
285 285
 
286
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
286
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
287 287
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
288 288
     
289
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
290
-        $amount = __( 'Free', 'invoicing' );
289
+    if ($trial_interval > 0 && !empty($trial_period)) {
290
+        $amount = __('Free', 'invoicing');
291 291
         $interval = $trial_interval;
292 292
         $period = $trial_period;
293 293
     }
294 294
     
295 295
     $description = '';
296
-    switch ( $period ) {
296
+    switch ($period) {
297 297
         case 'D' :
298 298
         case 'day' :
299
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
299
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
300 300
             break;
301 301
         case 'W' :
302 302
         case 'week' :
303
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
303
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
304 304
             break;
305 305
         case 'M' :
306 306
         case 'month' :
307
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
307
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
308 308
             break;
309 309
         case 'Y' :
310 310
         case 'year' :
311
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
311
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
312 312
             break;
313 313
     }
314 314
 
315
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
315
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
316 316
 }
317 317
 
318
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
318
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
319 319
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
320 320
     $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
321 321
     
322 322
     $description = '';
323
-    switch ( $period ) {
323
+    switch ($period) {
324 324
         case 'D' :
325 325
         case 'day' :            
326
-            if ( (int)$bill_times > 0 ) {
327
-                if ( $interval > 1 ) {
328
-                    if ( $bill_times > 1 ) {
329
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
326
+            if ((int)$bill_times > 0) {
327
+                if ($interval > 1) {
328
+                    if ($bill_times > 1) {
329
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
330 330
                     } else {
331
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
331
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
332 332
                     }
333 333
                 } else {
334
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
334
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
335 335
                 }
336 336
             } else {
337
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
337
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
338 338
             }
339 339
             break;
340 340
         case 'W' :
341 341
         case 'week' :            
342
-            if ( (int)$bill_times > 0 ) {
343
-                if ( $interval > 1 ) {
344
-                    if ( $bill_times > 1 ) {
345
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
342
+            if ((int)$bill_times > 0) {
343
+                if ($interval > 1) {
344
+                    if ($bill_times > 1) {
345
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
346 346
                     } else {
347
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
347
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
348 348
                     }
349 349
                 } else {
350
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
350
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
351 351
                 }
352 352
             } else {
353
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
353
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
354 354
             }
355 355
             break;
356 356
         case 'M' :
357 357
         case 'month' :            
358
-            if ( (int)$bill_times > 0 ) {
359
-                if ( $interval > 1 ) {
360
-                    if ( $bill_times > 1 ) {
361
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
358
+            if ((int)$bill_times > 0) {
359
+                if ($interval > 1) {
360
+                    if ($bill_times > 1) {
361
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
362 362
                     } else {
363
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
363
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
364 364
                     }
365 365
                 } else {
366
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
366
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
367 367
                 }
368 368
             } else {
369
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
369
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
370 370
             }
371 371
             break;
372 372
         case 'Y' :
373 373
         case 'year' :            
374
-            if ( (int)$bill_times > 0 ) {
375
-                if ( $interval > 1 ) {
376
-                    if ( $bill_times > 1 ) {
377
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
374
+            if ((int)$bill_times > 0) {
375
+                if ($interval > 1) {
376
+                    if ($bill_times > 1) {
377
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
378 378
                     } else {
379
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
379
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
380 380
                     }
381 381
                 } else {
382
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
382
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
383 383
                 }
384 384
             } else {
385
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
385
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
386 386
             }
387 387
             break;
388 388
     }
389 389
 
390
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
390
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
391 391
 }
392 392
 
393
-function wpinv_subscription_payment_desc( $invoice ) {
394
-    if ( empty( $invoice ) ) {
393
+function wpinv_subscription_payment_desc($invoice) {
394
+    if (empty($invoice)) {
395 395
         return NULL;
396 396
     }
397 397
     
398 398
     $description = '';
399
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
400
-        if ( $item->has_free_trial() ) {
399
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
400
+        if ($item->has_free_trial()) {
401 401
             $trial_period = $item->get_trial_period();
402 402
             $trial_interval = $item->get_trial_interval();
403 403
         } else {
@@ -405,45 +405,45 @@  discard block
 block discarded – undo
405 405
             $trial_interval = 0;
406 406
         }
407 407
         
408
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
408
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
409 409
     }
410 410
     
411
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
411
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
412 412
 }
413 413
 
414
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
415
-    $initial_total      = wpinv_round_amount( $initial );
416
-    $recurring_total    = wpinv_round_amount( $recurring );
414
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
415
+    $initial_total      = wpinv_round_amount($initial);
416
+    $recurring_total    = wpinv_round_amount($recurring);
417 417
     
418
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
418
+    if ($trial_interval > 0 && !empty($trial_period)) {
419 419
         // Free trial
420 420
     } else {
421
-        if ( $bill_times == 1 ) {
421
+        if ($bill_times == 1) {
422 422
             $recurring_total = $initial_total;
423
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
423
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
424 424
             $bill_times--;
425 425
         }
426 426
     }
427 427
     
428
-    $initial_amount     = wpinv_price( wpinv_format_amount( $initial_total ), $currency );
429
-    $recurring_amount   = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );
428
+    $initial_amount     = wpinv_price(wpinv_format_amount($initial_total), $currency);
429
+    $recurring_amount   = wpinv_price(wpinv_format_amount($recurring_total), $currency);
430 430
     
431
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
431
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
432 432
         
433
-    if ( $initial_total != $recurring_total ) {
434
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
433
+    if ($initial_total != $recurring_total) {
434
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
435 435
         
436
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
436
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
437 437
     } else {
438 438
         $description    = $recurring;
439 439
     }
440 440
     
441
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
441
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
442 442
 }
443 443
 
444
-function wpinv_recurring_send_payment_failed( $invoice ) {
445
-    if ( !empty( $invoice->ID ) ) {
446
-        wpinv_failed_invoice_notification( $invoice->ID );
444
+function wpinv_recurring_send_payment_failed($invoice) {
445
+    if (!empty($invoice->ID)) {
446
+        wpinv_failed_invoice_notification($invoice->ID);
447 447
     }
448 448
 }
449
-add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 );
450 449
\ No newline at end of file
450
+add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1);
451 451
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -1,44 +1,44 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
         
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
22
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
23 23
         $is_recurring       = $invoice->is_recurring();
24 24
         $post_type_object   = get_post_type_object($invoice->post_type);
25 25
         $type_title         = $post_type_object->labels->singular_name;
26 26
         
27 27
         $cols = 5;
28
-        if ( $item_quantities ) {
28
+        if ($item_quantities) {
29 29
             $cols++;
30 30
         }
31
-        if ( $use_taxes ) {
31
+        if ($use_taxes) {
32 32
             $cols++;
33 33
         }
34 34
         $class = '';
35
-        if ( $invoice->is_paid() ) {
35
+        if ($invoice->is_paid()) {
36 36
             $class .= ' wpinv-paid';
37 37
         }
38
-        if ( $invoice->is_refunded() ) {
38
+        if ($invoice->is_refunded()) {
39 39
             $class .= ' wpinv-refunded';
40 40
         }
41
-        if ( $is_recurring ) {
41
+        if ($is_recurring) {
42 42
             $class .= ' wpi-recurring';
43 43
         }
44 44
         ?>
@@ -46,21 +46,21 @@  discard block
 block discarded – undo
46 46
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
47 47
                 <thead>
48 48
                     <tr>
49
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
50
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
51
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
52
-                        <?php if ( $item_quantities ) { ?>
53
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
49
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
50
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
51
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
52
+                        <?php if ($item_quantities) { ?>
53
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
54 54
                         <?php } ?>
55
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
56
-                        <?php if ( $use_taxes ) { ?>
57
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
55
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
56
+                        <?php if ($use_taxes) { ?>
57
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
58 58
                         <?php } ?>
59 59
                         <th class="action"></th>
60 60
                     </tr>
61 61
                 </thead>
62 62
                 <tbody class="wpinv-line-items">
63
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
63
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
64 64
                 </tbody>
65 65
                 <tfoot class="wpinv-totals">
66 66
                     <tr>
@@ -72,44 +72,44 @@  discard block
 block discarded – undo
72 72
                                         </td>
73 73
                                         <td class="title">
74 74
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
75
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
75
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
76 76
                                             <div class="wp-clearfix">
77 77
                                                 <label class="wpi-vat-rule">
78
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
78
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
79 79
                                                     <span class="input-text-wrap">
80
-                                                        <?php echo wpinv_html_select( array(
80
+                                                        <?php echo wpinv_html_select(array(
81 81
                                                             'options'          => $wpinv_euvat->get_rules(),
82 82
                                                             'name'             => '_wpinv_quick[vat_rule]',
83 83
                                                             'id'               => '_wpinv_quick_vat_rule',
84 84
                                                             'show_option_all'  => false,
85 85
                                                             'show_option_none' => false,
86 86
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
87
-                                                        ) ); ?>
87
+                                                        )); ?>
88 88
                                                     </span>
89 89
                                                 </label>
90 90
                                             </div>
91
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
91
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
92 92
                                             <div class="wp-clearfix">
93 93
                                                 <label class="wpi-vat-class">
94
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
94
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
95 95
                                                     <span class="input-text-wrap">
96
-                                                        <?php echo wpinv_html_select( array(
96
+                                                        <?php echo wpinv_html_select(array(
97 97
                                                             'options'          => $wpinv_euvat->get_all_classes(),
98 98
                                                             'name'             => '_wpinv_quick[vat_class]',
99 99
                                                             'id'               => '_wpinv_quick_vat_class',
100 100
                                                             'show_option_all'  => false,
101 101
                                                             'show_option_none' => false,
102 102
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
103
-                                                        ) ); ?>
103
+                                                        )); ?>
104 104
                                                     </span>
105 105
                                                 </label>
106 106
                                             </div>
107 107
                                             <?php } ?>
108 108
                                             <div class="wp-clearfix">
109 109
                                                 <label class="wpi-item-type">
110
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
110
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
111 111
                                                     <span class="input-text-wrap">
112
-                                                        <?php echo wpinv_html_select( array(
112
+                                                        <?php echo wpinv_html_select(array(
113 113
                                                             'options'          => $item_types,
114 114
                                                             'name'             => '_wpinv_quick[type]',
115 115
                                                             'id'               => '_wpinv_quick_type',
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                                                             'show_option_all'  => false,
118 118
                                                             'show_option_none' => false,
119 119
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
120
-                                                        ) ); ?>
120
+                                                        )); ?>
121 121
                                                     </span>
122 122
                                                 </label>
123 123
                                             </div>
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
                                             </div>
131 131
                                         </td>
132 132
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
133
-                                        <?php if ( $item_quantities ) { ?>
133
+                                        <?php if ($item_quantities) { ?>
134 134
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
135 135
                                         <?php } ?>
136 136
                                         <td class="total"></td>
137
-                                        <?php if ( $use_taxes ) { ?>
137
+                                        <?php if ($use_taxes) { ?>
138 138
                                         <td class="tax"></td>
139 139
                                         <?php } ?>
140 140
                                         <td class="action"></td>
@@ -147,29 +147,29 @@  discard block
 block discarded – undo
147 147
                         <td colspan="<?php echo $cols; ?>"></td>
148 148
                     </tr>
149 149
                     <tr class="totals">
150
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
150
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
151 151
                         <td colspan="4">
152 152
                             <table cellspacing="0" cellpadding="0">
153 153
                                 <tr class="subtotal">
154
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
155
-                                    <td class="total"><?php echo $subtotal;?></td>
154
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
155
+                                    <td class="total"><?php echo $subtotal; ?></td>
156 156
                                     <td class="action"></td>
157 157
                                 </tr>
158 158
                                 <tr class="discount">
159
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
160
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
159
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
160
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
161 161
                                     <td class="action"></td>
162 162
                                 </tr>
163
-                                <?php if ( $use_taxes ) { ?>
163
+                                <?php if ($use_taxes) { ?>
164 164
                                 <tr class="tax">
165
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
166
-                                    <td class="total"><?php echo $tax;?></td>
165
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
166
+                                    <td class="total"><?php echo $tax; ?></td>
167 167
                                     <td class="action"></td>
168 168
                                 </tr>
169 169
                                 <?php } ?>
170 170
                                 <tr class="total">
171
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
172
-                                    <td class="total"><?php echo $total;?></td>
171
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
172
+                                    <td class="total"><?php echo $total; ?></td>
173 173
                                     <td class="action"></td>
174 174
                                 </tr>
175 175
                             </table>
@@ -179,86 +179,86 @@  discard block
 block discarded – undo
179 179
             </table>
180 180
             <div class="wpinv-actions">
181 181
                 <?php
182
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
183
-                    if ( !$invoice->is_recurring() ) {
184
-                    echo wpinv_item_dropdown( array(
182
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
183
+                    if (!$invoice->is_recurring()) {
184
+                    echo wpinv_item_dropdown(array(
185 185
                         'name'             => 'wpinv_invoice_item',
186 186
                         'id'               => 'wpinv_invoice_item',
187 187
                         'show_recurring'   => true,
188
-                    ) );
188
+                    ));
189 189
                     ?>
190
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
190
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
191 191
                     <?php } ?>
192
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
192
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
193 193
             </div>
194 194
         </div>
195 195
         <?php
196 196
     }
197 197
     
198
-    public static function prices( $post ) {        
198
+    public static function prices($post) {        
199 199
         $symbol         = wpinv_currency_symbol();
200 200
         $position       = wpinv_currency_position();
201
-        $item           = new WPInv_Item( $post->ID );
201
+        $item           = new WPInv_Item($post->ID);
202 202
         
203 203
         $price          = $item->get_price();
204 204
         $is_recurring   = $item->is_recurring();
205 205
         $period         = $item->get_recurring_period();
206
-        $interval       = absint( $item->get_recurring_interval() );
207
-        $times          = absint( $item->get_recurring_limit() );
206
+        $interval       = absint($item->get_recurring_interval());
207
+        $times          = absint($item->get_recurring_limit());
208 208
         $free_trial     = $item->has_free_trial();
209 209
         $trial_interval = $item->get_trial_interval();
210 210
         $trial_period   = $item->get_trial_period();
211 211
         
212 212
         $intervals      = array();
213
-        for ( $i = 1; $i <= 90; $i++ ) {
213
+        for ($i = 1; $i <= 90; $i++) {
214 214
             $intervals[$i] = $i;
215 215
         }
216 216
         
217
-        $interval       = $interval > 0 ? $interval : 1;
217
+        $interval = $interval > 0 ? $interval : 1;
218 218
         
219 219
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
220 220
         ?>
221
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
222
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
221
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
222
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
223 223
         </p>
224 224
         <p class="wpinv-row-is-recurring">
225 225
             <label for="wpinv_is_recurring">
226
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
227
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
226
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
227
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
228 228
             </label>
229 229
         </p>
230
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
231
-                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
232
-                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
230
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
231
+                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
232
+                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
233 233
                     'options'          => $intervals,
234 234
                     'name'             => 'wpinv_recurring_interval',
235 235
                     'id'               => 'wpinv_recurring_interval',
236 236
                     'selected'         => $interval,
237 237
                     'show_option_all'  => false,
238 238
                     'show_option_none' => false
239
-                ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
240
-                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
239
+                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
240
+                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
241 241
                 <span class="clear wpi-trial-clr"></span>
242 242
                 <label class="wpinv-free-trial" for="wpinv_free_trial">
243
-                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
244
-                    <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
243
+                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
244
+                    <?php echo __('Offer free trial for', 'invoicing'); ?>
245 245
                 </label>
246 246
                 <label class="wpinv-trial-interval" for="wpinv_trial_interval">
247
-                    <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
247
+                    <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
248 248
                 </label>
249 249
         </p>
250
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
251
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
250
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
251
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
252 252
         <?php
253 253
     }
254 254
     
255
-    public static function vat_rules( $post ) {
255
+    public static function vat_rules($post) {
256 256
         global $wpinv_euvat;
257 257
         
258
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
258
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
259 259
         ?>
260
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
261
-        <?php echo wpinv_html_select( array(
260
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
261
+        <?php echo wpinv_html_select(array(
262 262
                     'options'          => $wpinv_euvat->get_rules(),
263 263
                     'name'             => 'wpinv_vat_rules',
264 264
                     'id'               => 'wpinv_vat_rules',
@@ -266,19 +266,19 @@  discard block
 block discarded – undo
266 266
                     'show_option_all'  => false,
267 267
                     'show_option_none' => false,
268 268
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
269
-                ) ); ?>
269
+                )); ?>
270 270
         </p>
271
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
272
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
271
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
272
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
273 273
         <?php
274 274
     }
275 275
     
276
-    public static function vat_classes( $post ) {
276
+    public static function vat_classes($post) {
277 277
         global $wpinv_euvat;
278 278
         
279
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
279
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
280 280
         ?>
281
-        <p><?php echo wpinv_html_select( array(
281
+        <p><?php echo wpinv_html_select(array(
282 282
                     'options'          => $wpinv_euvat->get_all_classes(),
283 283
                     'name'             => 'wpinv_vat_class',
284 284
                     'id'               => 'wpinv_vat_class',
@@ -286,18 +286,18 @@  discard block
 block discarded – undo
286 286
                     'show_option_all'  => false,
287 287
                     'show_option_none' => false,
288 288
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
289
-                ) ); ?>
289
+                )); ?>
290 290
         </p>
291
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
291
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
292 292
         <?php
293 293
     }
294 294
     
295
-    public static function item_info( $post ) {
296
-        $item_type = wpinv_get_item_type( $post->ID );
297
-        do_action( 'wpinv_item_info_metabox_before', $post );
295
+    public static function item_info($post) {
296
+        $item_type = wpinv_get_item_type($post->ID);
297
+        do_action('wpinv_item_info_metabox_before', $post);
298 298
         ?>
299
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
300
-        <?php echo wpinv_html_select( array(
299
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
300
+        <?php echo wpinv_html_select(array(
301 301
                     'options'          => wpinv_get_item_types(),
302 302
                     'name'             => 'wpinv_item_type',
303 303
                     'id'               => 'wpinv_item_type',
@@ -305,114 +305,114 @@  discard block
 block discarded – undo
305 305
                     'show_option_all'  => false,
306 306
                     'show_option_none' => false,
307 307
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
308
-                ) ); ?>
308
+                )); ?>
309 309
         </p>
310
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
310
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
311 311
         <?php
312
-        do_action( 'wpinv_item_info_metabox_after', $post );
312
+        do_action('wpinv_item_info_metabox_after', $post);
313 313
     }
314 314
     
315
-    public static function meta_values( $post ) {
316
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
315
+    public static function meta_values($post) {
316
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
317 317
             'type',
318 318
             'custom_id'
319
-        ) );
319
+        ));
320 320
         
321
-        if ( empty( $meta_keys ) ) {
321
+        if (empty($meta_keys)) {
322 322
             return;
323 323
         }
324 324
         
325
-        do_action( 'wpinv_meta_values_metabox_before', $post );
325
+        do_action('wpinv_meta_values_metabox_before', $post);
326 326
         
327
-        foreach ( $meta_keys as $meta_key ) {
327
+        foreach ($meta_keys as $meta_key) {
328 328
             ?>
329
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
329
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
330 330
             <?php 
331 331
         }
332 332
         
333
-        do_action( 'wpinv_meta_values_metabox_after', $post );
333
+        do_action('wpinv_meta_values_metabox_after', $post);
334 334
     }
335 335
     
336
-    public static function save( $post_id, $data, $post ) {
337
-        $invoice        = new WPInv_Invoice( $post_id );
336
+    public static function save($post_id, $data, $post) {
337
+        $invoice        = new WPInv_Invoice($post_id);
338 338
         
339 339
         // Billing
340
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
341
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
342
-        $company        = sanitize_text_field( $data['wpinv_company'] );
343
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
344
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
345
-        $address        = sanitize_text_field( $data['wpinv_address'] );
346
-        $city           = sanitize_text_field( $data['wpinv_city'] );
347
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
348
-        $country        = sanitize_text_field( $data['wpinv_country'] );
349
-        $state          = sanitize_text_field( $data['wpinv_state'] );
340
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
341
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
342
+        $company        = sanitize_text_field($data['wpinv_company']);
343
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
344
+        $phone          = sanitize_text_field($data['wpinv_phone']);
345
+        $address        = sanitize_text_field($data['wpinv_address']);
346
+        $city           = sanitize_text_field($data['wpinv_city']);
347
+        $zip            = sanitize_text_field($data['wpinv_zip']);
348
+        $country        = sanitize_text_field($data['wpinv_country']);
349
+        $state          = sanitize_text_field($data['wpinv_state']);
350 350
         
351 351
         // Details
352
-        $status         = sanitize_text_field( $data['wpinv_status'] );
353
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
354
-        $number         = sanitize_text_field( $data['wpinv_number'] );
355
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
352
+        $status         = sanitize_text_field($data['wpinv_status']);
353
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
354
+        $number         = sanitize_text_field($data['wpinv_number']);
355
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
356 356
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
357 357
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
358 358
         
359
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
359
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
360 360
         
361
-        $invoice->set( 'due_date', $due_date );
362
-        $invoice->set( 'first_name', $first_name );
363
-        $invoice->set( 'last_name', $last_name );
364
-        $invoice->set( 'company', $company );
365
-        $invoice->set( 'vat_number', $vat_number );
366
-        $invoice->set( 'phone', $phone );
367
-        $invoice->set( 'address', $address );
368
-        $invoice->set( 'city', $city );
369
-        $invoice->set( 'zip', $zip );
370
-        $invoice->set( 'country', $country );
371
-        $invoice->set( 'state', $state );
372
-        $invoice->set( 'status', $status );
361
+        $invoice->set('due_date', $due_date);
362
+        $invoice->set('first_name', $first_name);
363
+        $invoice->set('last_name', $last_name);
364
+        $invoice->set('company', $company);
365
+        $invoice->set('vat_number', $vat_number);
366
+        $invoice->set('phone', $phone);
367
+        $invoice->set('address', $address);
368
+        $invoice->set('city', $city);
369
+        $invoice->set('zip', $zip);
370
+        $invoice->set('country', $country);
371
+        $invoice->set('state', $state);
372
+        $invoice->set('status', $status);
373 373
         //$invoice->set( 'number', $number );
374 374
         //$invoice->set( 'discounts', $discounts );
375 375
         //$invoice->set( 'discount', $discount );
376
-        $invoice->set( 'ip', $ip );
376
+        $invoice->set('ip', $ip);
377 377
         $invoice->old_status = $_POST['original_post_status'];
378 378
         $invoice->currency = wpinv_get_currency();
379
-        if ( !empty( $data['wpinv_gateway'] ) ) {
380
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
379
+        if (!empty($data['wpinv_gateway'])) {
380
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
381 381
         }
382 382
         $saved = $invoice->save();
383 383
         
384 384
         // Check for payment notes
385
-        if ( !empty( $data['invoice_note'] ) ) {
386
-            $note               = wp_kses( $data['invoice_note'], array() );
387
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
385
+        if (!empty($data['invoice_note'])) {
386
+            $note               = wp_kses($data['invoice_note'], array());
387
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
388 388
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
389 389
         
390
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
390
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
391 391
         }
392 392
         
393 393
         // Update user address if empty.
394
-        if ( $saved && !empty( $invoice ) ) {
395
-            if ( $user_id = $invoice->get_user_id() ) {
396
-                $user_address = wpinv_get_user_address( $user_id, false );
394
+        if ($saved && !empty($invoice)) {
395
+            if ($user_id = $invoice->get_user_id()) {
396
+                $user_address = wpinv_get_user_address($user_id, false);
397 397
                 
398 398
                 if (empty($user_address['first_name'])) {
399
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
400
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
399
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
400
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
401 401
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
402
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
402
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
403 403
                 }
404 404
                 
405 405
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
406
-                    update_user_meta( $user_id, '_wpinv_address', $address );
407
-                    update_user_meta( $user_id, '_wpinv_city', $city );
408
-                    update_user_meta( $user_id, '_wpinv_state', $state );
409
-                    update_user_meta( $user_id, '_wpinv_country', $country );
410
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
411
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
406
+                    update_user_meta($user_id, '_wpinv_address', $address);
407
+                    update_user_meta($user_id, '_wpinv_city', $city);
408
+                    update_user_meta($user_id, '_wpinv_state', $state);
409
+                    update_user_meta($user_id, '_wpinv_country', $country);
410
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
411
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
412 412
                 }
413 413
             }
414 414
             
415
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
415
+            do_action('wpinv_invoice_metabox_saved', $invoice);
416 416
         }
417 417
         
418 418
         return $saved;
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-details.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Details {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         $currency_symbol    = wpinv_currency_symbol();
10 10
         $statuses           = wpinv_get_invoice_statuses();
11 11
         
12
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
13
-        $invoice            = new WPInv_Invoice( $post_id );
12
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
13
+        $invoice            = new WPInv_Invoice($post_id);
14 14
         
15
-        $status             = $invoice->get_status( false ); // Current status    
15
+        $status             = $invoice->get_status(false); // Current status    
16 16
         $discount           = $invoice->get_discount();
17 17
         $discount_code      = $discount > 0 ? $invoice->get_discount_code() : '';
18 18
         $invoice_number     = $invoice->get_number();
19 19
         
20 20
         $date_created       = $invoice->get_created_date();
21
-        $datetime_created   = strtotime( $date_created );
22
-        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : '';
21
+        $datetime_created   = strtotime($date_created);
22
+        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : '';
23 23
         $date_completed     = $invoice->get_completed_date();
24
-        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a';
25
-        $title['status'] = __( 'Invoice Status:', 'invoicing' );
26
-        $title['number'] = __( 'Invoice Number:', 'invoicing' );
27
-        $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing' );
24
+        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a';
25
+        $title['status'] = __('Invoice Status:', 'invoicing');
26
+        $title['number'] = __('Invoice Number:', 'invoicing');
27
+        $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing');
28 28
         
29 29
         $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice);
30 30
         $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice);
@@ -34,29 +34,29 @@  discard block
 block discarded – undo
34 34
 <div class="gdmbx2-wrap form-table">
35 35
     <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details">
36 36
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created">
37
-            <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div>
38
-            <div class="gdmbx-td"><?php echo $date_created;?></div>
37
+            <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div>
38
+            <div class="gdmbx-td"><?php echo $date_created; ?></div>
39 39
         </div>
40
-        <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft' ) ) ) ) { ?>
40
+        <?php if ($invoice->post_type == 'wpi_invoice' && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft')))) { ?>
41 41
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue">
42
-            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div>
42
+            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div>
43 43
             <div class="gdmbx-td">
44
-                <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd">
44
+                <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd">
45 45
             </div>
46 46
         </div>
47 47
         <?php } ?>
48
-        <?php if ( $date_completed && $date_completed != 'n/a' ) { ?>
48
+        <?php if ($date_completed && $date_completed != 'n/a') { ?>
49 49
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed">
50
-            <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div>
51
-            <div class="gdmbx-td"><?php echo $date_completed;?></div>
50
+            <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div>
51
+            <div class="gdmbx-td"><?php echo $date_completed; ?></div>
52 52
         </div>
53 53
         <?php } ?>
54 54
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status">
55 55
             <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div>
56 56
             <div class="gdmbx-td">
57 57
                 <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select">
58
-                    <?php foreach ( $statuses as $value => $label ) { ?>
59
-                    <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option>
58
+                    <?php foreach ($statuses as $value => $label) { ?>
59
+                    <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option>
60 60
                     <?php } ?>
61 61
                 </select>
62 62
             </div>
@@ -64,107 +64,107 @@  discard block
 block discarded – undo
64 64
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout">
65 65
             <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div>
66 66
             <div class="gdmbx-td">
67
-                <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
67
+                <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
68 68
             </div>
69 69
         </div>
70
-        <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); ?>
71
-        <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) || $discount_code ) { ?>
70
+        <?php do_action('wpinv_meta_box_details_inner', $post_id); ?>
71
+        <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) || $discount_code) { ?>
72 72
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout">
73
-            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div>
73
+            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div>
74 74
             <div class="gdmbx-td">
75
-                <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
75
+                <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
76 76
             </div>
77 77
         </div>
78 78
         <?php } ?>
79 79
     </div>
80 80
 </div>
81 81
 <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout">
82
-    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label>
82
+    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label>
83 83
         <select id="wpi_save_send" name="wpi_save_send">
84
-            <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option>
85
-            <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option>
84
+            <option value="1"><?php _e('Yes', 'invoicing'); ?></option>
85
+            <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option>
86 86
         </select>
87 87
     </p>
88 88
     <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p>
89 89
 </div>
90
-<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?>
90
+<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?>
91 91
         <?php
92 92
     }
93 93
     
94
-    public static function resend_invoice( $post ) {
94
+    public static function resend_invoice($post) {
95 95
         global $wpi_mb_invoice;
96 96
         
97
-        if ( empty( $wpi_mb_invoice ) ) {
97
+        if (empty($wpi_mb_invoice)) {
98 98
             return;
99 99
         }
100 100
         
101 101
         $text = array(
102
-            'message'       => esc_attr__( 'This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing' ),
103
-            'button_text'   =>  __( 'Resend Invoice', 'invoicing' ),
102
+            'message'       => esc_attr__('This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing'),
103
+            'button_text'   =>  __('Resend Invoice', 'invoicing'),
104 104
         );
105 105
             
106 106
         $text = apply_filters('wpinv_resend_invoice_metabox_text', $text);
107
-        do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice );
107
+        do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice);
108 108
         
109
-        if ( $email = $wpi_mb_invoice->get_email() ) {
109
+        if ($email = $wpi_mb_invoice->get_email()) {
110 110
             $email_actions = array();
111
-            $email_actions['email_url']      = add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) );
112
-            $email_actions['reminder_url']   = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) );
111
+            $email_actions['email_url']      = add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID));
112
+            $email_actions['reminder_url']   = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID));
113 113
             
114
-            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions );
114
+            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions);
115 115
         ?>
116 116
         <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p>
117
-        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
118
-        <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?>
119
-        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
117
+        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
118
+        <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?>
119
+        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
120 120
         <?php } ?>
121 121
         <?php
122 122
         }
123 123
         
124
-        do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice );
124
+        do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice);
125 125
     }
126 126
     
127
-    public static function subscriptions( $post ) {
127
+    public static function subscriptions($post) {
128 128
         global $wpi_mb_invoice;
129 129
         
130 130
         $invoice = $wpi_mb_invoice;
131 131
         
132
-        if ( !empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) {
132
+        if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) {
133 133
             $payments       = $invoice->get_child_payments();
134 134
             
135 135
             $total_payments = (int)$invoice->get_total_payments();
136 136
             $subscription   = $invoice->get_subscription_data();
137 137
 
138
-            $billing_cycle  = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() );
139
-            $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
138
+            $billing_cycle  = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency());
139
+            $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
140 140
             $subscription_status = $invoice->get_subscription_status();
141 141
             ?>
142
-            <p class="wpi-meta-row wpi-sub-label"><?php _e( 'Recurring Payment', 'invoicing' );?></p>
143
-            <?php if ( $subscription_id = $invoice->get_subscription_id() ) { ?>
144
-            <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $subscription_id; ?></p>
142
+            <p class="wpi-meta-row wpi-sub-label"><?php _e('Recurring Payment', 'invoicing'); ?></p>
143
+            <?php if ($subscription_id = $invoice->get_subscription_id()) { ?>
144
+            <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $subscription_id; ?></p>
145 145
             <?php } ?>
146
-            <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e( 'Billing Cycle:', 'invoicing' );?> </label><?php echo $billing_cycle; ?></p>
147
-            <p class="wpi-meta-row wpi-billed-times"><label><?php _e( 'Times Billed:', 'invoicing' );?> </label><?php echo $times_billed; ?></p>
148
-            <?php if ( !empty( $payments ) || ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
149
-                <p class="wpi-meta-row wpi-start-date"><label><?php _e( 'Start Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_start(); ?></p>
150
-                <p class="wpi-meta-row wpi-end-date"><label><?php _e( 'Expiration Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_end(); ?></p>
151
-                <?php if ( $status_label = $invoice->get_subscription_status_label( $subscription_status ) ) { ?>
152
-                <p class="wpi-meta-row wpi-sub-status"><label><?php _e( 'Subscription Status:', 'invoicing' );?> </label><?php echo $status_label; ?></p>
146
+            <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php echo $billing_cycle; ?></p>
147
+            <p class="wpi-meta-row wpi-billed-times"><label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $times_billed; ?></p>
148
+            <?php if (!empty($payments) || ($invoice->is_paid() || $invoice->is_refunded())) { ?>
149
+                <p class="wpi-meta-row wpi-start-date"><label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_start(); ?></p>
150
+                <p class="wpi-meta-row wpi-end-date"><label><?php _e('Expiration Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_end(); ?></p>
151
+                <?php if ($status_label = $invoice->get_subscription_status_label($subscription_status)) { ?>
152
+                <p class="wpi-meta-row wpi-sub-status"><label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $status_label; ?></p>
153 153
                 <?php } ?>
154
-                <?php if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { ?>
155
-                <p class="wpi-meta-row wpi-trial-date"><label><?php _e( 'Trial Until:', 'invoicing' );?> </label><?php echo $trial_end_date; ?></p>
154
+                <?php if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { ?>
155
+                <p class="wpi-meta-row wpi-trial-date"><label><?php _e('Trial Until:', 'invoicing'); ?> </label><?php echo $trial_end_date; ?></p>
156 156
                 <?php } ?>
157
-                <?php if ( $cancelled_date = $invoice->get_cancelled_date() ) { ?>
158
-                <p class="wpi-meta-row wpi-cancel-date"><label><?php _e( 'Cancelled On:', 'invoicing' );?> </label><?php echo $cancelled_date; ?></p>
157
+                <?php if ($cancelled_date = $invoice->get_cancelled_date()) { ?>
158
+                <p class="wpi-meta-row wpi-cancel-date"><label><?php _e('Cancelled On:', 'invoicing'); ?> </label><?php echo $cancelled_date; ?></p>
159 159
                 <?php } ?>
160
-                <?php if ( !empty( $payments ) ) { ?>
161
-                <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p>
160
+                <?php if (!empty($payments)) { ?>
161
+                <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p>
162 162
                 <ul id="wpi-sub-payments">
163
-                <?php foreach ( $payments as $invoice_id ) { ?>
163
+                <?php foreach ($payments as $invoice_id) { ?>
164 164
                     <li>
165
-                        <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a>&nbsp;&ndash;&nbsp;
166
-                        <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?>&nbsp;&ndash;&nbsp;</span>
167
-                        <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span>
165
+                        <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a>&nbsp;&ndash;&nbsp;
166
+                        <span><?php echo wpinv_get_invoice_date($invoice_id); ?>&nbsp;&ndash;&nbsp;</span>
167
+                        <span><?php echo wpinv_payment_total($invoice_id, true); ?></span>
168 168
                     </li>
169 169
                 <?php } ?>
170 170
                 </ul>
@@ -172,49 +172,49 @@  discard block
 block discarded – undo
172 172
         }
173 173
     }
174 174
     
175
-    public static function renewals( $post ) {
175
+    public static function renewals($post) {
176 176
         global $wpi_mb_invoice;
177 177
         
178
-        if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
179
-            $parent_url = get_edit_post_link( $wpi_mb_invoice->parent_invoice );
180
-            $parent_id  = wpinv_get_invoice_number( $wpi_mb_invoice->parent_invoice );
178
+        if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
179
+            $parent_url = get_edit_post_link($wpi_mb_invoice->parent_invoice);
180
+            $parent_id  = wpinv_get_invoice_number($wpi_mb_invoice->parent_invoice);
181 181
         ?>
182
-        <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p>
183
-        <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p>
182
+        <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p>
183
+        <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p>
184 184
         <?php
185 185
         }
186 186
     }
187 187
     
188
-    public static function payment_meta( $post ) {
188
+    public static function payment_meta($post) {
189 189
         global $wpi_mb_invoice;
190 190
 
191
-        $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false;
192
-        if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) {
191
+        $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false;
192
+        if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) {
193 193
             $set_dateway = true;
194 194
         }
195 195
         
196 196
         ?>
197 197
         <p class="wpi-meta-row">
198
-        <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?>
199
-            <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label>
198
+        <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?>
199
+            <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label>
200 200
             <select required="required" id="wpinv_gateway" name="wpinv_gateway">
201
-                <?php foreach ( $gateways as $name => $gateway ) {
202
-                    if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) {
201
+                <?php foreach ($gateways as $name => $gateway) {
202
+                    if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) {
203 203
                         continue;
204 204
                     }
205 205
                     ?>
206
-                <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
206
+                <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
207 207
                 <?php } ?>
208 208
             </select>
209 209
         <?php } else { 
210
-            echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_checkout_label( $wpi_mb_invoice->gateway ) );
210
+            echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_checkout_label($wpi_mb_invoice->gateway));
211 211
         } ?>
212 212
         </p>
213
-        <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?>
214
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p>
213
+        <?php if ($key = $wpi_mb_invoice->get_key()) { ?>
214
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p>
215 215
         <?php } ?>
216
-        <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?>
217
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p>
216
+        <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?>
217
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p>
218 218
         <?php } ?>
219 219
         <?php
220 220
     }
Please login to merge, or discard this patch.