Passed
Pull Request — master (#47)
by Kiran
04:17
created
includes/wpinv-user-functions.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_user_invoices( $current_page = 1 ) {    
5
+function wpinv_user_invoices($current_page = 1) {    
6 6
     global $current_page;
7
-    do_action( 'wpinv_before_user_invoices_template', $current_page );
8
-    wpinv_get_template_part( 'wpinv-invoice-history' );
9
-    do_action( 'wpinv_after_user_invoices_template', $current_page );
7
+    do_action('wpinv_before_user_invoices_template', $current_page);
8
+    wpinv_get_template_part('wpinv-invoice-history');
9
+    do_action('wpinv_after_user_invoices_template', $current_page);
10 10
 }
11 11
 
12
-function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) {
13
-    if ( empty( $user ) ) {
12
+function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') {
13
+    if (empty($user)) {
14 14
         $user = get_current_user_id();
15 15
     }
16 16
 
17
-    if ( 0 === $user ) {
17
+    if (0 === $user) {
18 18
         return false;
19 19
     }
20 20
 
21
-    if ( $pagination ) {
22
-        if ( get_query_var( 'paged' ) )
21
+    if ($pagination) {
22
+        if (get_query_var('paged'))
23 23
             $paged = get_query_var('paged');
24
-        else if ( get_query_var( 'page' ) )
25
-            $paged = get_query_var( 'page' );
24
+        else if (get_query_var('page'))
25
+            $paged = get_query_var('page');
26 26
         else
27 27
             $paged = 1;
28 28
     }
@@ -31,21 +31,21 @@  discard block
 block discarded – undo
31 31
         'post_type'      => 'wpi_invoice',
32 32
         'posts_per_page' => 2,
33 33
         'paged'          => null,
34
-        'post_status'    => array( 'publish', 'pending' ),
34
+        'post_status'    => array('publish', 'pending'),
35 35
         'user'           => $user,
36 36
         'order'          => 'date',
37 37
     );
38 38
 
39
-    $invoices = get_posts( $args );
39
+    $invoices = get_posts($args);
40 40
 
41 41
     // No invoices
42
-    if ( ! $invoices )
42
+    if (!$invoices)
43 43
         return false;
44 44
 
45 45
     return $invoices;
46 46
 }
47 47
 
48
-function wpinv_dropdown_users( $args = '' ) {
48
+function wpinv_dropdown_users($args = '') {
49 49
     $defaults = array(
50 50
         'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
51 51
         'orderby' => 'display_name', 'order' => 'ASC',
@@ -56,18 +56,18 @@  discard block
 block discarded – undo
56 56
         'option_none_value' => -1
57 57
     );
58 58
 
59
-    $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
59
+    $defaults['selected'] = is_author() ? get_query_var('author') : 0;
60 60
 
61
-    $r = wp_parse_args( $args, $defaults );
61
+    $r = wp_parse_args($args, $defaults);
62 62
 
63
-    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
63
+    $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who'));
64 64
 
65
-    $fields = array( 'ID', 'user_login', 'user_email' );
65
+    $fields = array('ID', 'user_login', 'user_email');
66 66
 
67
-    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
68
-    if ( 'display_name_with_login' === $show ) {
67
+    $show = !empty($r['show']) ? $r['show'] : 'display_name';
68
+    if ('display_name_with_login' === $show) {
69 69
         $fields[] = 'display_name';
70
-    } else if ( 'display_name_with_email' === $show ) {
70
+    } else if ('display_name_with_email' === $show) {
71 71
         $fields[] = 'display_name';
72 72
     } else {
73 73
         $fields[] = $show;
@@ -79,99 +79,99 @@  discard block
 block discarded – undo
79 79
     $show_option_none = $r['show_option_none'];
80 80
     $option_none_value = $r['option_none_value'];
81 81
 
82
-    $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r );
82
+    $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r);
83 83
 
84
-    $users = get_users( $query_args );
84
+    $users = get_users($query_args);
85 85
 
86 86
     $output = '';
87
-    if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
88
-        $name = esc_attr( $r['name'] );
89
-        if ( $r['multi'] && ! $r['id'] ) {
87
+    if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) {
88
+        $name = esc_attr($r['name']);
89
+        if ($r['multi'] && !$r['id']) {
90 90
             $id = '';
91 91
         } else {
92
-            $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
92
+            $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'";
93 93
         }
94 94
         $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n";
95 95
 
96
-        if ( $show_option_all ) {
96
+        if ($show_option_all) {
97 97
             $output .= "\t<option value='0'>$show_option_all</option>\n";
98 98
         }
99 99
 
100
-        if ( $show_option_none ) {
101
-            $_selected = selected( $option_none_value, $r['selected'], false );
102
-            $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
100
+        if ($show_option_none) {
101
+            $_selected = selected($option_none_value, $r['selected'], false);
102
+            $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n";
103 103
         }
104 104
 
105
-        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
105
+        if ($r['include_selected'] && ($r['selected'] > 0)) {
106 106
             $found_selected = false;
107
-            $r['selected'] = (int) $r['selected'];
108
-            foreach ( (array) $users as $user ) {
109
-                $user->ID = (int) $user->ID;
110
-                if ( $user->ID === $r['selected'] ) {
107
+            $r['selected'] = (int)$r['selected'];
108
+            foreach ((array)$users as $user) {
109
+                $user->ID = (int)$user->ID;
110
+                if ($user->ID === $r['selected']) {
111 111
                     $found_selected = true;
112 112
                 }
113 113
             }
114 114
 
115
-            if ( ! $found_selected ) {
116
-                $users[] = get_userdata( $r['selected'] );
115
+            if (!$found_selected) {
116
+                $users[] = get_userdata($r['selected']);
117 117
             }
118 118
         }
119 119
 
120
-        foreach ( (array) $users as $user ) {
121
-            if ( 'display_name_with_login' === $show ) {
120
+        foreach ((array)$users as $user) {
121
+            if ('display_name_with_login' === $show) {
122 122
                 /* translators: 1: display name, 2: user_login */
123
-                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
124
-            } elseif ( 'display_name_with_email' === $show ) {
123
+                $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login);
124
+            } elseif ('display_name_with_email' === $show) {
125 125
                 /* translators: 1: display name, 2: user_email */
126
-                if ( $user->display_name == $user->user_email ) {
126
+                if ($user->display_name == $user->user_email) {
127 127
                     $display = $user->display_name;
128 128
                 } else {
129
-                    $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email );
129
+                    $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email);
130 130
                 }
131
-            } elseif ( ! empty( $user->$show ) ) {
131
+            } elseif (!empty($user->$show)) {
132 132
                 $display = $user->$show;
133 133
             } else {
134 134
                 $display = '(' . $user->user_login . ')';
135 135
             }
136 136
 
137
-            $_selected = selected( $user->ID, $r['selected'], false );
138
-            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
137
+            $_selected = selected($user->ID, $r['selected'], false);
138
+            $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
139 139
         }
140 140
 
141 141
         $output .= "</select>";
142 142
     }
143 143
 
144
-    $html = apply_filters( 'wpinv_dropdown_users', $output );
144
+    $html = apply_filters('wpinv_dropdown_users', $output);
145 145
 
146
-    if ( $r['echo'] ) {
146
+    if ($r['echo']) {
147 147
         echo $html;
148 148
     }
149 149
     return $html;
150 150
 }
151 151
 
152
-function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) {
153
-    if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) {
154
-        wpinv_login_user( $user_id );
152
+function wpinv_guest_redirect($redirect_to, $user_id = 0) {
153
+    if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) {
154
+        wpinv_login_user($user_id);
155 155
     } else {
156
-        $redirect_to = wp_login_url( $redirect_to );
156
+        $redirect_to = wp_login_url($redirect_to);
157 157
     }
158 158
     
159
-    $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id );
159
+    $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id);
160 160
     
161
-    wp_redirect( $redirect_to );
161
+    wp_redirect($redirect_to);
162 162
 }
163 163
 
164
-function wpinv_login_user( $user_id ) {
165
-    if ( is_user_logged_in() ) {
164
+function wpinv_login_user($user_id) {
165
+    if (is_user_logged_in()) {
166 166
         return true;
167 167
     }
168 168
     
169
-    $user = get_user_by( 'id', $user_id );
169
+    $user = get_user_by('id', $user_id);
170 170
     
171
-    if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) {
172
-        wp_set_current_user( $user_id, $user->user_login );
173
-        wp_set_auth_cookie( $user_id );
174
-        do_action( 'wp_login', $user->user_login );
171
+    if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) {
172
+        wp_set_current_user($user_id, $user->user_login);
173
+        wp_set_auth_cookie($user_id);
174
+        do_action('wp_login', $user->user_login);
175 175
         
176 176
         return true;
177 177
     }
Please login to merge, or discard this patch.
includes/class-wpinv-reports.php 1 patch
Spacing   +169 added lines, -169 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
 
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
     public function init() {
22 22
         global $wp_filesystem;
23 23
 
24
-        if ( empty( $wp_filesystem ) ) {
25
-            require_once( ABSPATH . '/wp-admin/includes/file.php' );
24
+        if (empty($wp_filesystem)) {
25
+            require_once(ABSPATH . '/wp-admin/includes/file.php');
26 26
             WP_Filesystem();
27 27
             global $wp_filesystem;
28 28
         }
29 29
         $this->wp_filesystem    = $wp_filesystem;
30 30
         
31 31
         $this->export_dir       = $this->export_location();
32
-        $this->export_url       = $this->export_location( true );
32
+        $this->export_url       = $this->export_location(true);
33 33
         $this->export           = 'invoicing';
34 34
         $this->filetype         = 'csv';
35 35
         $this->per_page         = 20;
36 36
         
37
-        do_action( 'wpinv_class_reports_init', $this );
37
+        do_action('wpinv_class_reports_init', $this);
38 38
     }
39 39
     
40 40
     public function includes() {
41
-        do_action( 'wpinv_class_reports_includes', $this );
41
+        do_action('wpinv_class_reports_includes', $this);
42 42
     }
43 43
     
44 44
     public function actions() {
45
-        if ( is_admin() ) {
46
-            add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 );
47
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
48
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 10);
47
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
48
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
49 49
             
50 50
             // Export Invoices.
51
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
52
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
53
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
54
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
51
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
52
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
53
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
54
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
55 55
         }
56
-        do_action( 'wpinv_class_reports_actions', $this );
56
+        do_action('wpinv_class_reports_actions', $this);
57 57
     }
58 58
     
59 59
     public function add_submenu() {
60 60
         global $wpi_reports_page;
61
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) );
61
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', 'wpinv-reports', array($this, 'reports_page'));
62 62
     }
63 63
     
64 64
     public function reports_page() {
65
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
66
-            wp_enqueue_script( 'postbox' );
65
+        if (!wp_script_is('postbox', 'enqueued')) {
66
+            wp_enqueue_script('postbox');
67 67
         }
68
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
69
-            wp_enqueue_script( 'jquery-ui-datepicker' );
68
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
69
+            wp_enqueue_script('jquery-ui-datepicker');
70 70
         }
71 71
         
72
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
73
-        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export';
72
+        $current_page = admin_url('admin.php?page=wpinv-reports');
73
+        $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export';
74 74
         ?>
75 75
         <div class="wrap wpi-reports-wrap">
76
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
76
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
77 77
             <h2 class="nav-tab-wrapper wp-clearfix">
78
-                <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a>
79
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
78
+                <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a>
79
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
80 80
             </h2>
81 81
             <div class="wpi-reports-content wpi-reports-<?php echo $active_tab; ?>">
82 82
             <?php
83
-                do_action( 'wpinv_reports_page_top' );
84
-                do_action( 'wpinv_reports_tab_' . $active_tab );
85
-                do_action( 'wpinv_reports_page_bottom' );
83
+                do_action('wpinv_reports_page_top');
84
+                do_action('wpinv_reports_tab_' . $active_tab);
85
+                do_action('wpinv_reports_page_bottom');
86 86
             ?>
87 87
         </div>
88 88
         <?php
@@ -90,97 +90,97 @@  discard block
 block discarded – undo
90 90
     
91 91
     public function export() {
92 92
         $statuses = wpinv_get_invoice_statuses();
93
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
93
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
94 94
         ?>
95 95
         <div class="metabox-holder">
96 96
             <div id="post-body">
97 97
                 <div id="post-body-content">
98
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
98
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
99 99
                     
100 100
                     <div class="postbox wpi-export-invoices">
101
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
101
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
102 102
                         <div class="inside">
103
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
103
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
104 104
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
105
-                                <?php echo wpinv_html_date_field( array( 
105
+                                <?php echo wpinv_html_date_field(array( 
106 106
                                     'id' => 'wpi_export_from_date', 
107 107
                                     'name' => 'from_date',
108 108
                                     'data' => array(
109 109
                                         'dateFormat' => 'yy-mm-dd'
110 110
                                     ),
111
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
111
+                                    'placeholder' => __('From date', 'invoicing') )
112 112
                                 ); ?>
113
-                                <?php echo wpinv_html_date_field( array( 
113
+                                <?php echo wpinv_html_date_field(array( 
114 114
                                     'id' => 'wpi_export_to_date',
115 115
                                     'name' => 'to_date',
116 116
                                     'data' => array(
117 117
                                         'dateFormat' => 'yy-mm-dd'
118 118
                                     ),
119
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
119
+                                    'placeholder' => __('To date', 'invoicing') )
120 120
                                 ); ?>
121 121
                                 <span id="wpinv-status-wrap">
122
-                                <?php echo wpinv_html_select( array(
122
+                                <?php echo wpinv_html_select(array(
123 123
                                     'options'          => $statuses,
124 124
                                     'name'             => 'status',
125 125
                                     'id'               => 'wpi_export_status',
126 126
                                     'show_option_all'  => false,
127 127
                                     'show_option_none' => false,
128 128
                                     'class'            => '',
129
-                                ) ); ?>
130
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
129
+                                )); ?>
130
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
131 131
                                 </span>
132 132
                                 <span id="wpinv-submit-wrap">
133 133
                                     <input type="hidden" value="invoices" name="export" />
134
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
134
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
135 135
                                 </span>
136 136
                             </form>
137 137
                         </div>
138 138
                     </div>
139 139
                     
140
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
140
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
141 141
                 </div>
142 142
             </div>
143 143
         </div>
144 144
         <?php
145 145
     }
146 146
     
147
-    public function export_location( $relative = false ) {
147
+    public function export_location($relative = false) {
148 148
         $upload_dir         = wp_upload_dir();
149
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
150
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
149
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
150
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
151 151
         
152
-        return trailingslashit( $export_location );
152
+        return trailingslashit($export_location);
153 153
     }
154 154
     
155 155
     public function check_export_location() {
156 156
         try {
157
-            if ( empty( $this->wp_filesystem ) ) {
158
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
157
+            if (empty($this->wp_filesystem)) {
158
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
159 159
             }
160 160
 
161
-            if ( is_wp_error( $this->wp_filesystem ) ) {
162
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
161
+            if (is_wp_error($this->wp_filesystem)) {
162
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
163 163
             }
164 164
         
165
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
166
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
165
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
166
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
167 167
             
168
-            if ( $is_dir && $is_writeable ) {
168
+            if ($is_dir && $is_writeable) {
169 169
                return true;
170
-            } else if ( $is_dir && !$is_writeable ) {
171
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
170
+            } else if ($is_dir && !$is_writeable) {
171
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
172
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
173 173
                }
174 174
                
175 175
                return true;
176 176
             } else {
177
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
178
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
177
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
178
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
179 179
                 }
180 180
                 
181 181
                 return true;
182 182
             }
183
-        } catch ( Exception $e ) {
183
+        } catch (Exception $e) {
184 184
             return $e->getMessage();
185 185
         }
186 186
     }
@@ -188,130 +188,130 @@  discard block
 block discarded – undo
188 188
     public function ajax_export() {
189 189
         $response               = array();
190 190
         $response['success']    = false;
191
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
191
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
192 192
         
193
-        if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) {
194
-            wp_send_json( $response );
193
+        if (empty($_POST['data']) || !current_user_can('manage_options')) {
194
+            wp_send_json($response);
195 195
         }
196 196
 
197
-        parse_str( $_POST['data'], $data );
197
+        parse_str($_POST['data'], $data);
198 198
         
199
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
199
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
200 200
 
201 201
         $_REQUEST = (array)$data;
202
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
203
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
204
-            wp_send_json( $response );
202
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
203
+            $response['msg'] = __('Security check failed.', 'invoicing');
204
+            wp_send_json($response);
205 205
         }
206 206
         
207
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
208
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
209
-            wp_send_json( $response );
207
+        if (($error = $this->check_export_location(true)) !== true) {
208
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
209
+            wp_send_json($response);
210 210
         }
211 211
                         
212
-        $this->set_export_params( $_REQUEST );
212
+        $this->set_export_params($_REQUEST);
213 213
         
214 214
         $return = $this->process_export_step();
215 215
         $done   = $this->get_export_status();
216 216
         
217
-        if ( $return ) {
217
+        if ($return) {
218 218
             $this->step += 1;
219 219
             
220 220
             $response['success']    = true;
221 221
             $response['msg']        = '';
222 222
             
223
-            if ( $done >= 100 ) {
223
+            if ($done >= 100) {
224 224
                 $this->step     = 'done';
225
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
225
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
226 226
                 $new_file       = $this->export_dir . $new_filename;
227 227
                 
228
-                if ( file_exists( $this->file ) ) {
229
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
228
+                if (file_exists($this->file)) {
229
+                    $this->wp_filesystem->move($this->file, $new_file, true);
230 230
                 }
231 231
                 
232
-                if ( file_exists( $new_file ) ) {
233
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
232
+                if (file_exists($new_file)) {
233
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
234 234
                 }
235 235
             }
236 236
             
237 237
             $response['data']['step']   = $this->step;
238 238
             $response['data']['done']   = $done;
239 239
         } else {
240
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
240
+            $response['msg'] = __('No data found for export.', 'invoicing');
241 241
         }
242 242
 
243
-        wp_send_json( $response );
243
+        wp_send_json($response);
244 244
     }
245 245
     
246
-    public function set_export_params( $request ) {
246
+    public function set_export_params($request) {
247 247
         $this->empty    = false;
248
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
249
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
248
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
249
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
250 250
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
251 251
         $this->file     = $this->export_dir . $this->filename;
252 252
         
253
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
253
+        do_action('wpinv_export_set_params_' . $this->export, $request);
254 254
     }
255 255
     
256 256
     public function get_columns() {
257 257
         $columns = array(
258
-            'id'   => __( 'ID',   'invoicing' ),
259
-            'date' => __( 'Date', 'invoicing' )
258
+            'id'   => __('ID', 'invoicing'),
259
+            'date' => __('Date', 'invoicing')
260 260
         );
261 261
         
262
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
262
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
263 263
     }
264 264
     
265 265
     protected function get_export_file() {
266 266
         $file = '';
267 267
 
268
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
269
-            $file = $this->wp_filesystem->get_contents( $this->file );
268
+        if ($this->wp_filesystem->exists($this->file)) {
269
+            $file = $this->wp_filesystem->get_contents($this->file);
270 270
         } else {
271
-            $this->wp_filesystem->put_contents( $this->file, '' );
271
+            $this->wp_filesystem->put_contents($this->file, '');
272 272
         }
273 273
 
274 274
         return $file;
275 275
     }
276 276
     
277
-    protected function attach_export_data( $data = '' ) {
278
-        $filedata   = $this->get_export_file();
279
-        $filedata   .= $data;
277
+    protected function attach_export_data($data = '') {
278
+        $filedata = $this->get_export_file();
279
+        $filedata .= $data;
280 280
         
281
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
281
+        $this->wp_filesystem->put_contents($this->file, $filedata);
282 282
 
283
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
283
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
284 284
         $columns    = $this->get_columns();
285
-        $columns    = empty( $columns ) ? 0 : 1;
285
+        $columns    = empty($columns) ? 0 : 1;
286 286
 
287
-        $this->empty = count( $rows ) == $columns ? true : false;
287
+        $this->empty = count($rows) == $columns ? true : false;
288 288
     }
289 289
     
290 290
     public function print_columns() {
291 291
         $column_data    = '';
292 292
         $columns        = $this->get_columns();
293 293
         $i              = 1;
294
-        foreach( $columns as $key => $column ) {
295
-            $column_data .= '"' . addslashes( $column ) . '"';
296
-            $column_data .= $i == count( $columns ) ? '' : ',';
294
+        foreach ($columns as $key => $column) {
295
+            $column_data .= '"' . addslashes($column) . '"';
296
+            $column_data .= $i == count($columns) ? '' : ',';
297 297
             $i++;
298 298
         }
299 299
         $column_data .= "\r\n";
300 300
 
301
-        $this->attach_export_data( $column_data );
301
+        $this->attach_export_data($column_data);
302 302
 
303 303
         return $column_data;
304 304
     }
305 305
     
306 306
     public function process_export_step() {
307
-        if ( $this->step < 2 ) {
308
-            @unlink( $this->file );
307
+        if ($this->step < 2) {
308
+            @unlink($this->file);
309 309
             $this->print_columns();
310 310
         }
311 311
         
312 312
         $return = $this->print_rows();
313 313
         
314
-        if ( $return ) {
314
+        if ($return) {
315 315
             return true;
316 316
         } else {
317 317
             return false;
@@ -320,23 +320,23 @@  discard block
 block discarded – undo
320 320
     
321 321
     public function get_export_status() {
322 322
         $status = 100;
323
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
323
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
324 324
     }
325 325
     
326 326
     public function get_export_data() {
327 327
         $data = array(
328 328
             0 => array(
329 329
                 'id'   => '',
330
-                'data' => date( 'F j, Y' )
330
+                'data' => date('F j, Y')
331 331
             ),
332 332
             1 => array(
333 333
                 'id'   => '',
334
-                'data' => date( 'F j, Y' )
334
+                'data' => date('F j, Y')
335 335
             )
336 336
         );
337 337
 
338
-        $data = apply_filters( 'wpinv_export_get_data', $data );
339
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
338
+        $data = apply_filters('wpinv_export_get_data', $data);
339
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
340 340
 
341 341
         return $data;
342 342
     }
@@ -346,20 +346,20 @@  discard block
 block discarded – undo
346 346
         $data       = $this->get_export_data();
347 347
         $columns    = $this->get_columns();
348 348
 
349
-        if ( $data ) {
350
-            foreach ( $data as $row ) {
349
+        if ($data) {
350
+            foreach ($data as $row) {
351 351
                 $i = 1;
352
-                foreach ( $row as $key => $column ) {
353
-                    if ( array_key_exists( $key, $columns ) ) {
354
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
355
-                        $row_data .= $i == count( $columns ) ? '' : ',';
352
+                foreach ($row as $key => $column) {
353
+                    if (array_key_exists($key, $columns)) {
354
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
355
+                        $row_data .= $i == count($columns) ? '' : ',';
356 356
                         $i++;
357 357
                     }
358 358
                 }
359 359
                 $row_data .= "\r\n";
360 360
             }
361 361
 
362
-            $this->attach_export_data( $row_data );
362
+            $this->attach_export_data($row_data);
363 363
 
364 364
             return $row_data;
365 365
         }
@@ -368,46 +368,46 @@  discard block
 block discarded – undo
368 368
     }
369 369
     
370 370
     // Export Invoices.
371
-    public function set_invoices_export( $request ) {
372
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
373
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
374
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish';
371
+    public function set_invoices_export($request) {
372
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
373
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
374
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish';
375 375
     }
376 376
     
377
-    public function get_invoices_columns( $columns = array() ) {
377
+    public function get_invoices_columns($columns = array()) {
378 378
         $columns = array(
379
-            'id'            => __( 'ID',   'invoicing' ),
380
-            'number'        => __( 'Number',   'invoicing' ),
381
-            'date'          => __( 'Date', 'invoicing' ),
382
-            'amount'        => __( 'Amount', 'invoicing' ),
383
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
384
-            'status'        => __( 'Status', 'invoicing' ),
385
-            'tax'           => __( 'Tax', 'invoicing' ),
386
-            'discount'      => __( 'Discount', 'invoicing' ),
387
-            'user_id'       => __( 'User ID', 'invoicing' ),
388
-            'email'         => __( 'Email', 'invoicing' ),
389
-            'first_name'    => __( 'First Name', 'invoicing' ),
390
-            'last_name'     => __( 'Last Name', 'invoicing' ),
391
-            'address'       => __( 'Address', 'invoicing' ),
392
-            'city'          => __( 'City', 'invoicing' ),
393
-            'state'         => __( 'State', 'invoicing' ),
394
-            'country'       => __( 'Country', 'invoicing' ),
395
-            'zip'           => __( 'Zipcode', 'invoicing' ),
396
-            'phone'         => __( 'Phone', 'invoicing' ),
397
-            'company'       => __( 'Company', 'invoicing' ),
398
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
399
-            'ip'            => __( 'IP', 'invoicing' ),
400
-            'gateway'       => __( 'Gateway', 'invoicing' ),
401
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
402
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
403
-            'currency'      => __( 'Currency', 'invoicing' ),
404
-            'due_date'      => __( 'Due Date', 'invoicing' ),
379
+            'id'            => __('ID', 'invoicing'),
380
+            'number'        => __('Number', 'invoicing'),
381
+            'date'          => __('Date', 'invoicing'),
382
+            'amount'        => __('Amount', 'invoicing'),
383
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
384
+            'status'        => __('Status', 'invoicing'),
385
+            'tax'           => __('Tax', 'invoicing'),
386
+            'discount'      => __('Discount', 'invoicing'),
387
+            'user_id'       => __('User ID', 'invoicing'),
388
+            'email'         => __('Email', 'invoicing'),
389
+            'first_name'    => __('First Name', 'invoicing'),
390
+            'last_name'     => __('Last Name', 'invoicing'),
391
+            'address'       => __('Address', 'invoicing'),
392
+            'city'          => __('City', 'invoicing'),
393
+            'state'         => __('State', 'invoicing'),
394
+            'country'       => __('Country', 'invoicing'),
395
+            'zip'           => __('Zipcode', 'invoicing'),
396
+            'phone'         => __('Phone', 'invoicing'),
397
+            'company'       => __('Company', 'invoicing'),
398
+            'vat_number'    => __('Vat Number', 'invoicing'),
399
+            'ip'            => __('IP', 'invoicing'),
400
+            'gateway'       => __('Gateway', 'invoicing'),
401
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
402
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
403
+            'currency'      => __('Currency', 'invoicing'),
404
+            'due_date'      => __('Due Date', 'invoicing'),
405 405
         );
406 406
 
407 407
         return $columns;
408 408
     }
409 409
         
410
-    public function get_invoices_data( $response = array() ) {
410
+    public function get_invoices_data($response = array()) {
411 411
         $args = array(
412 412
             'limit'    => $this->per_page,
413 413
             'page'     => $this->step,
@@ -415,35 +415,35 @@  discard block
 block discarded – undo
415 415
             'orderby'  => 'date',
416 416
         );
417 417
         
418
-        if ( $this->status != 'any' ) {
418
+        if ($this->status != 'any') {
419 419
             $args['status'] = $this->status;
420 420
         }
421 421
 
422
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
422
+        if (!empty($this->from_date) || !empty($this->to_date)) {
423 423
             $args['date_query'] = array(
424 424
                 array(
425
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
426
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
425
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
426
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
427 427
                     'inclusive' => true
428 428
                 )
429 429
             );
430 430
         }
431 431
 
432
-        $invoices = wpinv_get_invoices( $args );
432
+        $invoices = wpinv_get_invoices($args);
433 433
         
434 434
         $data = array();
435 435
         
436
-        if ( !empty( $invoices ) ) {
437
-            foreach ( $invoices as $invoice ) {
436
+        if (!empty($invoices)) {
437
+            foreach ($invoices as $invoice) {
438 438
                 $row = array(
439 439
                     'id'            => $invoice->ID,
440 440
                     'number'        => $invoice->get_number(),
441
-                    'date'          => $invoice->get_invoice_date( false ),
442
-                    'amount'        => wpinv_round_amount( $invoice->get_total() ),
443
-                    'status_nicename' => $invoice->get_status( true ),
441
+                    'date'          => $invoice->get_invoice_date(false),
442
+                    'amount'        => wpinv_round_amount($invoice->get_total()),
443
+                    'status_nicename' => $invoice->get_status(true),
444 444
                     'status'        => $invoice->get_status(),
445
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '',
446
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '',
445
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '',
446
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '',
447 447
                     'user_id'       => $invoice->get_user_id(),
448 448
                     'email'         => $invoice->get_email(),
449 449
                     'first_name'    => $invoice->get_first_name(),
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
                     'due_date'      => $invoice->needs_payment() ? $invoice->get_due_date() : '',
465 465
                 );
466 466
                 
467
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
467
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
468 468
             }
469 469
 
470 470
             return $data;
@@ -480,29 +480,29 @@  discard block
 block discarded – undo
480 480
             'return'   => 'ids',
481 481
         );
482 482
         
483
-        if ( $this->status != 'any' ) {
483
+        if ($this->status != 'any') {
484 484
             $args['status'] = $this->status;
485 485
         }
486 486
 
487
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
487
+        if (!empty($this->from_date) || !empty($this->to_date)) {
488 488
             $args['date_query'] = array(
489 489
                 array(
490
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
491
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
490
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
491
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
492 492
                     'inclusive' => true
493 493
                 )
494 494
             );
495 495
         }
496 496
 
497
-        $invoices   = wpinv_get_invoices( $args );
498
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
497
+        $invoices   = wpinv_get_invoices($args);
498
+        $total      = !empty($invoices) ? count($invoices) : 0;
499 499
         $status     = 100;
500 500
 
501
-        if ( $total > 0 ) {
502
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
501
+        if ($total > 0) {
502
+            $status = (($this->per_page * $this->step) / $total) * 100;
503 503
         }
504 504
 
505
-        if ( $status > 100 ) {
505
+        if ($status > 100) {
506 506
             $status = 100;
507 507
         }
508 508
 
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Spacing   +507 added lines, -507 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  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
 function wpinv_init_transactional_emails() {
15
-    $email_actions = apply_filters( 'wpinv_email_actions', array(
15
+    $email_actions = apply_filters('wpinv_email_actions', array(
16 16
         'wpinv_status_pending_to_processing',
17 17
         'wpinv_status_pending_to_publish',
18 18
         'wpinv_status_pending_to_cancelled',
@@ -28,79 +28,79 @@  discard block
 block discarded – undo
28 28
         'wpinv_fully_refunded',
29 29
         'wpinv_partially_refunded',
30 30
         'wpinv_new_invoice_note'
31
-    ) );
31
+    ));
32 32
 
33
-    foreach ( $email_actions as $action ) {
34
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
33
+    foreach ($email_actions as $action) {
34
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
35 35
     }
36 36
 }
37
-add_action( 'init', 'wpinv_init_transactional_emails' );
37
+add_action('init', 'wpinv_init_transactional_emails');
38 38
 
39 39
 // New invoice email
40
-add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' );
41
-add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' );
42
-add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' );
43
-add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' );
44
-add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' );
45
-add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' );
40
+add_action('wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification');
41
+add_action('wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification');
42
+add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification');
43
+add_action('wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification');
44
+add_action('wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification');
45
+add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification');
46 46
 
47 47
 // Cancelled invoice email
48
-add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' );
49
-add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' );
48
+add_action('wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification');
49
+add_action('wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification');
50 50
 
51 51
 // Failed invoice email
52
-add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' );
53
-add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' );
52
+add_action('wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification');
53
+add_action('wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification');
54 54
 
55 55
 // On hold invoice email
56
-add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' );
57
-add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' );
56
+add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification');
57
+add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification');
58 58
 
59 59
 // Processing invoice email
60
-add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' );
60
+add_action('wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification');
61 61
 
62 62
 // Paid invoice email
63
-add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
63
+add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification');
64 64
 
65 65
 // Refunded invoice email
66
-add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
67
-add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
66
+add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification');
67
+add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification');
68 68
 
69 69
 // Invoice note
70
-add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
70
+add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification');
71 71
 
72
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
73
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
74
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
75
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
76
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
77
-add_action( 'wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4 );
72
+add_action('wpinv_email_header', 'wpinv_email_header');
73
+add_action('wpinv_email_footer', 'wpinv_email_footer');
74
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
75
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
76
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
77
+add_action('wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4);
78 78
 
79 79
 function wpinv_send_transactional_email() {
80 80
     $args       = func_get_args();
81 81
     $function   = current_filter() . '_notification';
82
-    do_action_ref_array( $function, $args );
82
+    do_action_ref_array($function, $args);
83 83
 }
84 84
     
85
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
85
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
86 86
     global $wpinv_email_search, $wpinv_email_replace;
87 87
     
88 88
     $email_type = 'new_invoice';
89
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
89
+    if (!wpinv_email_is_enabled($email_type)) {
90 90
         return false;
91 91
     }
92 92
     
93
-    $invoice = wpinv_get_invoice( $invoice_id );
94
-    if ( empty( $invoice ) ) {
93
+    $invoice = wpinv_get_invoice($invoice_id);
94
+    if (empty($invoice)) {
95 95
         return false;
96 96
     }
97 97
 
98
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
98
+    if (!("wpi_invoice" === $invoice->post_type)) {
99 99
         return false;
100 100
     }
101 101
     
102
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
103
-    if ( !is_email( $recipient ) ) {
102
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
103
+    if (!is_email($recipient)) {
104 104
         return false;
105 105
     }
106 106
         
@@ -117,41 +117,41 @@  discard block
 block discarded – undo
117 117
     $wpinv_email_search     = $search;
118 118
     $wpinv_email_replace    = $replace;
119 119
     
120
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
121
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
122
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
123
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
120
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
121
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
122
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
123
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
124 124
     
125
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
125
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
126 126
             'invoice'       => $invoice,
127 127
             'email_type'    => $email_type,
128 128
             'email_heading' => $email_heading,
129 129
             'sent_to_admin' => true,
130 130
             'plain_text'    => false,
131
-        ) );
131
+        ));
132 132
     
133
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
133
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
134 134
 }
135 135
 
136
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
136
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
137 137
     global $wpinv_email_search, $wpinv_email_replace;
138 138
     
139 139
     $email_type = 'cancelled_invoice';
140
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
140
+    if (!wpinv_email_is_enabled($email_type)) {
141 141
         return false;
142 142
     }
143 143
     
144
-    $invoice = wpinv_get_invoice( $invoice_id );
145
-    if ( empty( $invoice ) ) {
144
+    $invoice = wpinv_get_invoice($invoice_id);
145
+    if (empty($invoice)) {
146 146
         return false;
147 147
     }
148 148
 
149
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
149
+    if (!("wpi_invoice" === $invoice->post_type)) {
150 150
         return false;
151 151
     }
152 152
     
153
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
154
-    if ( !is_email( $recipient ) ) {
153
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
154
+    if (!is_email($recipient)) {
155 155
         return false;
156 156
     }
157 157
         
@@ -168,41 +168,41 @@  discard block
 block discarded – undo
168 168
     $wpinv_email_search     = $search;
169 169
     $wpinv_email_replace    = $replace;
170 170
     
171
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
172
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
173
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
174
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
171
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
172
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
173
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
174
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
175 175
     
176
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
176
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
177 177
             'invoice'       => $invoice,
178 178
             'email_type'    => $email_type,
179 179
             'email_heading' => $email_heading,
180 180
             'sent_to_admin' => true,
181 181
             'plain_text'    => false,
182
-        ) );
182
+        ));
183 183
     
184
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
184
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
185 185
 }
186 186
 
187
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
187
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
188 188
     global $wpinv_email_search, $wpinv_email_replace;
189 189
     
190 190
     $email_type = 'failed_invoice';
191
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
191
+    if (!wpinv_email_is_enabled($email_type)) {
192 192
         return false;
193 193
     }
194 194
     
195
-    $invoice = wpinv_get_invoice( $invoice_id );
196
-    if ( empty( $invoice ) ) {
195
+    $invoice = wpinv_get_invoice($invoice_id);
196
+    if (empty($invoice)) {
197 197
         return false;
198 198
     }
199 199
 
200
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
200
+    if (!("wpi_invoice" === $invoice->post_type)) {
201 201
         return false;
202 202
     }
203 203
     
204
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
205
-    if ( !is_email( $recipient ) ) {
204
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
205
+    if (!is_email($recipient)) {
206 206
         return false;
207 207
     }
208 208
         
@@ -219,41 +219,41 @@  discard block
 block discarded – undo
219 219
     $wpinv_email_search     = $search;
220 220
     $wpinv_email_replace    = $replace;
221 221
     
222
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
223
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
224
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
225
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
222
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
223
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
224
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
225
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
226 226
     
227
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
227
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
228 228
             'invoice'       => $invoice,
229 229
             'email_type'    => $email_type,
230 230
             'email_heading' => $email_heading,
231 231
             'sent_to_admin' => true,
232 232
             'plain_text'    => false,
233
-        ) );
233
+        ));
234 234
     
235
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
235
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
236 236
 }
237 237
 
238
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
238
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
239 239
     global $wpinv_email_search, $wpinv_email_replace;
240 240
     
241 241
     $email_type = 'onhold_invoice';
242
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
242
+    if (!wpinv_email_is_enabled($email_type)) {
243 243
         return false;
244 244
     }
245 245
     
246
-    $invoice = wpinv_get_invoice( $invoice_id );
247
-    if ( empty( $invoice ) ) {
246
+    $invoice = wpinv_get_invoice($invoice_id);
247
+    if (empty($invoice)) {
248 248
         return false;
249 249
     }
250 250
 
251
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
251
+    if (!("wpi_invoice" === $invoice->post_type)) {
252 252
         return false;
253 253
     }
254 254
     
255
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
256
-    if ( !is_email( $recipient ) ) {
255
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
256
+    if (!is_email($recipient)) {
257 257
         return false;
258 258
     }
259 259
         
@@ -270,49 +270,49 @@  discard block
 block discarded – undo
270 270
     $wpinv_email_search     = $search;
271 271
     $wpinv_email_replace    = $replace;
272 272
     
273
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
274
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
275
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
276
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
273
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
274
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
275
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
276
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
277 277
     
278
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
278
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
279 279
             'invoice'       => $invoice,
280 280
             'email_type'    => $email_type,
281 281
             'email_heading' => $email_heading,
282 282
             'sent_to_admin' => false,
283 283
             'plain_text'    => false,
284
-        ) );
284
+        ));
285 285
     
286
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
286
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
287 287
     
288
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
289
-        $recipient  = wpinv_get_admin_email();
290
-        $subject    .= ' - ADMIN BCC COPY';
291
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
288
+    if (wpinv_mail_admin_bcc_active($email_type)) {
289
+        $recipient = wpinv_get_admin_email();
290
+        $subject .= ' - ADMIN BCC COPY';
291
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
292 292
     }
293 293
     
294 294
     return $sent;
295 295
 }
296 296
 
297
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
297
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
298 298
     global $wpinv_email_search, $wpinv_email_replace;
299 299
     
300 300
     $email_type = 'processing_invoice';
301
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
301
+    if (!wpinv_email_is_enabled($email_type)) {
302 302
         return false;
303 303
     }
304 304
     
305
-    $invoice = wpinv_get_invoice( $invoice_id );
306
-    if ( empty( $invoice ) ) {
305
+    $invoice = wpinv_get_invoice($invoice_id);
306
+    if (empty($invoice)) {
307 307
         return false;
308 308
     }
309 309
 
310
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
310
+    if (!("wpi_invoice" === $invoice->post_type)) {
311 311
         return false;
312 312
     }
313 313
     
314
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
315
-    if ( !is_email( $recipient ) ) {
314
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
315
+    if (!is_email($recipient)) {
316 316
         return false;
317 317
     }
318 318
         
@@ -329,49 +329,49 @@  discard block
 block discarded – undo
329 329
     $wpinv_email_search     = $search;
330 330
     $wpinv_email_replace    = $replace;
331 331
     
332
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
333
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
334
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
335
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
332
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
333
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
334
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
335
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
336 336
     
337
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
337
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
338 338
             'invoice'       => $invoice,
339 339
             'email_type'    => $email_type,
340 340
             'email_heading' => $email_heading,
341 341
             'sent_to_admin' => false,
342 342
             'plain_text'    => false,
343
-        ) );
343
+        ));
344 344
     
345
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
345
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
346 346
     
347
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
348
-        $recipient  = wpinv_get_admin_email();
349
-        $subject    .= ' - ADMIN BCC COPY';
350
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
347
+    if (wpinv_mail_admin_bcc_active($email_type)) {
348
+        $recipient = wpinv_get_admin_email();
349
+        $subject .= ' - ADMIN BCC COPY';
350
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
351 351
     }
352 352
     
353 353
     return $sent;
354 354
 }
355 355
 
356
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
356
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
357 357
     global $wpinv_email_search, $wpinv_email_replace;
358 358
     
359 359
     $email_type = 'completed_invoice';
360
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
360
+    if (!wpinv_email_is_enabled($email_type)) {
361 361
         return false;
362 362
     }
363 363
     
364
-    $invoice = wpinv_get_invoice( $invoice_id );
365
-    if ( empty( $invoice ) ) {
364
+    $invoice = wpinv_get_invoice($invoice_id);
365
+    if (empty($invoice)) {
366 366
         return false;
367 367
     }
368 368
 
369
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
369
+    if (!("wpi_invoice" === $invoice->post_type)) {
370 370
         return false;
371 371
     }
372 372
     
373
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
374
-    if ( !is_email( $recipient ) ) {
373
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
374
+    if (!is_email($recipient)) {
375 375
         return false;
376 376
     }
377 377
         
@@ -388,49 +388,49 @@  discard block
 block discarded – undo
388 388
     $wpinv_email_search     = $search;
389 389
     $wpinv_email_replace    = $replace;
390 390
     
391
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
392
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
393
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
394
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
391
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
392
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
393
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
394
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
395 395
     
396
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
396
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
397 397
             'invoice'       => $invoice,
398 398
             'email_type'    => $email_type,
399 399
             'email_heading' => $email_heading,
400 400
             'sent_to_admin' => false,
401 401
             'plain_text'    => false,
402
-        ) );
402
+        ));
403 403
     
404
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
404
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
405 405
     
406
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
407
-        $recipient  = wpinv_get_admin_email();
408
-        $subject    .= ' - ADMIN BCC COPY';
409
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
406
+    if (wpinv_mail_admin_bcc_active($email_type)) {
407
+        $recipient = wpinv_get_admin_email();
408
+        $subject .= ' - ADMIN BCC COPY';
409
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
410 410
     }
411 411
     
412 412
     return $sent;
413 413
 }
414 414
 
415
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
415
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
416 416
     global $wpinv_email_search, $wpinv_email_replace;
417 417
     
418 418
     $email_type = 'refunded_invoice';
419
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
419
+    if (!wpinv_email_is_enabled($email_type)) {
420 420
         return false;
421 421
     }
422 422
     
423
-    $invoice = wpinv_get_invoice( $invoice_id );
424
-    if ( empty( $invoice ) ) {
423
+    $invoice = wpinv_get_invoice($invoice_id);
424
+    if (empty($invoice)) {
425 425
         return false;
426 426
     }
427 427
 
428
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
428
+    if (!("wpi_invoice" === $invoice->post_type)) {
429 429
         return false;
430 430
     }
431 431
     
432
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
433
-    if ( !is_email( $recipient ) ) {
432
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
433
+    if (!is_email($recipient)) {
434 434
         return false;
435 435
     }
436 436
         
@@ -447,50 +447,50 @@  discard block
 block discarded – undo
447 447
     $wpinv_email_search     = $search;
448 448
     $wpinv_email_replace    = $replace;
449 449
     
450
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
451
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
452
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
453
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
450
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
451
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
452
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
453
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
454 454
     
455
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
455
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
456 456
             'invoice'           => $invoice,
457 457
             'email_type'        => $email_type,
458 458
             'email_heading'     => $email_heading,
459 459
             'sent_to_admin'     => false,
460 460
             'plain_text'        => false,
461 461
             'partial_refund'    => false
462
-        ) );
462
+        ));
463 463
     
464
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
464
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
465 465
     
466
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
467
-        $recipient  = wpinv_get_admin_email();
468
-        $subject    .= ' - ADMIN BCC COPY';
469
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
466
+    if (wpinv_mail_admin_bcc_active($email_type)) {
467
+        $recipient = wpinv_get_admin_email();
468
+        $subject .= ' - ADMIN BCC COPY';
469
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
470 470
     }
471 471
     
472 472
     return $sent;
473 473
 }
474 474
 
475
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
475
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
476 476
     global $wpinv_email_search, $wpinv_email_replace;
477 477
     
478 478
     $email_type = 'refunded_invoice';
479
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
479
+    if (!wpinv_email_is_enabled($email_type)) {
480 480
         return false;
481 481
     }
482 482
     
483
-    $invoice = wpinv_get_invoice( $invoice_id );
484
-    if ( empty( $invoice ) ) {
483
+    $invoice = wpinv_get_invoice($invoice_id);
484
+    if (empty($invoice)) {
485 485
         return false;
486 486
     }
487 487
 
488
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
488
+    if (!("wpi_invoice" === $invoice->post_type)) {
489 489
         return false;
490 490
     }
491 491
     
492
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
493
-    if ( !is_email( $recipient ) ) {
492
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
493
+    if (!is_email($recipient)) {
494 494
         return false;
495 495
     }
496 496
         
@@ -507,53 +507,53 @@  discard block
 block discarded – undo
507 507
     $wpinv_email_search     = $search;
508 508
     $wpinv_email_replace    = $replace;
509 509
     
510
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
511
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
512
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
513
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
510
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
511
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
512
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
513
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
514 514
     
515
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
515
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
516 516
             'invoice'           => $invoice,
517 517
             'email_type'        => $email_type,
518 518
             'email_heading'     => $email_heading,
519 519
             'sent_to_admin'     => false,
520 520
             'plain_text'        => false,
521 521
             'partial_refund'    => true
522
-        ) );
522
+        ));
523 523
     
524
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
524
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
525 525
     
526
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
527
-        $recipient  = wpinv_get_admin_email();
528
-        $subject    .= ' - ADMIN BCC COPY';
529
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
526
+    if (wpinv_mail_admin_bcc_active($email_type)) {
527
+        $recipient = wpinv_get_admin_email();
528
+        $subject .= ' - ADMIN BCC COPY';
529
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
530 530
     }
531 531
     
532 532
     return $sent;
533 533
 }
534 534
 
535
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
535
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
536 536
 }
537 537
 
538
-function wpinv_user_invoice_notification( $invoice_id ) {
538
+function wpinv_user_invoice_notification($invoice_id) {
539 539
     global $wpinv_email_search, $wpinv_email_replace;
540 540
     
541 541
     $email_type = 'user_invoice';
542
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
542
+    if (!wpinv_email_is_enabled($email_type)) {
543 543
         return false;
544 544
     }
545 545
     
546
-    $invoice = wpinv_get_invoice( $invoice_id );
547
-    if ( empty( $invoice ) ) {
546
+    $invoice = wpinv_get_invoice($invoice_id);
547
+    if (empty($invoice)) {
548 548
         return false;
549 549
     }
550 550
 
551
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
551
+    if (!("wpi_invoice" === $invoice->post_type)) {
552 552
         return false;
553 553
     }
554 554
     
555
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
556
-    if ( !is_email( $recipient ) ) {
555
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
556
+    if (!is_email($recipient)) {
557 557
         return false;
558 558
     }
559 559
         
@@ -570,52 +570,52 @@  discard block
 block discarded – undo
570 570
     $wpinv_email_search     = $search;
571 571
     $wpinv_email_replace    = $replace;
572 572
     
573
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
574
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
575
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
576
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
573
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
574
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
575
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
576
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
577 577
     
578
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
578
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
579 579
             'invoice'       => $invoice,
580 580
             'email_type'    => $email_type,
581 581
             'email_heading' => $email_heading,
582 582
             'sent_to_admin' => false,
583 583
             'plain_text'    => false,
584
-        ) );
584
+        ));
585 585
     
586
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
586
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
587 587
     
588
-    if ( $sent ) {
589
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
588
+    if ($sent) {
589
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
590 590
     } else {
591
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
591
+        $note = __('Fail to send invoice to the user!', 'invoicing');
592 592
     }
593
-    $invoice->add_note( $note ); // Add private note.
593
+    $invoice->add_note($note); // Add private note.
594 594
     
595
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
596
-        $recipient  = wpinv_get_admin_email();
597
-        $subject    .= ' - ADMIN BCC COPY';
598
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
595
+    if (wpinv_mail_admin_bcc_active($email_type)) {
596
+        $recipient = wpinv_get_admin_email();
597
+        $subject .= ' - ADMIN BCC COPY';
598
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
599 599
     }
600 600
     
601 601
     return $sent;
602 602
 }
603 603
 
604
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
604
+function wpinv_user_note_notification($invoice_id, $args = array()) {
605 605
     global $wpinv_email_search, $wpinv_email_replace;
606 606
     
607 607
     $email_type = 'user_note';
608
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
608
+    if (!wpinv_email_is_enabled($email_type)) {
609 609
         return false;
610 610
     }
611 611
     
612
-    $invoice = wpinv_get_invoice( $invoice_id );
613
-    if ( empty( $invoice ) ) {
612
+    $invoice = wpinv_get_invoice($invoice_id);
613
+    if (empty($invoice)) {
614 614
         return false;
615 615
     }
616 616
     
617
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
618
-    if ( !is_email( $recipient ) ) {
617
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
618
+    if (!is_email($recipient)) {
619 619
         return false;
620 620
     }
621 621
     
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
         'user_note' => ''
624 624
     );
625 625
 
626
-    $args = wp_parse_args( $args, $defaults );
626
+    $args = wp_parse_args($args, $defaults);
627 627
         
628 628
     $search                     = array();
629 629
     $search['invoice_number']   = '{invoice_number}';
@@ -642,46 +642,46 @@  discard block
 block discarded – undo
642 642
     $wpinv_email_search     = $search;
643 643
     $wpinv_email_replace    = $replace;
644 644
     
645
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
646
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
647
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
648
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
645
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
646
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
647
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
648
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
649 649
     
650
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
650
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
651 651
             'invoice'       => $invoice,
652 652
             'email_type'    => $email_type,
653 653
             'email_heading' => $email_heading,
654 654
             'sent_to_admin' => false,
655 655
             'plain_text'    => false,
656 656
             'customer_note' => $args['user_note']
657
-        ) );
657
+        ));
658 658
         
659
-    $content        = wpinv_email_format_text( $content );
659
+    $content = wpinv_email_format_text($content);
660 660
     
661
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
661
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
662 662
         
663 663
     return $sent;
664 664
 }
665 665
 
666 666
 function wpinv_mail_get_from_address() {
667
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
668
-    return sanitize_email( $from_address );
667
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
668
+    return sanitize_email($from_address);
669 669
 }
670 670
 
671 671
 function wpinv_mail_get_from_name() {
672
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
673
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
672
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
673
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
674 674
 }
675 675
 
676
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
677
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
678
-    return ( $active ? true : false );
676
+function wpinv_mail_admin_bcc_active($mail_type = '') {
677
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
678
+    return ($active ? true : false);
679 679
 }
680 680
     
681
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
682
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
681
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
682
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
683 683
     
684
-    switch ( $email_type ) {
684
+    switch ($email_type) {
685 685
         case 'html' :
686 686
             $content_type = 'text/html';
687 687
             break;
@@ -696,35 +696,35 @@  discard block
 block discarded – undo
696 696
     return $content_type;
697 697
 }
698 698
     
699
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
700
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
701
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
702
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
699
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments) {
700
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
701
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
702
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
703 703
 
704
-    $message = wpinv_email_style_body( $message );
705
-    $message = apply_filters( 'wpinv_mail_content', $message );
704
+    $message = wpinv_email_style_body($message);
705
+    $message = apply_filters('wpinv_mail_content', $message);
706 706
     
707
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
707
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
708 708
     
709
-    if ( !$sent ) {
710
-        $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject );
711
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
709
+    if (!$sent) {
710
+        $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject);
711
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
712 712
     }
713 713
 
714
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
715
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
716
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
714
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
715
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
716
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
717 717
 
718 718
     return $sent;
719 719
 }
720 720
     
721 721
 function wpinv_get_emails() {
722 722
     $overdue_days_options       = array();
723
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
724
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
723
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
724
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
725 725
     
726
-    for ( $i = 2; $i <= 10; $i++ ) {
727
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
726
+    for ($i = 2; $i <= 10; $i++) {
727
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
728 728
     }
729 729
 
730 730
 	// Default, built-in gateways
@@ -732,130 +732,130 @@  discard block
 block discarded – undo
732 732
             'new_invoice' => array(
733 733
             'email_new_invoice_header' => array(
734 734
                 'id'   => 'email_new_invoice_header',
735
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
736
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
735
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
736
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
737 737
                 'type' => 'header',
738 738
             ),
739 739
             'email_new_invoice_active' => array(
740 740
                 'id'   => 'email_new_invoice_active',
741
-                'name' => __( 'Enable/Disable', 'invoicing' ),
742
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
741
+                'name' => __('Enable/Disable', 'invoicing'),
742
+                'desc' => __('Enable this email notification', 'invoicing'),
743 743
                 'type' => 'checkbox',
744 744
                 'std'  => 1
745 745
             ),
746 746
             'email_new_invoice_subject' => array(
747 747
                 'id'   => 'email_new_invoice_subject',
748
-                'name' => __( 'Subject', 'invoicing' ),
749
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
748
+                'name' => __('Subject', 'invoicing'),
749
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
750 750
                 'type' => 'text',
751
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
751
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
752 752
                 'size' => 'large'
753 753
             ),
754 754
             'email_new_invoice_heading' => array(
755 755
                 'id'   => 'email_new_invoice_heading',
756
-                'name' => __( 'Email Heading', 'invoicing' ),
757
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
756
+                'name' => __('Email Heading', 'invoicing'),
757
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
758 758
                 'type' => 'text',
759
-                'std'  => __( 'New payment invoice', 'invoicing' ),
759
+                'std'  => __('New payment invoice', 'invoicing'),
760 760
                 'size' => 'large'
761 761
             ),
762 762
         ),
763 763
         'cancelled_invoice' => array(
764 764
             'email_cancelled_invoice_header' => array(
765 765
                 'id'   => 'email_cancelled_invoice_header',
766
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
767
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
766
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
767
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
768 768
                 'type' => 'header',
769 769
             ),
770 770
             'email_cancelled_invoice_active' => array(
771 771
                 'id'   => 'email_cancelled_invoice_active',
772
-                'name' => __( 'Enable/Disable', 'invoicing' ),
773
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
772
+                'name' => __('Enable/Disable', 'invoicing'),
773
+                'desc' => __('Enable this email notification', 'invoicing'),
774 774
                 'type' => 'checkbox',
775 775
                 'std'  => 1
776 776
             ),
777 777
             'email_cancelled_invoice_subject' => array(
778 778
                 'id'   => 'email_cancelled_invoice_subject',
779
-                'name' => __( 'Subject', 'invoicing' ),
780
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
779
+                'name' => __('Subject', 'invoicing'),
780
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
781 781
                 'type' => 'text',
782
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
782
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
783 783
                 'size' => 'large'
784 784
             ),
785 785
             'email_cancelled_invoice_heading' => array(
786 786
                 'id'   => 'email_cancelled_invoice_heading',
787
-                'name' => __( 'Email Heading', 'invoicing' ),
788
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
787
+                'name' => __('Email Heading', 'invoicing'),
788
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
789 789
                 'type' => 'text',
790
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
790
+                'std'  => __('Cancelled invoice', 'invoicing'),
791 791
                 'size' => 'large'
792 792
             ),
793 793
         ),
794 794
         'failed_invoice' => array(
795 795
             'email_failed_invoice_header' => array(
796 796
                 'id'   => 'email_failed_invoice_header',
797
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
798
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
797
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
798
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
799 799
                 'type' => 'header',
800 800
             ),
801 801
             'email_failed_invoice_active' => array(
802 802
                 'id'   => 'email_failed_invoice_active',
803
-                'name' => __( 'Enable/Disable', 'invoicing' ),
804
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
803
+                'name' => __('Enable/Disable', 'invoicing'),
804
+                'desc' => __('Enable this email notification', 'invoicing'),
805 805
                 'type' => 'checkbox',
806 806
                 'std'  => 1
807 807
             ),
808 808
             'email_failed_invoice_subject' => array(
809 809
                 'id'   => 'email_failed_invoice_subject',
810
-                'name' => __( 'Subject', 'invoicing' ),
811
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
810
+                'name' => __('Subject', 'invoicing'),
811
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
812 812
                 'type' => 'text',
813
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
813
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
814 814
                 'size' => 'large'
815 815
             ),
816 816
             'email_failed_invoice_heading' => array(
817 817
                 'id'   => 'email_failed_invoice_heading',
818
-                'name' => __( 'Email Heading', 'invoicing' ),
819
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
818
+                'name' => __('Email Heading', 'invoicing'),
819
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
820 820
                 'type' => 'text',
821
-                'std'  => __( 'Failed invoice', 'invoicing' ),
821
+                'std'  => __('Failed invoice', 'invoicing'),
822 822
                 'size' => 'large'
823 823
             )
824 824
         ),
825 825
         'onhold_invoice' => array(
826 826
             'email_onhold_invoice_header' => array(
827 827
                 'id'   => 'email_onhold_invoice_header',
828
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
829
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
828
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
829
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
830 830
                 'type' => 'header',
831 831
             ),
832 832
             'email_onhold_invoice_active' => array(
833 833
                 'id'   => 'email_onhold_invoice_active',
834
-                'name' => __( 'Enable/Disable', 'invoicing' ),
835
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
834
+                'name' => __('Enable/Disable', 'invoicing'),
835
+                'desc' => __('Enable this email notification', 'invoicing'),
836 836
                 'type' => 'checkbox',
837 837
                 'std'  => 1
838 838
             ),
839 839
             'email_onhold_invoice_subject' => array(
840 840
                 'id'   => 'email_onhold_invoice_subject',
841
-                'name' => __( 'Subject', 'invoicing' ),
842
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
841
+                'name' => __('Subject', 'invoicing'),
842
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
843 843
                 'type' => 'text',
844
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
844
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
845 845
                 'size' => 'large'
846 846
             ),
847 847
             'email_onhold_invoice_heading' => array(
848 848
                 'id'   => 'email_onhold_invoice_heading',
849
-                'name' => __( 'Email Heading', 'invoicing' ),
850
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
849
+                'name' => __('Email Heading', 'invoicing'),
850
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
851 851
                 'type' => 'text',
852
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
852
+                'std'  => __('Thank you for your invoice', 'invoicing'),
853 853
                 'size' => 'large'
854 854
             ),
855 855
             'email_onhold_invoice_admin_bcc' => array(
856 856
                 'id'   => 'email_onhold_invoice_admin_bcc',
857
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
858
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
857
+                'name' => __('Enable Admin BCC', 'invoicing'),
858
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
859 859
                 'type' => 'checkbox',
860 860
                 'std'  => 1
861 861
             ),
@@ -863,37 +863,37 @@  discard block
 block discarded – undo
863 863
         'processing_invoice' => array(
864 864
             'email_processing_invoice_header' => array(
865 865
                 'id'   => 'email_processing_invoice_header',
866
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
867
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
866
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
867
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
868 868
                 'type' => 'header',
869 869
             ),
870 870
             'email_processing_invoice_active' => array(
871 871
                 'id'   => 'email_processing_invoice_active',
872
-                'name' => __( 'Enable/Disable', 'invoicing' ),
873
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
872
+                'name' => __('Enable/Disable', 'invoicing'),
873
+                'desc' => __('Enable this email notification', 'invoicing'),
874 874
                 'type' => 'checkbox',
875 875
                 'std'  => 1
876 876
             ),
877 877
             'email_processing_invoice_subject' => array(
878 878
                 'id'   => 'email_processing_invoice_subject',
879
-                'name' => __( 'Subject', 'invoicing' ),
880
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
879
+                'name' => __('Subject', 'invoicing'),
880
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
881 881
                 'type' => 'text',
882
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
882
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
883 883
                 'size' => 'large'
884 884
             ),
885 885
             'email_processing_invoice_heading' => array(
886 886
                 'id'   => 'email_processing_invoice_heading',
887
-                'name' => __( 'Email Heading', 'invoicing' ),
888
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
887
+                'name' => __('Email Heading', 'invoicing'),
888
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
889 889
                 'type' => 'text',
890
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
890
+                'std'  => __('Thank you for your invoice', 'invoicing'),
891 891
                 'size' => 'large'
892 892
             ),
893 893
             'email_processing_invoice_admin_bcc' => array(
894 894
                 'id'   => 'email_processing_invoice_admin_bcc',
895
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
896
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
895
+                'name' => __('Enable Admin BCC', 'invoicing'),
896
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
897 897
                 'type' => 'checkbox',
898 898
                 'std'  => 1
899 899
             ),
@@ -901,37 +901,37 @@  discard block
 block discarded – undo
901 901
         'completed_invoice' => array(
902 902
             'email_completed_invoice_header' => array(
903 903
                 'id'   => 'email_completed_invoice_header',
904
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
905
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
904
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
905
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
906 906
                 'type' => 'header',
907 907
             ),
908 908
             'email_completed_invoice_active' => array(
909 909
                 'id'   => 'email_completed_invoice_active',
910
-                'name' => __( 'Enable/Disable', 'invoicing' ),
911
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
910
+                'name' => __('Enable/Disable', 'invoicing'),
911
+                'desc' => __('Enable this email notification', 'invoicing'),
912 912
                 'type' => 'checkbox',
913 913
                 'std'  => 1
914 914
             ),
915 915
             'email_completed_invoice_subject' => array(
916 916
                 'id'   => 'email_completed_invoice_subject',
917
-                'name' => __( 'Subject', 'invoicing' ),
918
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
917
+                'name' => __('Subject', 'invoicing'),
918
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
919 919
                 'type' => 'text',
920
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
920
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
921 921
                 'size' => 'large'
922 922
             ),
923 923
             'email_completed_invoice_heading' => array(
924 924
                 'id'   => 'email_completed_invoice_heading',
925
-                'name' => __( 'Email Heading', 'invoicing' ),
926
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
925
+                'name' => __('Email Heading', 'invoicing'),
926
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
927 927
                 'type' => 'text',
928
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
928
+                'std'  => __('Your invoice has been paid', 'invoicing'),
929 929
                 'size' => 'large'
930 930
             ),
931 931
             'email_completed_invoice_admin_bcc' => array(
932 932
                 'id'   => 'email_completed_invoice_admin_bcc',
933
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
934
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
933
+                'name' => __('Enable Admin BCC', 'invoicing'),
934
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
935 935
                 'type' => 'checkbox',
936 936
             ),
937 937
             'std'  => 1
@@ -939,37 +939,37 @@  discard block
 block discarded – undo
939 939
         'refunded_invoice' => array(
940 940
             'email_refunded_invoice_header' => array(
941 941
                 'id'   => 'email_refunded_invoice_header',
942
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
943
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
942
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
943
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
944 944
                 'type' => 'header',
945 945
             ),
946 946
             'email_refunded_invoice_active' => array(
947 947
                 'id'   => 'email_refunded_invoice_active',
948
-                'name' => __( 'Enable/Disable', 'invoicing' ),
949
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
948
+                'name' => __('Enable/Disable', 'invoicing'),
949
+                'desc' => __('Enable this email notification', 'invoicing'),
950 950
                 'type' => 'checkbox',
951 951
                 'std'  => 1
952 952
             ),
953 953
             'email_refunded_invoice_subject' => array(
954 954
                 'id'   => 'email_refunded_invoice_subject',
955
-                'name' => __( 'Subject', 'invoicing' ),
956
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
955
+                'name' => __('Subject', 'invoicing'),
956
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
957 957
                 'type' => 'text',
958
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
958
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
959 959
                 'size' => 'large'
960 960
             ),
961 961
             'email_refunded_invoice_heading' => array(
962 962
                 'id'   => 'email_refunded_invoice_heading',
963
-                'name' => __( 'Email Heading', 'invoicing' ),
964
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
963
+                'name' => __('Email Heading', 'invoicing'),
964
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
965 965
                 'type' => 'text',
966
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
966
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
967 967
                 'size' => 'large'
968 968
             ),
969 969
             'email_refunded_invoice_admin_bcc' => array(
970 970
                 'id'   => 'email_refunded_invoice_admin_bcc',
971
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
972
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
971
+                'name' => __('Enable Admin BCC', 'invoicing'),
972
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
973 973
                 'type' => 'checkbox',
974 974
                 'std'  => 1
975 975
             ),
@@ -977,37 +977,37 @@  discard block
 block discarded – undo
977 977
         'user_invoice' => array(
978 978
             'email_user_invoice_header' => array(
979 979
                 'id'   => 'email_user_invoice_header',
980
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
981
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
980
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
981
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
982 982
                 'type' => 'header',
983 983
             ),
984 984
             'email_user_invoice_active' => array(
985 985
                 'id'   => 'email_user_invoice_active',
986
-                'name' => __( 'Enable/Disable', 'invoicing' ),
987
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
986
+                'name' => __('Enable/Disable', 'invoicing'),
987
+                'desc' => __('Enable this email notification', 'invoicing'),
988 988
                 'type' => 'checkbox',
989 989
                 'std'  => 1
990 990
             ),
991 991
             'email_user_invoice_subject' => array(
992 992
                 'id'   => 'email_user_invoice_subject',
993
-                'name' => __( 'Subject', 'invoicing' ),
994
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
993
+                'name' => __('Subject', 'invoicing'),
994
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
995 995
                 'type' => 'text',
996
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
996
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
997 997
                 'size' => 'large'
998 998
             ),
999 999
             'email_user_invoice_heading' => array(
1000 1000
                 'id'   => 'email_user_invoice_heading',
1001
-                'name' => __( 'Email Heading', 'invoicing' ),
1002
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
1001
+                'name' => __('Email Heading', 'invoicing'),
1002
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
1003 1003
                 'type' => 'text',
1004
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1004
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
1005 1005
                 'size' => 'large'
1006 1006
             ),
1007 1007
             'email_user_invoice_admin_bcc' => array(
1008 1008
                 'id'   => 'email_user_invoice_admin_bcc',
1009
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1010
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1009
+                'name' => __('Enable Admin BCC', 'invoicing'),
1010
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1011 1011
                 'type' => 'checkbox',
1012 1012
                 'std'  => 1
1013 1013
             ),
@@ -1015,177 +1015,177 @@  discard block
 block discarded – undo
1015 1015
         'user_note' => array(
1016 1016
             'email_user_note_header' => array(
1017 1017
                 'id'   => 'email_user_note_header',
1018
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1019
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ),
1018
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
1019
+                'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'),
1020 1020
                 'type' => 'header',
1021 1021
             ),
1022 1022
             'email_user_note_active' => array(
1023 1023
                 'id'   => 'email_user_note_active',
1024
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1025
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1024
+                'name' => __('Enable/Disable', 'invoicing'),
1025
+                'desc' => __('Enable this email notification', 'invoicing'),
1026 1026
                 'type' => 'checkbox',
1027 1027
                 'std'  => 1
1028 1028
             ),
1029 1029
             'email_user_note_subject' => array(
1030 1030
                 'id'   => 'email_user_note_subject',
1031
-                'name' => __( 'Subject', 'invoicing' ),
1032
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1031
+                'name' => __('Subject', 'invoicing'),
1032
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1033 1033
                 'type' => 'text',
1034
-                'std'  => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ),
1034
+                'std'  => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'),
1035 1035
                 'size' => 'large'
1036 1036
             ),
1037 1037
             'email_user_note_heading' => array(
1038 1038
                 'id'   => 'email_user_note_heading',
1039
-                'name' => __( 'Email Heading', 'invoicing' ),
1040
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1039
+                'name' => __('Email Heading', 'invoicing'),
1040
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1041 1041
                 'type' => 'text',
1042
-                'std'  => __( 'A note has been added to your invoice', 'invoicing' ),
1042
+                'std'  => __('A note has been added to your invoice', 'invoicing'),
1043 1043
                 'size' => 'large'
1044 1044
             ),
1045 1045
         ),
1046 1046
         'overdue' => array(
1047 1047
             'email_overdue_header' => array(
1048 1048
                 'id'   => 'email_overdue_header',
1049
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1050
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1049
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1050
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1051 1051
                 'type' => 'header',
1052 1052
             ),
1053 1053
             'email_overdue_active' => array(
1054 1054
                 'id'   => 'email_overdue_active',
1055
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1056
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1055
+                'name' => __('Enable/Disable', 'invoicing'),
1056
+                'desc' => __('Enable this email notification', 'invoicing'),
1057 1057
                 'type' => 'checkbox',
1058 1058
                 'std'  => 1
1059 1059
             ),
1060 1060
             'email_due_reminder_days' => array(
1061 1061
                 'id'        => 'email_due_reminder_days',
1062
-                'name'      => __( 'When to Send', 'sliced-invoices' ),
1063
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1062
+                'name'      => __('When to Send', 'sliced-invoices'),
1063
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1064 1064
                 'default'   => '',
1065 1065
                 'type'      => 'multicheck',
1066 1066
                 'options'   => $overdue_days_options,
1067 1067
             ),
1068 1068
             'email_overdue_subject' => array(
1069 1069
                 'id'   => 'email_overdue_subject',
1070
-                'name' => __( 'Subject', 'invoicing' ),
1071
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1070
+                'name' => __('Subject', 'invoicing'),
1071
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1072 1072
                 'type' => 'text',
1073
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1073
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1074 1074
                 'size' => 'large'
1075 1075
             ),
1076 1076
             'email_overdue_heading' => array(
1077 1077
                 'id'   => 'email_overdue_heading',
1078
-                'name' => __( 'Email Heading', 'invoicing' ),
1079
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1078
+                'name' => __('Email Heading', 'invoicing'),
1079
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1080 1080
                 'type' => 'text',
1081
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1081
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1082 1082
                 'size' => 'large'
1083 1083
             ),
1084 1084
             'email_overdue_body' => array(
1085 1085
                 'id'   => 'email_overdue_body',
1086
-                'name' => __( 'Email Content', 'invoicing' ),
1087
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1086
+                'name' => __('Email Content', 'invoicing'),
1087
+                'desc' => __('The content of the email.', 'invoicing'),
1088 1088
                 'type' => 'rich_editor',
1089
-                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ),
1089
+                'std'  => __('<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing'),
1090 1090
                 'class' => 'large',
1091 1091
                 'size'  => 10,
1092 1092
             ),
1093 1093
         ),
1094 1094
     );
1095 1095
 
1096
-    return apply_filters( 'wpinv_get_emails', $emails );
1096
+    return apply_filters('wpinv_get_emails', $emails);
1097 1097
 }
1098 1098
 
1099
-function wpinv_settings_emails( $settings = array() ) {
1099
+function wpinv_settings_emails($settings = array()) {
1100 1100
     $emails = wpinv_get_emails();
1101 1101
     
1102
-    if ( !empty( $emails ) ) {
1103
-        foreach ( $emails as $key => $email ) {
1102
+    if (!empty($emails)) {
1103
+        foreach ($emails as $key => $email) {
1104 1104
             $settings[$key] = $email;
1105 1105
         }
1106 1106
     }
1107 1107
     
1108
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1108
+    return apply_filters('wpinv_settings_get_emails', $settings);
1109 1109
 }
1110
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1110
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1111 1111
 
1112
-function wpinv_settings_sections_emails( $settings ) {
1112
+function wpinv_settings_sections_emails($settings) {
1113 1113
     $emails = wpinv_get_emails();
1114 1114
     
1115 1115
     if (!empty($emails)) {
1116
-        foreach  ($emails as $key => $email) {
1117
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1116
+        foreach ($emails as $key => $email) {
1117
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1118 1118
         }
1119 1119
     }
1120 1120
     
1121 1121
     return $settings;    
1122 1122
 }
1123
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1123
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1124 1124
 
1125
-function wpinv_email_is_enabled( $email_type ) {
1125
+function wpinv_email_is_enabled($email_type) {
1126 1126
     $emails = wpinv_get_emails();
1127
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false;
1127
+    $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 1) ? true : false;
1128 1128
 
1129
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1129
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1130 1130
 }
1131 1131
 
1132
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1133
-    switch ( $email_type ) {
1132
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1133
+    switch ($email_type) {
1134 1134
         case 'new_invoice':
1135 1135
         case 'cancelled_invoice':
1136 1136
         case 'failed_invoice':
1137 1137
             $recipient  = wpinv_get_admin_email();
1138 1138
         break;
1139 1139
         default:
1140
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1141
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1140
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1141
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1142 1142
         break;
1143 1143
     }
1144 1144
     
1145
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1145
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1146 1146
 }
1147 1147
 
1148
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1149
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1148
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1149
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1150 1150
     
1151
-    $subject    = wpinv_email_format_text( $subject );
1151
+    $subject    = wpinv_email_format_text($subject);
1152 1152
     
1153
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1153
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1154 1154
 }
1155 1155
 
1156
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1157
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1156
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1157
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1158 1158
     
1159
-    $email_heading = wpinv_email_format_text( $email_heading );
1159
+    $email_heading = wpinv_email_format_text($email_heading);
1160 1160
     
1161
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1161
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1162 1162
 }
1163 1163
 
1164
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1165
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1164
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1165
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1166 1166
     
1167
-    $content    = wpinv_email_format_text( $content );
1167
+    $content    = wpinv_email_format_text($content);
1168 1168
     
1169
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1169
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1170 1170
 }
1171 1171
 
1172
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1172
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1173 1173
     $from_name = wpinv_mail_get_from_address();
1174 1174
     $from_email = wpinv_mail_get_from_address();
1175 1175
     
1176
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1176
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1177 1177
     
1178
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1179
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1178
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1179
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1180 1180
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1181 1181
     
1182
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1182
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1183 1183
 }
1184 1184
 
1185
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1185
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1186 1186
     $attachments = array();
1187 1187
     
1188
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1188
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1189 1189
 }
1190 1190
 
1191 1191
 function wpinv_email_global_vars() {
@@ -1202,73 +1202,73 @@  discard block
 block discarded – undo
1202 1202
     $replace['sitename']    = $blogname;
1203 1203
     $replace['site-title']  = $blogname;
1204 1204
     
1205
-    return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) );
1205
+    return apply_filters('wpinv_email_global_vars', array($search, $replace));
1206 1206
 }
1207 1207
 
1208
-function wpinv_email_format_text( $content ) {
1208
+function wpinv_email_format_text($content) {
1209 1209
     global $wpinv_email_search, $wpinv_email_replace;
1210 1210
     
1211
-    if ( empty( $wpinv_email_search ) ) {
1211
+    if (empty($wpinv_email_search)) {
1212 1212
         $wpinv_email_search = array();
1213 1213
     }
1214 1214
     
1215
-    if ( empty( $wpinv_email_replace ) ) {
1215
+    if (empty($wpinv_email_replace)) {
1216 1216
         $wpinv_email_replace = array();
1217 1217
     }
1218 1218
     
1219
-    $wpinv_email_search     = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search );
1220
-    $wpinv_email_replace    = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace );
1219
+    $wpinv_email_search     = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search);
1220
+    $wpinv_email_replace    = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace);
1221 1221
     
1222 1222
     $global_vars    = wpinv_email_global_vars();
1223 1223
     
1224
-    $search         = array_merge( $global_vars[0], $wpinv_email_search );
1225
-    $replace        = array_merge( $global_vars[1], $wpinv_email_replace );
1224
+    $search         = array_merge($global_vars[0], $wpinv_email_search);
1225
+    $replace        = array_merge($global_vars[1], $wpinv_email_replace);
1226 1226
     
1227
-    if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) {
1227
+    if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) {
1228 1228
         return  $content;
1229 1229
     }
1230 1230
         
1231
-    return str_replace( $search, $replace, $content );
1231
+    return str_replace($search, $replace, $content);
1232 1232
 }
1233 1233
 
1234
-function wpinv_email_style_body( $content ) {
1234
+function wpinv_email_style_body($content) {
1235 1235
     // make sure we only inline CSS for html emails
1236
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1236
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1237 1237
         ob_start();
1238
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1239
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1238
+        wpinv_get_template('emails/wpinv-email-styles.php');
1239
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1240 1240
         
1241 1241
         // apply CSS styles inline for picky email clients
1242 1242
         try {
1243
-            $emogrifier = new Emogrifier( $content, $css );
1243
+            $emogrifier = new Emogrifier($content, $css);
1244 1244
             $content    = $emogrifier->emogrify();
1245
-        } catch ( Exception $e ) {
1246
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1245
+        } catch (Exception $e) {
1246
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1247 1247
         }
1248 1248
     }
1249 1249
     return $content;
1250 1250
 }
1251 1251
 
1252
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1253
-    wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1252
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1253
+    wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1254 1254
 }
1255 1255
 
1256 1256
 /**
1257 1257
  * Get the email footer.
1258 1258
  */
1259
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1260
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1259
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1260
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1261 1261
 }
1262 1262
 
1263
-function wpinv_email_wrap_message( $message ) {
1263
+function wpinv_email_wrap_message($message) {
1264 1264
     // Buffer
1265 1265
     ob_start();
1266 1266
 
1267
-    do_action( 'wpinv_email_header' );
1267
+    do_action('wpinv_email_header');
1268 1268
 
1269
-    echo wpautop( wptexturize( $message ) );
1269
+    echo wpautop(wptexturize($message));
1270 1270
 
1271
-    do_action( 'wpinv_email_footer' );
1271
+    do_action('wpinv_email_footer');
1272 1272
 
1273 1273
     // Get contents
1274 1274
     $message = ob_get_clean();
@@ -1276,86 +1276,86 @@  discard block
 block discarded – undo
1276 1276
     return $message;
1277 1277
 }
1278 1278
 
1279
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1280
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1279
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1280
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1281 1281
 }
1282 1282
 
1283
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1284
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1283
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1284
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1285 1285
 }
1286 1286
 
1287
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1288
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1287
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1288
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1289 1289
 }
1290 1290
 
1291
-function wpinv_send_customer_invoice( $data = array() ) {
1292
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1291
+function wpinv_send_customer_invoice($data = array()) {
1292
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1293 1293
     
1294
-    if ( empty( $invoice_id ) ) {
1294
+    if (empty($invoice_id)) {
1295 1295
         return;
1296 1296
     }
1297 1297
 
1298
-    if ( !current_user_can( 'manage_options' ) ) {
1299
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1298
+    if (!current_user_can('manage_options')) {
1299
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1300 1300
     }
1301 1301
     
1302
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1302
+    $sent = wpinv_user_invoice_notification($invoice_id);
1303 1303
     
1304 1304
     $status = $sent ? 'email_sent' : 'email_fail';
1305 1305
     
1306
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1307
-    wp_redirect( $redirect );
1306
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1307
+    wp_redirect($redirect);
1308 1308
     exit;
1309 1309
 }
1310
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1310
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1311 1311
 
1312
-function wpinv_send_overdue_reminder( $data = array() ) {
1313
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1312
+function wpinv_send_overdue_reminder($data = array()) {
1313
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1314 1314
     
1315
-    if ( empty( $invoice_id ) ) {
1315
+    if (empty($invoice_id)) {
1316 1316
         return;
1317 1317
     }
1318 1318
 
1319
-    if ( !current_user_can( 'manage_options' ) ) {
1320
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1319
+    if (!current_user_can('manage_options')) {
1320
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1321 1321
     }
1322 1322
     
1323
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1323
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1324 1324
     
1325 1325
     $status = $sent ? 'email_sent' : 'email_fail';
1326 1326
     
1327
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1328
-    wp_redirect( $redirect );
1327
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1328
+    wp_redirect($redirect);
1329 1329
     exit;
1330 1330
 }
1331
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1331
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1332 1332
 
1333
-function wpinv_send_customer_note_email( $data ) {
1334
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1333
+function wpinv_send_customer_note_email($data) {
1334
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1335 1335
     
1336
-    if ( empty( $invoice_id ) ) {
1336
+    if (empty($invoice_id)) {
1337 1337
         return;
1338 1338
     }
1339 1339
     
1340
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1340
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1341 1341
 }
1342
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1342
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1343 1343
 
1344
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1345
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1346
-        $date_format = get_option( 'date_format' );
1347
-        $time_format = get_option( 'time_format' );
1344
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1345
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1346
+        $date_format = get_option('date_format');
1347
+        $time_format = get_option('time_format');
1348 1348
         ?>
1349 1349
         <div id="wpinv-email-notes">
1350
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1350
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1351 1351
             <ol class="wpinv-notes-lists">
1352 1352
         <?php
1353
-        foreach ( $invoice_notes as $note ) {
1354
-            $note_time = strtotime( $note->comment_date );
1353
+        foreach ($invoice_notes as $note) {
1354
+            $note_time = strtotime($note->comment_date);
1355 1355
             ?>
1356 1356
             <li class="comment wpinv-note">
1357
-            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
1358
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1357
+            <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p>
1358
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1359 1359
             </li>
1360 1360
             <?php
1361 1361
         }
@@ -1364,21 +1364,21 @@  discard block
 block discarded – undo
1364 1364
         <?php
1365 1365
     }
1366 1366
 }
1367
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1367
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1368 1368
 
1369 1369
 function wpinv_email_payment_reminders() {    
1370 1370
     global $wpi_auto_reminder;
1371
-    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1371
+    if (!wpinv_get_option('email_overdue_active')) {
1372 1372
         return;
1373 1373
     }
1374 1374
     
1375
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1376
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1375
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1376
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : '';
1377 1377
         
1378
-        if ( empty( $reminder_days ) ) {
1378
+        if (empty($reminder_days)) {
1379 1379
             return;
1380 1380
         }
1381
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1381
+        $reminder_days = array_unique(array_map('absint', $reminder_days));
1382 1382
         
1383 1383
         $args = array(
1384 1384
             'post_type'     => 'wpi_invoice',
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
             'meta_query'    => array(
1389 1389
                 array(
1390 1390
                     'key'       =>  '_wpinv_due_date',
1391
-                    'value'     =>  array( '', 'none' ),
1391
+                    'value'     =>  array('', 'none'),
1392 1392
                     'compare'   =>  'NOT IN',
1393 1393
                 )
1394 1394
             ),
@@ -1397,64 +1397,64 @@  discard block
 block discarded – undo
1397 1397
             'order'         => 'ASC',
1398 1398
         );
1399 1399
         
1400
-        $invoices = get_posts( $args );
1400
+        $invoices = get_posts($args);
1401 1401
         
1402
-        if ( empty( $invoices ) ) {
1402
+        if (empty($invoices)) {
1403 1403
             return;
1404 1404
         }
1405 1405
         
1406
-        $date_to_send   = array();
1406
+        $date_to_send = array();
1407 1407
         
1408
-        foreach ( $invoices as $id ) {
1409
-            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1408
+        foreach ($invoices as $id) {
1409
+            $due_date = get_post_meta($id, '_wpinv_due_date', true);
1410 1410
             
1411
-            foreach ( $reminder_days as $key => $days ) {
1412
-                if ( $days !== '' ) {
1413
-                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1411
+            foreach ($reminder_days as $key => $days) {
1412
+                if ($days !== '') {
1413
+                    $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS));
1414 1414
                 }
1415 1415
             }
1416 1416
         }
1417 1417
 
1418
-        $today              = date_i18n( 'Y-m-d' );
1418
+        $today              = date_i18n('Y-m-d');
1419 1419
         $wpi_auto_reminder  = true;
1420 1420
 
1421
-        foreach ( $date_to_send as $id => $values ) {
1422
-            if ( in_array( $today, $values ) ) {
1423
-                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1421
+        foreach ($date_to_send as $id => $values) {
1422
+            if (in_array($today, $values)) {
1423
+                $sent = get_post_meta($id, '_wpinv_reminder_sent', true);
1424 1424
 
1425
-                if ( isset( $sent ) && !empty( $sent ) ) {
1426
-                    if ( !in_array( $today, $sent ) ) {
1427
-                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1425
+                if (isset($sent) && !empty($sent)) {
1426
+                    if (!in_array($today, $sent)) {
1427
+                        do_action('wpinv_send_payment_reminder_notification', $id);
1428 1428
                     }
1429 1429
                 } else {
1430
-                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1430
+                    do_action('wpinv_send_payment_reminder_notification', $id);
1431 1431
                 }
1432 1432
             }
1433 1433
         }
1434 1434
         
1435
-        $wpi_auto_reminder  = false;
1435
+        $wpi_auto_reminder = false;
1436 1436
     }
1437 1437
 }
1438 1438
 
1439
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1439
+function wpinv_send_payment_reminder_notification($invoice_id) {
1440 1440
     global $wpinv_email_search, $wpinv_email_replace;
1441 1441
     
1442 1442
     $email_type = 'overdue';
1443
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1443
+    if (!wpinv_email_is_enabled($email_type)) {
1444 1444
         return false;
1445 1445
     }
1446 1446
     
1447
-    $invoice    = wpinv_get_invoice( $invoice_id );
1448
-    if ( empty( $invoice ) ) {
1447
+    $invoice = wpinv_get_invoice($invoice_id);
1448
+    if (empty($invoice)) {
1449 1449
         return false;
1450 1450
     }
1451 1451
     
1452
-    if ( !$invoice->needs_payment() ) {
1452
+    if (!$invoice->needs_payment()) {
1453 1453
         return false;
1454 1454
     }
1455 1455
     
1456
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1457
-    if ( !is_email( $recipient ) ) {
1456
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1457
+    if (!is_email($recipient)) {
1458 1458
         return false;
1459 1459
     }
1460 1460
         
@@ -1470,70 +1470,70 @@  discard block
 block discarded – undo
1470 1470
     $replace                    = array();
1471 1471
     $replace['full_name']       = $invoice->get_user_full_name();
1472 1472
     $replace['invoice_number']  = $invoice->get_number();
1473
-    $replace['invoice_due_date']= $invoice->get_due_date( true );
1474
-    $replace['invoice_total']   = $invoice->get_total( true );
1475
-    $replace['invoice_link']    = $invoice->get_view_url( true );
1476
-    $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true );
1477
-    $replace['is_was']          = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' );
1473
+    $replace['invoice_due_date'] = $invoice->get_due_date(true);
1474
+    $replace['invoice_total']   = $invoice->get_total(true);
1475
+    $replace['invoice_link']    = $invoice->get_view_url(true);
1476
+    $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true);
1477
+    $replace['is_was']          = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing');
1478 1478
 
1479 1479
     $wpinv_email_search         = $search;
1480 1480
     $wpinv_email_replace        = $replace;
1481 1481
     
1482
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1483
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1484
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1485
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1482
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1483
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1484
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1485
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1486 1486
     
1487
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1487
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1488 1488
     
1489
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1489
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1490 1490
             'invoice'       => $invoice,
1491 1491
             'email_type'    => $email_type,
1492 1492
             'email_heading' => $email_heading,
1493 1493
             'sent_to_admin' => false,
1494 1494
             'plain_text'    => false,
1495 1495
             'message_body'  => $message_body
1496
-        ) );
1496
+        ));
1497 1497
         
1498
-    $content        = wpinv_email_format_text( $content );
1498
+    $content = wpinv_email_format_text($content);
1499 1499
 
1500
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1501
-    if ( $sent ) {
1502
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1500
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1501
+    if ($sent) {
1502
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1503 1503
     }
1504 1504
         
1505 1505
     return $sent;
1506 1506
 }
1507
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1507
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1508 1508
 
1509
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1509
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1510 1510
     global $wpi_auto_reminder;
1511 1511
     
1512
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1512
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1513 1513
     
1514
-    if ( empty( $sent ) ) {
1514
+    if (empty($sent)) {
1515 1515
         $sent = array();
1516 1516
     }
1517
-    $sent[] = date_i18n( 'Y-m-d' );
1517
+    $sent[] = date_i18n('Y-m-d');
1518 1518
     
1519
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1519
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1520 1520
     
1521
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1522
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1523
-        $invoice->add_note( $note, false, false, true );
1521
+    if ($wpi_auto_reminder) { // Auto reminder note.
1522
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1523
+        $invoice->add_note($note, false, false, true);
1524 1524
     } else { // Menual reminder note.
1525
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1526
-        $invoice->add_note( $note );
1525
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1526
+        $invoice->add_note($note);
1527 1527
     }
1528 1528
 }
1529
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1529
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1530 1530
 
1531
-function wpinv_email_before_note_details( $invoice, $email_type, $sent_to_admin, $customer_note ) {
1532
-    if("wpi_invoice" === $invoice->post_type && !empty($customer_note)){
1531
+function wpinv_email_before_note_details($invoice, $email_type, $sent_to_admin, $customer_note) {
1532
+    if ("wpi_invoice" === $invoice->post_type && !empty($customer_note)) {
1533 1533
         $before_note = '';
1534
-        $before_note .= __( 'Hello, a note has just been added to your invoice:', 'invoicing' );
1535
-        $before_note .= '<blockquote class="wpinv-note">'.wpautop( wptexturize( $customer_note ) ).'</blockquote>';
1536
-        $before_note .= __( 'For your reference, your invoice details are shown below.', 'invoicing' );
1534
+        $before_note .= __('Hello, a note has just been added to your invoice:', 'invoicing');
1535
+        $before_note .= '<blockquote class="wpinv-note">' . wpautop(wptexturize($customer_note)) . '</blockquote>';
1536
+        $before_note .= __('For your reference, your invoice details are shown below.', 'invoicing');
1537 1537
         echo $before_note;
1538 1538
     }
1539 1539
 }
1540 1540
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  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
 function wpinv_get_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array)apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = 'gd_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,99 +189,99 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
     
216
-    $start_timestamp        = strtotime( $meta['start'] );
216
+    $start_timestamp        = strtotime($meta['start']);
217 217
 
218
-    if ( !empty( $meta['start'] ) ) {
219
-        $meta['start']      = date( 'Y-m-d H:i:s', $start_timestamp );
218
+    if (!empty($meta['start'])) {
219
+        $meta['start']      = date('Y-m-d H:i:s', $start_timestamp);
220 220
     }
221 221
         
222
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
222
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
223 223
         $meta['amount'] = 100;
224 224
     }
225 225
 
226
-    if ( !empty( $meta['expiration'] ) ) {
227
-        $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) );
228
-        $end_timestamp      = strtotime( $meta['expiration'] );
226
+    if (!empty($meta['expiration'])) {
227
+        $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59'));
228
+        $end_timestamp      = strtotime($meta['expiration']);
229 229
 
230
-        if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) {
230
+        if (!empty($meta['start']) && $start_timestamp > $end_timestamp) {
231 231
             $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date.
232 232
         }
233 233
     }
234 234
     
235
-    if ( $meta['uses'] === false ) {
236
-        unset( $meta['uses'] );
235
+    if ($meta['uses'] === false) {
236
+        unset($meta['uses']);
237 237
     }
238 238
     
239
-    if ( ! empty( $meta['items'] ) ) {
240
-        foreach ( $meta['items'] as $key => $item ) {
241
-            if ( 0 === intval( $item ) ) {
242
-                unset( $meta['items'][ $key ] );
239
+    if (!empty($meta['items'])) {
240
+        foreach ($meta['items'] as $key => $item) {
241
+            if (0 === intval($item)) {
242
+                unset($meta['items'][$key]);
243 243
             }
244 244
         }
245 245
     }
246 246
     
247
-    if ( ! empty( $meta['excluded_items'] ) ) {
248
-        foreach ( $meta['excluded_items'] as $key => $item ) {
249
-            if ( 0 === intval( $item ) ) {
250
-                unset( $meta['excluded_items'][ $key ] );
247
+    if (!empty($meta['excluded_items'])) {
248
+        foreach ($meta['excluded_items'] as $key => $item) {
249
+            if (0 === intval($item)) {
250
+                unset($meta['excluded_items'][$key]);
251 251
             }
252 252
         }
253 253
     }
254 254
     
255
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
255
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
256 256
     
257
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
257
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
258 258
     
259
-    foreach( $meta as $key => $value ) {
260
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
259
+    foreach ($meta as $key => $value) {
260
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
261 261
     }
262 262
     
263
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
263
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
264 264
     
265 265
     return $post_id;
266 266
 }
267 267
 
268
-function wpinv_remove_discount( $discount_id = 0 ) {
269
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
268
+function wpinv_remove_discount($discount_id = 0) {
269
+    do_action('wpinv_pre_delete_discount', $discount_id);
270 270
 
271
-    wp_delete_post( $discount_id, true );
271
+    wp_delete_post($discount_id, true);
272 272
 
273
-    do_action( 'wpinv_post_delete_discount', $discount_id );
273
+    do_action('wpinv_post_delete_discount', $discount_id);
274 274
 }
275 275
 
276
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
277
-    $discount = wpinv_get_discount(  $code_id );
276
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
277
+    $discount = wpinv_get_discount($code_id);
278 278
 
279
-    if ( $discount ) {
280
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
279
+    if ($discount) {
280
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
281 281
 
282
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
282
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
283 283
 
284
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
284
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
285 285
 
286 286
         return true;
287 287
     }
@@ -289,173 +289,173 @@  discard block
 block discarded – undo
289 289
     return false;
290 290
 }
291 291
 
292
-function wpinv_discount_exists( $code_id ) {
293
-    if ( wpinv_get_discount(  $code_id ) ) {
292
+function wpinv_discount_exists($code_id) {
293
+    if (wpinv_get_discount($code_id)) {
294 294
         return true;
295 295
     }
296 296
 
297 297
     return false;
298 298
 }
299 299
 
300
-function wpinv_is_discount_active( $code_id = null ) {
301
-    $discount = wpinv_get_discount(  $code_id );
300
+function wpinv_is_discount_active($code_id = null) {
301
+    $discount = wpinv_get_discount($code_id);
302 302
     $return   = false;
303 303
 
304
-    if ( $discount ) {
305
-        if ( wpinv_is_discount_expired( $code_id ) ) {
306
-            if( defined( 'DOING_AJAX' ) ) {
307
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
304
+    if ($discount) {
305
+        if (wpinv_is_discount_expired($code_id)) {
306
+            if (defined('DOING_AJAX')) {
307
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
308 308
             }
309
-        } elseif ( $discount->post_status == 'publish' ) {
309
+        } elseif ($discount->post_status == 'publish') {
310 310
             $return = true;
311 311
         } else {
312
-            if( defined( 'DOING_AJAX' ) ) {
313
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
312
+            if (defined('DOING_AJAX')) {
313
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
314 314
             }
315 315
         }
316 316
     }
317 317
 
318
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
318
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
319 319
 }
320 320
 
321
-function wpinv_get_discount_code( $code_id = null ) {
322
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
321
+function wpinv_get_discount_code($code_id = null) {
322
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
323 323
 
324
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
324
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
325 325
 }
326 326
 
327
-function wpinv_get_discount_start_date( $code_id = null ) {
328
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
327
+function wpinv_get_discount_start_date($code_id = null) {
328
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
329 329
 
330
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
330
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
331 331
 }
332 332
 
333
-function wpinv_get_discount_expiration( $code_id = null ) {
334
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
333
+function wpinv_get_discount_expiration($code_id = null) {
334
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
335 335
 
336
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
336
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
337 337
 }
338 338
 
339
-function wpinv_get_discount_max_uses( $code_id = null ) {
340
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
339
+function wpinv_get_discount_max_uses($code_id = null) {
340
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
341 341
 
342
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
342
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
343 343
 }
344 344
 
345
-function wpinv_get_discount_uses( $code_id = null ) {
346
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
345
+function wpinv_get_discount_uses($code_id = null) {
346
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
347 347
 
348
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
348
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
349 349
 }
350 350
 
351
-function wpinv_get_discount_min_total( $code_id = null ) {
352
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
351
+function wpinv_get_discount_min_total($code_id = null) {
352
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
353 353
 
354
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
354
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
355 355
 }
356 356
 
357
-function wpinv_get_discount_max_total( $code_id = null ) {
358
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
357
+function wpinv_get_discount_max_total($code_id = null) {
358
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
359 359
 
360
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
360
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
361 361
 }
362 362
 
363
-function wpinv_get_discount_amount( $code_id = null ) {
364
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
363
+function wpinv_get_discount_amount($code_id = null) {
364
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
365 365
 
366
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
366
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
367 367
 }
368 368
 
369
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
370
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
369
+function wpinv_get_discount_type($code_id = null, $name = false) {
370
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
371 371
     
372
-    if ( $name ) {
373
-        $name = wpinv_get_discount_type_name( $type );
372
+    if ($name) {
373
+        $name = wpinv_get_discount_type_name($type);
374 374
         
375
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
375
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
376 376
     }
377 377
 
378
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
378
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
379 379
 }
380 380
 
381
-function wpinv_discount_status( $status ) {
382
-    switch( $status ){
381
+function wpinv_discount_status($status) {
382
+    switch ($status) {
383 383
         case 'expired' :
384
-            $name = __( 'Expired', 'invoicing' );
384
+            $name = __('Expired', 'invoicing');
385 385
             break;
386 386
         case 'publish' :
387 387
         case 'active' :
388
-            $name = __( 'Active', 'invoicing' );
388
+            $name = __('Active', 'invoicing');
389 389
             break;
390 390
         default :
391
-            $name = __( 'Inactive', 'invoicing' );
391
+            $name = __('Inactive', 'invoicing');
392 392
             break;
393 393
     }
394 394
     return $name;
395 395
 }
396 396
 
397
-function wpinv_get_discount_excluded_items( $code_id = null ) {
398
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
397
+function wpinv_get_discount_excluded_items($code_id = null) {
398
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
399 399
 
400
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
400
+    if (empty($excluded_items) || !is_array($excluded_items)) {
401 401
         $excluded_items = array();
402 402
     }
403 403
 
404
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
404
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
405 405
 }
406 406
 
407
-function wpinv_get_discount_item_reqs( $code_id = null ) {
408
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
407
+function wpinv_get_discount_item_reqs($code_id = null) {
408
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
409 409
 
410
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
410
+    if (empty($item_reqs) || !is_array($item_reqs)) {
411 411
         $item_reqs = array();
412 412
     }
413 413
 
414
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
414
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
415 415
 }
416 416
 
417
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
418
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
417
+function wpinv_get_discount_item_condition($code_id = 0) {
418
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
419 419
 }
420 420
 
421
-function wpinv_is_discount_not_global( $code_id = 0 ) {
422
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
421
+function wpinv_is_discount_not_global($code_id = 0) {
422
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
423 423
 }
424 424
 
425
-function wpinv_is_discount_expired( $code_id = null ) {
426
-    $discount = wpinv_get_discount(  $code_id );
425
+function wpinv_is_discount_expired($code_id = null) {
426
+    $discount = wpinv_get_discount($code_id);
427 427
     $return   = false;
428 428
 
429
-    if ( $discount ) {
430
-        $expiration = wpinv_get_discount_expiration( $code_id );
431
-        if ( $expiration ) {
432
-            $expiration = strtotime( $expiration );
433
-            if ( $expiration < current_time( 'timestamp' ) ) {
429
+    if ($discount) {
430
+        $expiration = wpinv_get_discount_expiration($code_id);
431
+        if ($expiration) {
432
+            $expiration = strtotime($expiration);
433
+            if ($expiration < current_time('timestamp')) {
434 434
                 // Discount is expired
435
-                wpinv_update_discount_status( $code_id, 'pending' );
435
+                wpinv_update_discount_status($code_id, 'pending');
436 436
                 $return = true;
437 437
             }
438 438
         }
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
441
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
442 442
 }
443 443
 
444
-function wpinv_is_discount_started( $code_id = null ) {
445
-    $discount = wpinv_get_discount(  $code_id );
444
+function wpinv_is_discount_started($code_id = null) {
445
+    $discount = wpinv_get_discount($code_id);
446 446
     $return   = false;
447 447
 
448
-    if ( $discount ) {
449
-        $start_date = wpinv_get_discount_start_date( $code_id );
448
+    if ($discount) {
449
+        $start_date = wpinv_get_discount_start_date($code_id);
450 450
 
451
-        if ( $start_date ) {
452
-            $start_date = strtotime( $start_date );
451
+        if ($start_date) {
452
+            $start_date = strtotime($start_date);
453 453
 
454
-            if ( $start_date < current_time( 'timestamp' ) ) {
454
+            if ($start_date < current_time('timestamp')) {
455 455
                 // Discount has past the start date
456 456
                 $return = true;
457 457
             } else {
458
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
458
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
459 459
             }
460 460
         } else {
461 461
             // No start date for this discount, so has to be true
@@ -463,159 +463,159 @@  discard block
 block discarded – undo
463 463
         }
464 464
     }
465 465
 
466
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
466
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
467 467
 }
468 468
 
469
-function wpinv_check_discount_dates( $code_id = null ) {
470
-    $discount = wpinv_get_discount(  $code_id );
469
+function wpinv_check_discount_dates($code_id = null) {
470
+    $discount = wpinv_get_discount($code_id);
471 471
     $return   = false;
472 472
 
473
-    if ( $discount ) {
474
-        $start_date = wpinv_get_discount_start_date( $code_id );
473
+    if ($discount) {
474
+        $start_date = wpinv_get_discount_start_date($code_id);
475 475
 
476
-        if ( $start_date ) {
477
-            $start_date = strtotime( $start_date );
476
+        if ($start_date) {
477
+            $start_date = strtotime($start_date);
478 478
 
479
-            if ( $start_date < current_time( 'timestamp' ) ) {
479
+            if ($start_date < current_time('timestamp')) {
480 480
                 // Discount has past the start date
481 481
                 $return = true;
482 482
             } else {
483
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
483
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
484 484
             }
485 485
         } else {
486 486
             // No start date for this discount, so has to be true
487 487
             $return = true;
488 488
         }
489 489
         
490
-        if ( $return ) {
491
-            $expiration = wpinv_get_discount_expiration( $code_id );
490
+        if ($return) {
491
+            $expiration = wpinv_get_discount_expiration($code_id);
492 492
             
493
-            if ( $expiration ) {
494
-                $expiration = strtotime( $expiration );
495
-                if ( $expiration < current_time( 'timestamp' ) ) {
493
+            if ($expiration) {
494
+                $expiration = strtotime($expiration);
495
+                if ($expiration < current_time('timestamp')) {
496 496
                     // Discount is expired
497
-                    wpinv_update_discount_status( $code_id, 'pending' );
497
+                    wpinv_update_discount_status($code_id, 'pending');
498 498
                     $return = true;
499 499
                 }
500 500
             }
501 501
         }
502 502
     }
503 503
     
504
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
504
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
505 505
 }
506 506
 
507
-function wpinv_is_discount_maxed_out( $code_id = null ) {
508
-    $discount = wpinv_get_discount(  $code_id );
507
+function wpinv_is_discount_maxed_out($code_id = null) {
508
+    $discount = wpinv_get_discount($code_id);
509 509
     $return   = false;
510 510
 
511
-    if ( $discount ) {
512
-        $uses = wpinv_get_discount_uses( $code_id );
511
+    if ($discount) {
512
+        $uses = wpinv_get_discount_uses($code_id);
513 513
         // Large number that will never be reached
514
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
514
+        $max_uses = wpinv_get_discount_max_uses($code_id);
515 515
         // Should never be greater than, but just in case
516
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
516
+        if ($uses >= $max_uses && !empty($max_uses)) {
517 517
             // Discount is maxed out
518
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
518
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
519 519
             $return = true;
520 520
         }
521 521
     }
522 522
 
523
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
523
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
524 524
 }
525 525
 
526
-function wpinv_discount_is_min_met( $code_id = null ) {
527
-    $discount = wpinv_get_discount( $code_id );
526
+function wpinv_discount_is_min_met($code_id = null) {
527
+    $discount = wpinv_get_discount($code_id);
528 528
     $return   = false;
529 529
 
530
-    if ( $discount ) {
531
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
532
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
530
+    if ($discount) {
531
+        $min         = (float)wpinv_get_discount_min_total($code_id);
532
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
533 533
 
534
-        if ( !$min > 0 || $cart_amount >= $min ) {
534
+        if (!$min > 0 || $cart_amount >= $min) {
535 535
             // Minimum has been met
536 536
             $return = true;
537 537
         } else {
538
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
538
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
539 539
         }
540 540
     }
541 541
 
542
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
542
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
543 543
 }
544 544
 
545
-function wpinv_discount_is_max_met( $code_id = null ) {
546
-    $discount = wpinv_get_discount( $code_id );
545
+function wpinv_discount_is_max_met($code_id = null) {
546
+    $discount = wpinv_get_discount($code_id);
547 547
     $return   = false;
548 548
 
549
-    if ( $discount ) {
550
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
551
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
549
+    if ($discount) {
550
+        $max         = (float)wpinv_get_discount_max_total($code_id);
551
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
552 552
 
553
-        if ( !$max > 0 || $cart_amount <= $max ) {
553
+        if (!$max > 0 || $cart_amount <= $max) {
554 554
             // Minimum has been met
555 555
             $return = true;
556 556
         } else {
557
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
557
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
558 558
         }
559 559
     }
560 560
 
561
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
561
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
562 562
 }
563 563
 
564
-function wpinv_discount_is_single_use( $code_id = 0 ) {
565
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
566
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
564
+function wpinv_discount_is_single_use($code_id = 0) {
565
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
566
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
567 567
 }
568 568
 
569
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
570
-    if ( $code ) {
571
-        $discount = wpinv_get_discount_by_code( $code_id );
569
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
570
+    if ($code) {
571
+        $discount = wpinv_get_discount_by_code($code_id);
572 572
         
573
-        if ( !empty( $discount ) ) {
573
+        if (!empty($discount)) {
574 574
             $code_id = $discount->ID;
575 575
         }
576 576
     }
577 577
     
578
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
578
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
579 579
     
580
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
580
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
581 581
 }
582 582
 
583
-function wpinv_discount_item_reqs_met( $code_id = null ) {
584
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
585
-    $condition    = wpinv_get_discount_item_condition( $code_id );
586
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
583
+function wpinv_discount_item_reqs_met($code_id = null) {
584
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
585
+    $condition    = wpinv_get_discount_item_condition($code_id);
586
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
587 587
     $cart_items   = wpinv_get_cart_contents();
588
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
588
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
589 589
     $ret          = false;
590 590
 
591
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
591
+    if (empty($item_reqs) && empty($excluded_ps)) {
592 592
         $ret = true;
593 593
     }
594 594
 
595 595
     // Normalize our data for item requirements, exclusions and cart data
596 596
     // First absint the items, then sort, and reset the array keys
597
-    $item_reqs = array_map( 'absint', $item_reqs );
598
-    asort( $item_reqs );
599
-    $item_reqs = array_values( $item_reqs );
597
+    $item_reqs = array_map('absint', $item_reqs);
598
+    asort($item_reqs);
599
+    $item_reqs = array_values($item_reqs);
600 600
 
601
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
602
-    asort( $excluded_ps );
603
-    $excluded_ps  = array_values( $excluded_ps );
601
+    $excluded_ps  = array_map('absint', $excluded_ps);
602
+    asort($excluded_ps);
603
+    $excluded_ps  = array_values($excluded_ps);
604 604
 
605
-    $cart_ids     = array_map( 'absint', $cart_ids );
606
-    asort( $cart_ids );
607
-    $cart_ids     = array_values( $cart_ids );
605
+    $cart_ids     = array_map('absint', $cart_ids);
606
+    asort($cart_ids);
607
+    $cart_ids     = array_values($cart_ids);
608 608
 
609 609
     // Ensure we have requirements before proceeding
610
-    if ( !$ret && ! empty( $item_reqs ) ) {
611
-        switch( $condition ) {
610
+    if (!$ret && !empty($item_reqs)) {
611
+        switch ($condition) {
612 612
             case 'all' :
613 613
                 // Default back to true
614 614
                 $ret = true;
615 615
 
616
-                foreach ( $item_reqs as $item_id ) {
617
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
618
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
616
+                foreach ($item_reqs as $item_id) {
617
+                    if (!wpinv_item_in_cart($item_id)) {
618
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
619 619
                         $ret = false;
620 620
                         break;
621 621
                     }
@@ -624,15 +624,15 @@  discard block
 block discarded – undo
624 624
                 break;
625 625
 
626 626
             default : // Any
627
-                foreach ( $item_reqs as $item_id ) {
628
-                    if ( wpinv_item_in_cart( $item_id ) ) {
627
+                foreach ($item_reqs as $item_id) {
628
+                    if (wpinv_item_in_cart($item_id)) {
629 629
                         $ret = true;
630 630
                         break;
631 631
                     }
632 632
                 }
633 633
 
634
-                if( ! $ret ) {
635
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
634
+                if (!$ret) {
635
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
636 636
                 }
637 637
 
638 638
                 break;
@@ -641,68 +641,68 @@  discard block
 block discarded – undo
641 641
         $ret = true;
642 642
     }
643 643
 
644
-    if( ! empty( $excluded_ps ) ) {
644
+    if (!empty($excluded_ps)) {
645 645
         // Check that there are items other than excluded ones in the cart
646
-        if( $cart_ids == $excluded_ps ) {
647
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
646
+        if ($cart_ids == $excluded_ps) {
647
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
648 648
             $ret = false;
649 649
         }
650 650
     }
651 651
 
652
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
652
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
653 653
 }
654 654
 
655
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
655
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
656 656
     global $wpi_checkout_id;
657 657
     
658 658
     $return = false;
659 659
 
660
-    if ( empty( $code_id ) ) {
661
-        $code_id = wpinv_get_discount_id_by_code( $code );
660
+    if (empty($code_id)) {
661
+        $code_id = wpinv_get_discount_id_by_code($code);
662 662
         
663
-        if( empty( $code_id ) ) {
663
+        if (empty($code_id)) {
664 664
             return false; // No discount was found
665 665
         }
666 666
     }
667 667
 
668
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
668
+    if (wpinv_discount_is_single_use($code_id)) {
669 669
         $payments = array();
670 670
 
671 671
         $user_id = 0;
672
-        if ( is_int( $user ) ) {
672
+        if (is_int($user)) {
673 673
             $user_id = $user;
674
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
674
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
675 675
             $user_id = $user_data->ID;
676
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
676
+        } else if ($user_data = get_user_by('login', $user)) {
677 677
             $user_id = $user_data->ID;
678 678
         }
679 679
 
680
-        if ( !$user_id ) {
681
-            $query    = array( 'user' => $user_id, 'limit' => false );
682
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching email
680
+        if (!$user_id) {
681
+            $query    = array('user' => $user_id, 'limit' => false);
682
+            $payments = wpinv_get_invoices($query); // Get all payments with matching email
683 683
         }
684 684
 
685
-        if ( $payments ) {
686
-            foreach ( $payments as $payment ) {
687
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
685
+        if ($payments) {
686
+            foreach ($payments as $payment) {
687
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
688 688
                     continue;
689 689
                 }
690 690
 
691 691
                 // Don't count discount used for current invoice chekcout.
692
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
692
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
693 693
                     continue;
694 694
                 }
695 695
 
696
-                $discounts = $payment->get_discounts( true );
697
-                if ( empty( $discounts ) ) {
696
+                $discounts = $payment->get_discounts(true);
697
+                if (empty($discounts)) {
698 698
                     continue;
699 699
                 }
700 700
 
701
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
701
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
702 702
 
703
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
704
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
705
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
703
+                if (!empty($discounts) && is_array($discounts)) {
704
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
705
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
706 706
                         $return = true;
707 707
                         break;
708 708
                     }
@@ -711,61 +711,61 @@  discard block
 block discarded – undo
711 711
         }
712 712
     }
713 713
 
714
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
714
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
715 715
 }
716 716
 
717
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
717
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
718 718
     $return      = false;
719
-    $discount_id = wpinv_get_discount_id_by_code( $code );
720
-    $user        = trim( $user );
719
+    $discount_id = wpinv_get_discount_id_by_code($code);
720
+    $user        = trim($user);
721 721
 
722
-    if ( wpinv_get_cart_contents() ) {
723
-        if ( $discount_id ) {
722
+    if (wpinv_get_cart_contents()) {
723
+        if ($discount_id) {
724 724
             if (
725
-                wpinv_is_discount_active( $discount_id ) &&
726
-                wpinv_check_discount_dates( $discount_id ) &&
727
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
728
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
729
-                wpinv_discount_is_min_met( $discount_id ) &&
730
-                wpinv_discount_is_max_met( $discount_id ) &&
731
-                wpinv_discount_item_reqs_met( $discount_id )
725
+                wpinv_is_discount_active($discount_id) &&
726
+                wpinv_check_discount_dates($discount_id) &&
727
+                !wpinv_is_discount_maxed_out($discount_id) &&
728
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
729
+                wpinv_discount_is_min_met($discount_id) &&
730
+                wpinv_discount_is_max_met($discount_id) &&
731
+                wpinv_discount_item_reqs_met($discount_id)
732 732
             ) {
733 733
                 $return = true;
734 734
             }
735
-        } elseif( $set_error ) {
736
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
735
+        } elseif ($set_error) {
736
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
737 737
         }
738 738
     }
739 739
 
740
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
740
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
741 741
 }
742 742
 
743
-function wpinv_get_discount_id_by_code( $code ) {
744
-    $discount = wpinv_get_discount_by_code( $code );
745
-    if( $discount ) {
743
+function wpinv_get_discount_id_by_code($code) {
744
+    $discount = wpinv_get_discount_by_code($code);
745
+    if ($discount) {
746 746
         return $discount->ID;
747 747
     }
748 748
     return false;
749 749
 }
750 750
 
751
-function wpinv_get_discounted_amount( $code, $base_price ) {
751
+function wpinv_get_discounted_amount($code, $base_price) {
752 752
     $amount      = $base_price;
753
-    $discount_id = wpinv_get_discount_id_by_code( $code );
753
+    $discount_id = wpinv_get_discount_id_by_code($code);
754 754
 
755
-    if( $discount_id ) {
756
-        $type        = wpinv_get_discount_type( $discount_id );
757
-        $rate        = wpinv_get_discount_amount( $discount_id );
755
+    if ($discount_id) {
756
+        $type        = wpinv_get_discount_type($discount_id);
757
+        $rate        = wpinv_get_discount_amount($discount_id);
758 758
 
759
-        if ( $type == 'flat' ) {
759
+        if ($type == 'flat') {
760 760
             // Set amount
761 761
             $amount = $base_price - $rate;
762
-            if ( $amount < 0 ) {
762
+            if ($amount < 0) {
763 763
                 $amount = 0;
764 764
             }
765 765
 
766 766
         } else {
767 767
             // Percentage discount
768
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
768
+            $amount = $base_price - ($base_price * ($rate / 100));
769 769
         }
770 770
 
771 771
     } else {
@@ -774,108 +774,108 @@  discard block
 block discarded – undo
774 774
 
775 775
     }
776 776
 
777
-    return apply_filters( 'wpinv_discounted_amount', $amount );
777
+    return apply_filters('wpinv_discounted_amount', $amount);
778 778
 }
779 779
 
780
-function wpinv_increase_discount_usage( $code ) {
780
+function wpinv_increase_discount_usage($code) {
781 781
 
782
-    $id   = wpinv_get_discount_id_by_code( $code );
783
-    $uses = wpinv_get_discount_uses( $id );
782
+    $id   = wpinv_get_discount_id_by_code($code);
783
+    $uses = wpinv_get_discount_uses($id);
784 784
 
785
-    if ( $uses ) {
785
+    if ($uses) {
786 786
         $uses++;
787 787
     } else {
788 788
         $uses = 1;
789 789
     }
790 790
 
791
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
791
+    update_post_meta($id, '_wpi_discount_uses', $uses);
792 792
 
793
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
793
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
794 794
 
795 795
     return $uses;
796 796
 
797 797
 }
798 798
 
799
-function wpinv_decrease_discount_usage( $code ) {
799
+function wpinv_decrease_discount_usage($code) {
800 800
 
801
-    $id   = wpinv_get_discount_id_by_code( $code );
802
-    $uses = wpinv_get_discount_uses( $id );
801
+    $id   = wpinv_get_discount_id_by_code($code);
802
+    $uses = wpinv_get_discount_uses($id);
803 803
 
804
-    if ( $uses ) {
804
+    if ($uses) {
805 805
         $uses--;
806 806
     }
807 807
 
808
-    if ( $uses < 0 ) {
808
+    if ($uses < 0) {
809 809
         $uses = 0;
810 810
     }
811 811
 
812
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
812
+    update_post_meta($id, '_wpi_discount_uses', $uses);
813 813
 
814
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
814
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
815 815
 
816 816
     return $uses;
817 817
 
818 818
 }
819 819
 
820
-function wpinv_format_discount_rate( $type, $amount ) {
821
-    if ( $type == 'flat' ) {
822
-        return wpinv_price( wpinv_format_amount( $amount ) );
820
+function wpinv_format_discount_rate($type, $amount) {
821
+    if ($type == 'flat') {
822
+        return wpinv_price(wpinv_format_amount($amount));
823 823
     } else {
824 824
         return $amount . '%';
825 825
     }
826 826
 }
827 827
 
828
-function wpinv_set_cart_discount( $code = '' ) {    
829
-    if ( wpinv_multiple_discounts_allowed() ) {
828
+function wpinv_set_cart_discount($code = '') {    
829
+    if (wpinv_multiple_discounts_allowed()) {
830 830
         // Get all active cart discounts
831 831
         $discounts = wpinv_get_cart_discounts();
832 832
     } else {
833 833
         $discounts = false; // Only one discount allowed per purchase, so override any existing
834 834
     }
835 835
 
836
-    if ( $discounts ) {
837
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
838
-        if( false !== $key ) {
839
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
836
+    if ($discounts) {
837
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
838
+        if (false !== $key) {
839
+            unset($discounts[$key]); // Can't set the same discount more than once
840 840
         }
841 841
         $discounts[] = $code;
842 842
     } else {
843 843
         $discounts = array();
844 844
         $discounts[] = $code;
845 845
     }
846
-    $discounts = array_values( $discounts );
846
+    $discounts = array_values($discounts);
847 847
     
848 848
     $data = wpinv_get_checkout_session();
849
-    if ( empty( $data ) ) {
849
+    if (empty($data)) {
850 850
         $data = array();
851 851
     } else {
852
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
853
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
854
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
852
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
853
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
854
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
855 855
         }
856 856
     }
857 857
     $data['cart_discounts'] = $discounts;
858 858
     
859
-    wpinv_set_checkout_session( $data );
859
+    wpinv_set_checkout_session($data);
860 860
     
861 861
     return $discounts;
862 862
 }
863 863
 
864
-function wpinv_unset_cart_discount( $code = '' ) {    
864
+function wpinv_unset_cart_discount($code = '') {    
865 865
     $discounts = wpinv_get_cart_discounts();
866 866
 
867
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
868
-        $key = array_search( $code, $discounts );
869
-        unset( $discounts[ $key ] );
867
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
868
+        $key = array_search($code, $discounts);
869
+        unset($discounts[$key]);
870 870
             
871 871
         $data = wpinv_get_checkout_session();
872 872
         $data['cart_discounts'] = $discounts;
873
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
874
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
875
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
873
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
874
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
875
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
876 876
         }
877 877
         
878
-        wpinv_set_checkout_session( $data );
878
+        wpinv_set_checkout_session($data);
879 879
     }
880 880
 
881 881
     return $discounts;
@@ -884,27 +884,27 @@  discard block
 block discarded – undo
884 884
 function wpinv_unset_all_cart_discounts() {
885 885
     $data = wpinv_get_checkout_session();
886 886
     
887
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888
-        unset( $data['cart_discounts'] );
887
+    if (!empty($data) && isset($data['cart_discounts'])) {
888
+        unset($data['cart_discounts']);
889 889
         
890
-         wpinv_set_checkout_session( $data );
890
+         wpinv_set_checkout_session($data);
891 891
          return true;
892 892
     }
893 893
     
894 894
     return false;
895 895
 }
896 896
 
897
-function wpinv_get_cart_discounts( $items = array() ) {
897
+function wpinv_get_cart_discounts($items = array()) {
898 898
     $session = wpinv_get_checkout_session();
899 899
     
900
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
900
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
901 901
     return $discounts;
902 902
 }
903 903
 
904
-function wpinv_cart_has_discounts( $items = array() ) {
904
+function wpinv_cart_has_discounts($items = array()) {
905 905
     $ret = false;
906 906
 
907
-    if ( wpinv_get_cart_discounts( $items ) ) {
907
+    if (wpinv_get_cart_discounts($items)) {
908 908
         $ret = true;
909 909
     }
910 910
     
@@ -915,131 +915,131 @@  discard block
 block discarded – undo
915 915
     }
916 916
     */
917 917
 
918
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
918
+    return apply_filters('wpinv_cart_has_discounts', $ret);
919 919
 }
920 920
 
921
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
921
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
922 922
     $amount = 0.00;
923
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
923
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
924 924
 
925
-    if ( $items ) {
926
-        $discounts = wp_list_pluck( $items, 'discount' );
925
+    if ($items) {
926
+        $discounts = wp_list_pluck($items, 'discount');
927 927
 
928
-        if ( is_array( $discounts ) ) {
929
-            $discounts = array_map( 'floatval', $discounts );
930
-            $amount    = array_sum( $discounts );
928
+        if (is_array($discounts)) {
929
+            $discounts = array_map('floatval', $discounts);
930
+            $amount    = array_sum($discounts);
931 931
         }
932 932
     }
933 933
 
934
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
934
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
935 935
 }
936 936
 
937
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
938
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
937
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
938
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
939 939
     
940
-    if ( empty( $discount ) || empty( $items ) ) {
940
+    if (empty($discount) || empty($items)) {
941 941
         return 0;
942 942
     }
943 943
 
944 944
     $amount = 0;
945 945
     
946
-    foreach ( $items as $item ) {
947
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
946
+    foreach ($items as $item) {
947
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
948 948
     }
949 949
     
950
-    $amount = wpinv_round_amount( $amount );
950
+    $amount = wpinv_round_amount($amount);
951 951
 
952 952
     return $amount;
953 953
 }
954 954
 
955
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
955
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
956 956
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
957 957
     
958 958
     $amount = 0;
959 959
 
960
-    if ( empty( $item ) || empty( $item['id'] ) ) {
960
+    if (empty($item) || empty($item['id'])) {
961 961
         return $amount;
962 962
     }
963 963
 
964
-    if ( empty( $item['quantity'] ) ) {
964
+    if (empty($item['quantity'])) {
965 965
         return $amount;
966 966
     }
967 967
 
968
-    if ( empty( $item['options'] ) ) {
968
+    if (empty($item['options'])) {
969 969
         $item['options'] = array();
970 970
     }
971 971
 
972
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
972
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
973 973
     $discounted_price = $price;
974 974
 
975 975
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
976
-    if ( empty( $discounts ) ) {
976
+    if (empty($discounts)) {
977 977
         return $amount;
978 978
     }
979 979
 
980
-    if ( $discounts ) {
981
-        if ( is_array( $discounts ) ) {
982
-            $discounts = array_values( $discounts );
980
+    if ($discounts) {
981
+        if (is_array($discounts)) {
982
+            $discounts = array_values($discounts);
983 983
         } else {
984
-            $discounts = explode( ',', $discounts );
984
+            $discounts = explode(',', $discounts);
985 985
         }
986 986
     }
987 987
 
988
-    if( $discounts ) {
989
-        foreach ( $discounts as $discount ) {
990
-            $code_id = wpinv_get_discount_id_by_code( $discount );
988
+    if ($discounts) {
989
+        foreach ($discounts as $discount) {
990
+            $code_id = wpinv_get_discount_id_by_code($discount);
991 991
 
992 992
             // Check discount exists
993
-            if( ! $code_id ) {
993
+            if (!$code_id) {
994 994
                 continue;
995 995
             }
996 996
 
997
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
998
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
997
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
998
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
999 999
 
1000 1000
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1001
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1002
-                foreach ( $reqs as $item_id ) {
1003
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1004
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1001
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1002
+                foreach ($reqs as $item_id) {
1003
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1004
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1005 1005
                     }
1006 1006
                 }
1007 1007
             } else {
1008 1008
                 // This is a global cart discount
1009
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1010
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1009
+                if (!in_array($item['id'], $excluded_items)) {
1010
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1011 1011
                         $items_subtotal    = 0.00;
1012 1012
                         $cart_items        = wpinv_get_cart_contents();
1013 1013
                         
1014
-                        foreach ( $cart_items as $cart_item ) {
1015
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1016
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1017
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1014
+                        foreach ($cart_items as $cart_item) {
1015
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1016
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1017
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1018 1018
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1019 1019
                             }
1020 1020
                         }
1021 1021
 
1022
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1023
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1022
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1023
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1024 1024
                         $discounted_amount = $code_amount * $subtotal_percent;
1025 1025
                         $discounted_price -= $discounted_amount;
1026 1026
 
1027
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1027
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1028 1028
 
1029
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1029
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1030 1030
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1031 1031
                             $discounted_price -= $adjustment;
1032 1032
                         }
1033 1033
                     } else {
1034
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1034
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1035 1035
                     }
1036 1036
                 }
1037 1037
             }
1038 1038
         }
1039 1039
 
1040
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1040
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1041 1041
 
1042
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1042
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1043 1043
             $amount = $amount * $item['quantity'];
1044 1044
         }
1045 1045
     }
@@ -1047,59 +1047,59 @@  discard block
 block discarded – undo
1047 1047
     return $amount;
1048 1048
 }
1049 1049
 
1050
-function wpinv_cart_discounts_html( $items = array() ) {
1051
-    echo wpinv_get_cart_discounts_html( $items );
1050
+function wpinv_cart_discounts_html($items = array()) {
1051
+    echo wpinv_get_cart_discounts_html($items);
1052 1052
 }
1053 1053
 
1054
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1054
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1055 1055
     global $wpi_cart_columns;
1056 1056
     
1057
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1057
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1058 1058
     
1059
-    if ( !$discounts ) {
1060
-        $discounts = wpinv_get_cart_discounts( $items );
1059
+    if (!$discounts) {
1060
+        $discounts = wpinv_get_cart_discounts($items);
1061 1061
     }
1062 1062
 
1063
-    if ( !$discounts ) {
1063
+    if (!$discounts) {
1064 1064
         return;
1065 1065
     }
1066 1066
     
1067
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1067
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1068 1068
     
1069 1069
     $html = '';
1070 1070
 
1071
-    foreach ( $discounts as $discount ) {
1072
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1073
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1074
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1075
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1076
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1071
+    foreach ($discounts as $discount) {
1072
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1073
+        $discount_value = wpinv_get_discount_amount($discount_id);
1074
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1075
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1076
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1077 1077
         
1078 1078
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1079 1079
         ob_start();
1080
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1080
+        do_action('wpinv_checkout_table_discount_first', $items);
1081 1081
         $html .= ob_get_clean();
1082
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1082
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1083 1083
         ob_start();
1084
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1084
+        do_action('wpinv_checkout_table_discount_last', $items);
1085 1085
         $html .= ob_get_clean();
1086 1086
         $html .= '</tr>';
1087 1087
     }
1088 1088
 
1089
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1089
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1090 1090
 }
1091 1091
 
1092
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1092
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1093 1093
     $discounts = wpinv_get_cart_discounts();
1094 1094
 
1095
-    if ( empty( $discounts ) ) {
1095
+    if (empty($discounts)) {
1096 1096
         return false;
1097 1097
     }
1098 1098
 
1099
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1100
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1099
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1100
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1101 1101
 
1102
-    if ( $echo ) {
1102
+    if ($echo) {
1103 1103
         echo $amount;
1104 1104
     }
1105 1105
 
@@ -1107,133 +1107,133 @@  discard block
 block discarded – undo
1107 1107
 }
1108 1108
 
1109 1109
 function wpinv_remove_cart_discount() {
1110
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1110
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
1114
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1114
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1115 1115
 
1116
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1116
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1117 1117
 
1118
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1118
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1119 1119
 
1120
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1120
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1121 1121
 }
1122
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1122
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1123 1123
 
1124
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1124
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1125 1125
     $discounts = wpinv_get_cart_discounts();
1126 1126
 
1127
-    if ( !$discounts ) {
1127
+    if (!$discounts) {
1128 1128
         return;
1129 1129
     }
1130 1130
 
1131
-    foreach ( $discounts as $discount ) {
1132
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1133
-            wpinv_unset_cart_discount( $discount );
1131
+    foreach ($discounts as $discount) {
1132
+        if (!wpinv_is_discount_valid($discount)) {
1133
+            wpinv_unset_cart_discount($discount);
1134 1134
         }
1135 1135
     }
1136 1136
 }
1137
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1137
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1138 1138
 
1139 1139
 function wpinv_multiple_discounts_allowed() {
1140
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1141
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1140
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1141
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1142 1142
 }
1143 1143
 
1144 1144
 function wpinv_listen_for_cart_discount() {
1145 1145
     global $wpi_session;
1146 1146
     
1147
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1147
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1148 1148
         return;
1149 1149
     }
1150 1150
 
1151
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1151
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1152 1152
 
1153
-    $wpi_session->set( 'preset_discount', $code );
1153
+    $wpi_session->set('preset_discount', $code);
1154 1154
 }
1155 1155
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1156 1156
 
1157 1157
 function wpinv_apply_preset_discount() {
1158 1158
     global $wpi_session;
1159 1159
     
1160
-    $code = $wpi_session->get( 'preset_discount' );
1160
+    $code = $wpi_session->get('preset_discount');
1161 1161
 
1162
-    if ( !$code ) {
1162
+    if (!$code) {
1163 1163
         return;
1164 1164
     }
1165 1165
 
1166
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1166
+    if (!wpinv_is_discount_valid($code, '', false)) {
1167 1167
         return;
1168 1168
     }
1169 1169
     
1170
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1170
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1171 1171
 
1172
-    wpinv_set_cart_discount( $code );
1172
+    wpinv_set_cart_discount($code);
1173 1173
 
1174
-    $wpi_session->set( 'preset_discount', null );
1174
+    $wpi_session->set('preset_discount', null);
1175 1175
 }
1176 1176
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1177 1177
 
1178
-function wpinv_get_discount_label( $code, $echo = true ) {
1179
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1180
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1178
+function wpinv_get_discount_label($code, $echo = true) {
1179
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1180
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1181 1181
 
1182
-    if ( $echo ) {
1182
+    if ($echo) {
1183 1183
         echo $label;
1184 1184
     } else {
1185 1185
         return $label;
1186 1186
     }
1187 1187
 }
1188 1188
 
1189
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1190
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1191
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1189
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1190
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1191
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1192 1192
 
1193
-    if ( $echo ) {
1193
+    if ($echo) {
1194 1194
         echo $label;
1195 1195
     } else {
1196 1196
         return $label;
1197 1197
     }
1198 1198
 }
1199 1199
 
1200
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1201
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1200
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1201
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1202 1202
         return true;
1203 1203
     }
1204 1204
     
1205 1205
     return $check;
1206 1206
 }
1207
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1207
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1208 1208
 
1209 1209
 function wpinv_checkout_form_validate_discounts() {
1210 1210
     $discounts = wpinv_get_cart_discounts();
1211 1211
     
1212
-    if ( !empty( $discounts ) ) {
1212
+    if (!empty($discounts)) {
1213 1213
         $invalid = false;
1214 1214
         
1215
-        foreach ( $discounts as $key => $code ) {
1216
-            if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) {
1215
+        foreach ($discounts as $key => $code) {
1216
+            if (!wpinv_is_discount_valid($code, get_current_user_id())) {
1217 1217
                 $invalid = true;
1218 1218
                 
1219
-                wpinv_unset_cart_discount( $code );
1219
+                wpinv_unset_cart_discount($code);
1220 1220
             }
1221 1221
         }
1222 1222
         
1223
-        if ( $invalid ) {
1223
+        if ($invalid) {
1224 1224
             $errors = wpinv_get_errors();
1225
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1227
-            wpinv_set_error( 'wpinv-discount-error', $error );
1225
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1227
+            wpinv_set_error('wpinv-discount-error', $error);
1228 1228
             
1229
-            wpinv_recalculate_tax( true );
1229
+            wpinv_recalculate_tax(true);
1230 1230
         }
1231 1231
     }
1232 1232
 }
1233
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1233
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1234 1234
 
1235 1235
 function wpinv_discount_amount() {
1236 1236
     $output = 0.00;
1237 1237
     
1238
-    return apply_filters( 'wpinv_discount_amount', $output );
1238
+    return apply_filters('wpinv_discount_amount', $output);
1239 1239
 }
1240 1240
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +682 added lines, -682 removed lines patch added patch discarded remove patch
@@ -7,109 +7,109 @@  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
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', 'invoicing/' );
22
+    return apply_filters('wpinv_template_path', 'invoicing/');
23 23
 }
24 24
 
25
-function wpinv_post_class( $classes, $class, $post_id ) {
25
+function wpinv_post_class($classes, $class, $post_id) {
26 26
     global $pagenow, $typenow;
27 27
 
28
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) {
28
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') {
29 29
         $classes[] = 'wpi-gd-package';
30 30
     }
31 31
     return $classes;
32 32
 }
33
-add_filter( 'post_class', 'wpinv_post_class', 10, 3 );
33
+add_filter('post_class', 'wpinv_post_class', 10, 3);
34 34
 
35
-function wpinv_display_invoice_top_bar( $invoice ) {
36
-    if ( empty( $invoice ) ) {
35
+function wpinv_display_invoice_top_bar($invoice) {
36
+    if (empty($invoice)) {
37 37
         return;
38 38
     }
39 39
     ?>
40 40
     <div class="row wpinv-top-bar no-print">
41 41
         <div class="container">
42 42
             <div class="col-xs-6">
43
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
43
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
44 44
             </div>
45 45
             <div class="col-xs-6 text-right">
46
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
46
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
47 47
             </div>
48 48
         </div>
49 49
     </div>
50 50
     <?php
51 51
 }
52 52
 
53
-function wpinv_invoice_display_left_actions( $invoice ) {
54
-    if ( empty( $invoice ) ) {
53
+function wpinv_invoice_display_left_actions($invoice) {
54
+    if (empty($invoice)) {
55 55
         return;
56 56
     }
57 57
     
58
-    if($invoice->post_type == 'wpi_invoice'){
58
+    if ($invoice->post_type == 'wpi_invoice') {
59 59
     
60 60
         $user_id = (int)$invoice->get_user_id();
61 61
         $current_user_id = (int)get_current_user_id();
62 62
 
63
-        if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) {
63
+        if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) {
64 64
             ?> 
65
-            <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a>
65
+            <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a>
66 66
             <?php
67 67
         }
68 68
     }
69 69
     do_action('wpinv_invoice_display_left_actions', $invoice);
70 70
 }
71 71
 
72
-function wpinv_invoice_display_right_actions( $invoice ) {
73
-    if ( empty( $invoice ) ) return; //Exit if invoice is not set.
72
+function wpinv_invoice_display_right_actions($invoice) {
73
+    if (empty($invoice)) return; //Exit if invoice is not set.
74 74
     
75
-    if($invoice->post_type == 'wpi_invoice'){
75
+    if ($invoice->post_type == 'wpi_invoice') {
76 76
         $user_id = (int)$invoice->get_user_id();
77 77
         $current_user_id = (int)get_current_user_id();
78 78
 
79
-        if ( $user_id > 0 && $user_id == $current_user_id ) {
79
+        if ($user_id > 0 && $user_id == $current_user_id) {
80 80
         ?>
81
-            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> &nbsp;
82
-            <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
81
+            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> &nbsp;
82
+            <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
83 83
         <?php } 
84 84
     }
85 85
     do_action('wpinv_invoice_display_right_actions', $invoice);
86 86
 }
87 87
 
88
-function wpinv_before_invoice_content( $content ) {
88
+function wpinv_before_invoice_content($content) {
89 89
     global $post;
90 90
 
91
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
91
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
92 92
         ob_start();
93
-        do_action( 'wpinv_before_invoice_content', $post->ID );
93
+        do_action('wpinv_before_invoice_content', $post->ID);
94 94
         $content = ob_get_clean() . $content;
95 95
     }
96 96
 
97 97
     return $content;
98 98
 }
99
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
99
+add_filter('the_content', 'wpinv_before_invoice_content');
100 100
 
101
-function wpinv_after_invoice_content( $content ) {
101
+function wpinv_after_invoice_content($content) {
102 102
     global $post;
103 103
 
104
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
104
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
105 105
         ob_start();
106
-        do_action( 'wpinv_after_invoice_content', $post->ID );
106
+        do_action('wpinv_after_invoice_content', $post->ID);
107 107
         $content .= ob_get_clean();
108 108
     }
109 109
 
110 110
     return $content;
111 111
 }
112
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
112
+add_filter('the_content', 'wpinv_after_invoice_content');
113 113
 
114 114
 function wpinv_get_templates_dir() {
115 115
     return WPINV_PLUGIN_DIR . 'templates';
@@ -119,105 +119,105 @@  discard block
 block discarded – undo
119 119
     return WPINV_PLUGIN_URL . 'templates';
120 120
 }
121 121
 
122
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
123
-    if ( ! empty( $args ) && is_array( $args ) ) {
124
-		extract( $args );
122
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
123
+    if (!empty($args) && is_array($args)) {
124
+		extract($args);
125 125
 	}
126 126
 
127
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
127
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
128 128
 	// Allow 3rd party plugin filter template file from their plugin.
129
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
129
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
130 130
 
131
-	if ( ! file_exists( $located ) ) {
132
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
131
+	if (!file_exists($located)) {
132
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
133 133
 		return;
134 134
 	}
135 135
 
136
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
136
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
137 137
 
138
-	include( $located );
138
+	include($located);
139 139
 
140
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
140
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
141 141
 }
142 142
 
143
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
144 144
 	ob_start();
145
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
145
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
146 146
 	return ob_get_clean();
147 147
 }
148 148
 
149
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
150
-    if ( ! $template_path ) {
149
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
150
+    if (!$template_path) {
151 151
         $template_path = wpinv_template_path();
152 152
     }
153 153
 
154
-    if ( ! $default_path ) {
154
+    if (!$default_path) {
155 155
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
156 156
     }
157 157
 
158 158
     // Look within passed path within the theme - this is priority.
159 159
     $template = locate_template(
160 160
         array(
161
-            trailingslashit( $template_path ) . $template_name,
161
+            trailingslashit($template_path) . $template_name,
162 162
             $template_name
163 163
         )
164 164
     );
165 165
 
166 166
     // Get default templates/
167
-    if ( !$template && $default_path ) {
168
-        $template = trailingslashit( $default_path ) . $template_name;
167
+    if (!$template && $default_path) {
168
+        $template = trailingslashit($default_path) . $template_name;
169 169
     }
170 170
 
171 171
     // Return what we found.
172
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
172
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
173 173
 }
174 174
 
175
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
176
-	do_action( 'get_template_part_' . $slug, $slug, $name );
175
+function wpinv_get_template_part($slug, $name = null, $load = true) {
176
+	do_action('get_template_part_' . $slug, $slug, $name);
177 177
 
178 178
 	// Setup possible parts
179 179
 	$templates = array();
180
-	if ( isset( $name ) )
180
+	if (isset($name))
181 181
 		$templates[] = $slug . '-' . $name . '.php';
182 182
 	$templates[] = $slug . '.php';
183 183
 
184 184
 	// Allow template parts to be filtered
185
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
185
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
186 186
 
187 187
 	// Return the part that is found
188
-	return wpinv_locate_tmpl( $templates, $load, false );
188
+	return wpinv_locate_tmpl($templates, $load, false);
189 189
 }
190 190
 
191
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
191
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
192 192
 	// No file found yet
193 193
 	$located = false;
194 194
 
195 195
 	// Try to find a template file
196
-	foreach ( (array)$template_names as $template_name ) {
196
+	foreach ((array)$template_names as $template_name) {
197 197
 
198 198
 		// Continue if template is empty
199
-		if ( empty( $template_name ) )
199
+		if (empty($template_name))
200 200
 			continue;
201 201
 
202 202
 		// Trim off any slashes from the template name
203
-		$template_name = ltrim( $template_name, '/' );
203
+		$template_name = ltrim($template_name, '/');
204 204
 
205 205
 		// try locating this template file by looping through the template paths
206
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
206
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
207 207
 
208
-			if( file_exists( $template_path . $template_name ) ) {
208
+			if (file_exists($template_path . $template_name)) {
209 209
 				$located = $template_path . $template_name;
210 210
 				break;
211 211
 			}
212 212
 		}
213 213
 
214
-		if( !empty( $located ) ) {
214
+		if (!empty($located)) {
215 215
 			break;
216 216
 		}
217 217
 	}
218 218
 
219
-	if ( ( true == $load ) && ! empty( $located ) )
220
-		load_template( $located, $require_once );
219
+	if ((true == $load) && !empty($located))
220
+		load_template($located, $require_once);
221 221
 
222 222
 	return $located;
223 223
 }
@@ -226,143 +226,143 @@  discard block
 block discarded – undo
226 226
 	$template_dir = wpinv_get_theme_template_dir_name();
227 227
 
228 228
 	$file_paths = array(
229
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
230
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
229
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
230
+		10 => trailingslashit(get_template_directory()) . $template_dir,
231 231
 		100 => wpinv_get_templates_dir()
232 232
 	);
233 233
 
234
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
234
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
235 235
 
236 236
 	// sort the file paths based on priority
237
-	ksort( $file_paths, SORT_NUMERIC );
237
+	ksort($file_paths, SORT_NUMERIC);
238 238
 
239
-	return array_map( 'trailingslashit', $file_paths );
239
+	return array_map('trailingslashit', $file_paths);
240 240
 }
241 241
 
242 242
 function wpinv_get_theme_template_dir_name() {
243
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
243
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
244 244
 }
245 245
 
246 246
 function wpinv_checkout_meta_tags() {
247 247
 
248 248
 	$pages   = array();
249
-	$pages[] = wpinv_get_option( 'success_page' );
250
-	$pages[] = wpinv_get_option( 'failure_page' );
251
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
249
+	$pages[] = wpinv_get_option('success_page');
250
+	$pages[] = wpinv_get_option('failure_page');
251
+	$pages[] = wpinv_get_option('invoice_history_page');
252 252
 
253
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+	if (!wpinv_is_checkout() && !is_page($pages)) {
254 254
 		return;
255 255
 	}
256 256
 
257 257
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
258 258
 }
259
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259
+add_action('wp_head', 'wpinv_checkout_meta_tags');
260 260
 
261
-function wpinv_add_body_classes( $class ) {
261
+function wpinv_add_body_classes($class) {
262 262
 	$classes = (array)$class;
263 263
 
264
-	if( wpinv_is_checkout() ) {
264
+	if (wpinv_is_checkout()) {
265 265
 		$classes[] = 'wpinv-checkout';
266 266
 		$classes[] = 'wpinv-page';
267 267
 	}
268 268
 
269
-	if( wpinv_is_success_page() ) {
269
+	if (wpinv_is_success_page()) {
270 270
 		$classes[] = 'wpinv-success';
271 271
 		$classes[] = 'wpinv-page';
272 272
 	}
273 273
 
274
-	if( wpinv_is_failed_transaction_page() ) {
274
+	if (wpinv_is_failed_transaction_page()) {
275 275
 		$classes[] = 'wpinv-failed-transaction';
276 276
 		$classes[] = 'wpinv-page';
277 277
 	}
278 278
 
279
-	if( wpinv_is_invoice_history_page() ) {
279
+	if (wpinv_is_invoice_history_page()) {
280 280
 		$classes[] = 'wpinv-history';
281 281
 		$classes[] = 'wpinv-page';
282 282
 	}
283 283
 
284
-	if( wpinv_is_test_mode() ) {
284
+	if (wpinv_is_test_mode()) {
285 285
 		$classes[] = 'wpinv-test-mode';
286 286
 		$classes[] = 'wpinv-page';
287 287
 	}
288 288
 
289
-	return array_unique( $classes );
289
+	return array_unique($classes);
290 290
 }
291
-add_filter( 'body_class', 'wpinv_add_body_classes' );
291
+add_filter('body_class', 'wpinv_add_body_classes');
292 292
 
293
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
294
-    $args = array( 'nopaging' => true );
293
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
294
+    $args = array('nopaging' => true);
295 295
 
296
-    if ( ! empty( $status ) )
296
+    if (!empty($status))
297 297
         $args['post_status'] = $status;
298 298
 
299
-    $discounts = wpinv_get_discounts( $args );
299
+    $discounts = wpinv_get_discounts($args);
300 300
     $options   = array();
301 301
 
302
-    if ( $discounts ) {
303
-        foreach ( $discounts as $discount ) {
304
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
302
+    if ($discounts) {
303
+        foreach ($discounts as $discount) {
304
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
305 305
         }
306 306
     } else {
307
-        $options[0] = __( 'No discounts found', 'invoicing' );
307
+        $options[0] = __('No discounts found', 'invoicing');
308 308
     }
309 309
 
310
-    $output = wpinv_html_select( array(
310
+    $output = wpinv_html_select(array(
311 311
         'name'             => $name,
312 312
         'selected'         => $selected,
313 313
         'options'          => $options,
314 314
         'show_option_all'  => false,
315 315
         'show_option_none' => false,
316
-    ) );
316
+    ));
317 317
 
318 318
     return $output;
319 319
 }
320 320
 
321
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
322
-    $current     = date( 'Y' );
323
-    $start_year  = $current - absint( $years_before );
324
-    $end_year    = $current + absint( $years_after );
325
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
321
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
322
+    $current     = date('Y');
323
+    $start_year  = $current - absint($years_before);
324
+    $end_year    = $current + absint($years_after);
325
+    $selected    = empty($selected) ? date('Y') : $selected;
326 326
     $options     = array();
327 327
 
328
-    while ( $start_year <= $end_year ) {
329
-        $options[ absint( $start_year ) ] = $start_year;
328
+    while ($start_year <= $end_year) {
329
+        $options[absint($start_year)] = $start_year;
330 330
         $start_year++;
331 331
     }
332 332
 
333
-    $output = wpinv_html_select( array(
333
+    $output = wpinv_html_select(array(
334 334
         'name'             => $name,
335 335
         'selected'         => $selected,
336 336
         'options'          => $options,
337 337
         'show_option_all'  => false,
338 338
         'show_option_none' => false
339
-    ) );
339
+    ));
340 340
 
341 341
     return $output;
342 342
 }
343 343
 
344
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
344
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
345 345
     $month   = 1;
346 346
     $options = array();
347
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
347
+    $selected = empty($selected) ? date('n') : $selected;
348 348
 
349
-    while ( $month <= 12 ) {
350
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
349
+    while ($month <= 12) {
350
+        $options[absint($month)] = wpinv_month_num_to_name($month);
351 351
         $month++;
352 352
     }
353 353
 
354
-    $output = wpinv_html_select( array(
354
+    $output = wpinv_html_select(array(
355 355
         'name'             => $name,
356 356
         'selected'         => $selected,
357 357
         'options'          => $options,
358 358
         'show_option_all'  => false,
359 359
         'show_option_none' => false
360
-    ) );
360
+    ));
361 361
 
362 362
     return $output;
363 363
 }
364 364
 
365
-function wpinv_html_select( $args = array() ) {
365
+function wpinv_html_select($args = array()) {
366 366
     $defaults = array(
367 367
         'options'          => array(),
368 368
         'name'             => null,
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
         'chosen'           => false,
373 373
         'placeholder'      => null,
374 374
         'multiple'         => false,
375
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
376
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
375
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
376
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
377 377
         'data'             => array(),
378 378
         'onchange'         => null,
379 379
         'required'         => false,
@@ -381,78 +381,78 @@  discard block
 block discarded – undo
381 381
         'readonly'         => false,
382 382
     );
383 383
 
384
-    $args = wp_parse_args( $args, $defaults );
384
+    $args = wp_parse_args($args, $defaults);
385 385
 
386 386
     $data_elements = '';
387
-    foreach ( $args['data'] as $key => $value ) {
388
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
387
+    foreach ($args['data'] as $key => $value) {
388
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
389 389
     }
390 390
 
391
-    if( $args['multiple'] ) {
391
+    if ($args['multiple']) {
392 392
         $multiple = ' MULTIPLE';
393 393
     } else {
394 394
         $multiple = '';
395 395
     }
396 396
 
397
-    if( $args['chosen'] ) {
397
+    if ($args['chosen']) {
398 398
         $args['class'] .= ' wpinv-select-chosen';
399 399
     }
400 400
 
401
-    if( $args['placeholder'] ) {
401
+    if ($args['placeholder']) {
402 402
         $placeholder = $args['placeholder'];
403 403
     } else {
404 404
         $placeholder = '';
405 405
     }
406 406
     
407 407
     $options = '';
408
-    if( !empty( $args['onchange'] ) ) {
409
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
408
+    if (!empty($args['onchange'])) {
409
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
410 410
     }
411 411
     
412
-    if( !empty( $args['required'] ) ) {
412
+    if (!empty($args['required'])) {
413 413
         $options .= ' required="required"';
414 414
     }
415 415
     
416
-    if( !empty( $args['disabled'] ) ) {
416
+    if (!empty($args['disabled'])) {
417 417
         $options .= ' disabled';
418 418
     }
419 419
     
420
-    if( !empty( $args['readonly'] ) ) {
420
+    if (!empty($args['readonly'])) {
421 421
         $options .= ' readonly';
422 422
     }
423 423
 
424
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
425
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
424
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
425
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
426 426
 
427
-    if ( $args['show_option_all'] ) {
428
-        if( $args['multiple'] ) {
429
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
427
+    if ($args['show_option_all']) {
428
+        if ($args['multiple']) {
429
+            $selected = selected(true, in_array(0, $args['selected']), false);
430 430
         } else {
431
-            $selected = selected( $args['selected'], 0, false );
431
+            $selected = selected($args['selected'], 0, false);
432 432
         }
433
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
433
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
434 434
     }
435 435
 
436
-    if ( !empty( $args['options'] ) ) {
436
+    if (!empty($args['options'])) {
437 437
 
438
-        if ( $args['show_option_none'] ) {
439
-            if( $args['multiple'] ) {
440
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
438
+        if ($args['show_option_none']) {
439
+            if ($args['multiple']) {
440
+                $selected = selected(true, in_array("", $args['selected']), false);
441 441
             } else {
442
-                $selected = selected( $args['selected'] === "", true, false );
442
+                $selected = selected($args['selected'] === "", true, false);
443 443
             }
444
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
444
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
445 445
         }
446 446
 
447
-        foreach( $args['options'] as $key => $option ) {
447
+        foreach ($args['options'] as $key => $option) {
448 448
 
449
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
450
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
449
+            if ($args['multiple'] && is_array($args['selected'])) {
450
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
451 451
             } else {
452
-                $selected = selected( $args['selected'], $key, false );
452
+                $selected = selected($args['selected'], $key, false);
453 453
             }
454 454
 
455
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
455
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
456 456
         }
457 457
     }
458 458
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
     return $output;
462 462
 }
463 463
 
464
-function wpinv_item_dropdown( $args = array() ) {
464
+function wpinv_item_dropdown($args = array()) {
465 465
     $defaults = array(
466 466
         'name'              => 'wpi_item',
467 467
         'id'                => 'wpi_item',
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
         'selected'          => 0,
471 471
         'chosen'            => false,
472 472
         'number'            => 100,
473
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
474
-        'data'              => array( 'search-type' => 'item' ),
473
+        'placeholder'       => __('Choose a item', 'invoicing'),
474
+        'data'              => array('search-type' => 'item'),
475 475
         'show_option_all'   => false,
476 476
         'show_option_none'  => false,
477 477
         'with_packages'     => true,
478 478
         'show_recurring'    => false,
479 479
     );
480 480
 
481
-    $args = wp_parse_args( $args, $defaults );
481
+    $args = wp_parse_args($args, $defaults);
482 482
 
483 483
     $item_args = array(
484 484
         'post_type'      => 'wpi_item',
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         'posts_per_page' => $args['number']
488 488
     );
489 489
     
490
-    if ( !$args['with_packages'] ) {
490
+    if (!$args['with_packages']) {
491 491
         $item_args['meta_query'] = array(
492 492
             array(
493 493
                 'key'       => '_wpinv_type',
@@ -497,42 +497,42 @@  discard block
 block discarded – undo
497 497
         );
498 498
     }
499 499
 
500
-    $items      = get_posts( $item_args );
500
+    $items      = get_posts($item_args);
501 501
     $options    = array();
502
-    if ( $items ) {
503
-        foreach ( $items as $item ) {
504
-            $title = esc_html( $item->post_title );
502
+    if ($items) {
503
+        foreach ($items as $item) {
504
+            $title = esc_html($item->post_title);
505 505
             
506
-            if ( !empty( $args['show_recurring'] ) ) {
507
-                $title .= wpinv_get_item_suffix( $item->ID, false );
506
+            if (!empty($args['show_recurring'])) {
507
+                $title .= wpinv_get_item_suffix($item->ID, false);
508 508
             }
509 509
             
510
-            $options[ absint( $item->ID ) ] = $title;
510
+            $options[absint($item->ID)] = $title;
511 511
         }
512 512
     }
513 513
 
514 514
     // This ensures that any selected items are included in the drop down
515
-    if( is_array( $args['selected'] ) ) {
516
-        foreach( $args['selected'] as $item ) {
517
-            if( ! in_array( $item, $options ) ) {
518
-                $title = get_the_title( $item );
519
-                if ( !empty( $args['show_recurring'] ) ) {
520
-                    $title .= wpinv_get_item_suffix( $item, false );
515
+    if (is_array($args['selected'])) {
516
+        foreach ($args['selected'] as $item) {
517
+            if (!in_array($item, $options)) {
518
+                $title = get_the_title($item);
519
+                if (!empty($args['show_recurring'])) {
520
+                    $title .= wpinv_get_item_suffix($item, false);
521 521
                 }
522 522
                 $options[$item] = $title;
523 523
             }
524 524
         }
525
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
526
-        if ( ! in_array( $args['selected'], $options ) ) {
527
-            $title = get_the_title( $args['selected'] );
528
-            if ( !empty( $args['show_recurring'] ) ) {
529
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
525
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
526
+        if (!in_array($args['selected'], $options)) {
527
+            $title = get_the_title($args['selected']);
528
+            if (!empty($args['show_recurring'])) {
529
+                $title .= wpinv_get_item_suffix($args['selected'], false);
530 530
             }
531
-            $options[$args['selected']] = get_the_title( $args['selected'] );
531
+            $options[$args['selected']] = get_the_title($args['selected']);
532 532
         }
533 533
     }
534 534
 
535
-    $output = wpinv_html_select( array(
535
+    $output = wpinv_html_select(array(
536 536
         'name'             => $args['name'],
537 537
         'selected'         => $args['selected'],
538 538
         'id'               => $args['id'],
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
         'show_option_all'  => $args['show_option_all'],
545 545
         'show_option_none' => $args['show_option_none'],
546 546
         'data'             => $args['data'],
547
-    ) );
547
+    ));
548 548
 
549 549
     return $output;
550 550
 }
551 551
 
552
-function wpinv_html_checkbox( $args = array() ) {
552
+function wpinv_html_checkbox($args = array()) {
553 553
     $defaults = array(
554 554
         'name'     => null,
555 555
         'current'  => null,
@@ -560,38 +560,38 @@  discard block
 block discarded – undo
560 560
         )
561 561
     );
562 562
 
563
-    $args = wp_parse_args( $args, $defaults );
563
+    $args = wp_parse_args($args, $defaults);
564 564
 
565
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
565
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
566 566
     $options = '';
567
-    if ( ! empty( $args['options']['disabled'] ) ) {
567
+    if (!empty($args['options']['disabled'])) {
568 568
         $options .= ' disabled="disabled"';
569
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
569
+    } elseif (!empty($args['options']['readonly'])) {
570 570
         $options .= ' readonly';
571 571
     }
572 572
 
573
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
573
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
574 574
 
575 575
     return $output;
576 576
 }
577 577
 
578
-function wpinv_html_text( $args = array() ) {
578
+function wpinv_html_text($args = array()) {
579 579
     // Backwards compatibility
580
-    if ( func_num_args() > 1 ) {
580
+    if (func_num_args() > 1) {
581 581
         $args = func_get_args();
582 582
 
583 583
         $name  = $args[0];
584
-        $value = isset( $args[1] ) ? $args[1] : '';
585
-        $label = isset( $args[2] ) ? $args[2] : '';
586
-        $desc  = isset( $args[3] ) ? $args[3] : '';
584
+        $value = isset($args[1]) ? $args[1] : '';
585
+        $label = isset($args[2]) ? $args[2] : '';
586
+        $desc  = isset($args[3]) ? $args[3] : '';
587 587
     }
588 588
 
589 589
     $defaults = array(
590 590
         'id'           => '',
591
-        'name'         => isset( $name )  ? $name  : 'text',
592
-        'value'        => isset( $value ) ? $value : null,
593
-        'label'        => isset( $label ) ? $label : null,
594
-        'desc'         => isset( $desc )  ? $desc  : null,
591
+        'name'         => isset($name) ? $name : 'text',
592
+        'value'        => isset($value) ? $value : null,
593
+        'label'        => isset($label) ? $label : null,
594
+        'desc'         => isset($desc) ? $desc : null,
595 595
         'placeholder'  => '',
596 596
         'class'        => 'regular-text',
597 597
         'disabled'     => false,
@@ -601,51 +601,51 @@  discard block
 block discarded – undo
601 601
         'data'         => false
602 602
     );
603 603
 
604
-    $args = wp_parse_args( $args, $defaults );
604
+    $args = wp_parse_args($args, $defaults);
605 605
 
606
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
606
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
607 607
     $options = '';
608
-    if( $args['required'] ) {
608
+    if ($args['required']) {
609 609
         $options .= ' required="required"';
610 610
     }
611
-    if( $args['readonly'] ) {
611
+    if ($args['readonly']) {
612 612
         $options .= ' readonly';
613 613
     }
614
-    if( $args['readonly'] ) {
614
+    if ($args['readonly']) {
615 615
         $options .= ' readonly';
616 616
     }
617 617
 
618 618
     $data = '';
619
-    if ( !empty( $args['data'] ) ) {
620
-        foreach ( $args['data'] as $key => $value ) {
621
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
619
+    if (!empty($args['data'])) {
620
+        foreach ($args['data'] as $key => $value) {
621
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
622 622
         }
623 623
     }
624 624
 
625
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
626
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
627
-    if ( ! empty( $args['desc'] ) ) {
628
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
625
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
626
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
627
+    if (!empty($args['desc'])) {
628
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
629 629
     }
630 630
 
631
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
631
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
632 632
 
633 633
     $output .= '</span>';
634 634
 
635 635
     return $output;
636 636
 }
637 637
 
638
-function wpinv_html_date_field( $args = array() ) {
639
-    if( empty( $args['class'] ) ) {
638
+function wpinv_html_date_field($args = array()) {
639
+    if (empty($args['class'])) {
640 640
         $args['class'] = 'wpiDatepicker';
641
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
641
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
642 642
         $args['class'] .= ' wpiDatepicker';
643 643
     }
644 644
 
645
-    return wpinv_html_text( $args );
645
+    return wpinv_html_text($args);
646 646
 }
647 647
 
648
-function wpinv_html_textarea( $args = array() ) {
648
+function wpinv_html_textarea($args = array()) {
649 649
     $defaults = array(
650 650
         'name'        => 'textarea',
651 651
         'value'       => null,
@@ -655,31 +655,31 @@  discard block
 block discarded – undo
655 655
         'disabled'    => false
656 656
     );
657 657
 
658
-    $args = wp_parse_args( $args, $defaults );
658
+    $args = wp_parse_args($args, $defaults);
659 659
 
660
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
660
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
661 661
     $disabled = '';
662
-    if( $args['disabled'] ) {
662
+    if ($args['disabled']) {
663 663
         $disabled = ' disabled="disabled"';
664 664
     }
665 665
 
666
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
667
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
668
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
666
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
667
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
668
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
669 669
 
670
-    if ( ! empty( $args['desc'] ) ) {
671
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
670
+    if (!empty($args['desc'])) {
671
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
672 672
     }
673 673
     $output .= '</span>';
674 674
 
675 675
     return $output;
676 676
 }
677 677
 
678
-function wpinv_html_ajax_user_search( $args = array() ) {
678
+function wpinv_html_ajax_user_search($args = array()) {
679 679
     $defaults = array(
680 680
         'name'        => 'user_id',
681 681
         'value'       => null,
682
-        'placeholder' => __( 'Enter username', 'invoicing' ),
682
+        'placeholder' => __('Enter username', 'invoicing'),
683 683
         'label'       => null,
684 684
         'desc'        => null,
685 685
         'class'       => '',
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
         'data'        => false
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693 693
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
694 694
 
695 695
     $output  = '<span class="wpinv_user_search_wrap">';
696
-        $output .= wpinv_html_text( $args );
697
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
696
+        $output .= wpinv_html_text($args);
697
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
698 698
     $output .= '</span>';
699 699
 
700 700
     return $output;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 function wpinv_ip_geolocation() {
704 704
     global $wpinv_euvat;
705 705
     
706
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
706
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
707 707
     $content    = '';
708 708
     $iso        = '';
709 709
     $country    = '';
@@ -714,69 +714,69 @@  discard block
 block discarded – undo
714 714
     $credit     = '';
715 715
     $address    = '';
716 716
     
717
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
717
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
718 718
         try {
719 719
             $iso        = $geoip2_city->country->isoCode;
720 720
             $country    = $geoip2_city->country->name;
721
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
721
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
722 722
             $city       = $geoip2_city->city->name;
723 723
             $longitude  = $geoip2_city->location->longitude;
724 724
             $latitude   = $geoip2_city->location->latitude;
725
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
726
-        } catch( Exception $e ) { }
725
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
729
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
730 730
         try {
731
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
731
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
732 732
             
733
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
733
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
734 734
                 $iso        = $load_xml->geoplugin_countryCode;
735 735
                 $country    = $load_xml->geoplugin_countryName;
736
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
737
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
736
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
737
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
738 738
                 $longitude  = $load_xml->geoplugin_longitude;
739 739
                 $latitude   = $load_xml->geoplugin_latitude;
740 740
                 $credit     = $load_xml->geoplugin_credit;
741
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
741
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
742 742
             }
743
-        } catch( Exception $e ) { }
743
+        } catch (Exception $e) { }
744 744
     }
745 745
     
746
-    if ( $iso && $longitude && $latitude ) {
747
-        if ( $city ) {
746
+    if ($iso && $longitude && $latitude) {
747
+        if ($city) {
748 748
             $address .= $city . ', ';
749 749
         }
750 750
         
751
-        if ( $region ) {
751
+        if ($region) {
752 752
             $address .= $region . ', ';
753 753
         }
754 754
         
755 755
         $address .= $country . ' (' . $iso . ')';
756
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
757
-        $content .= '<p>'. $credit . '</p>';
756
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
757
+        $content .= '<p>' . $credit . '</p>';
758 758
     } else {
759
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
759
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
760 760
     }
761 761
     ?>
762 762
 <!DOCTYPE html>
763
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
763
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
764 764
 <body>
765
-    <?php if ( $latitude && $latitude ) { ?>
765
+    <?php if ($latitude && $latitude) { ?>
766 766
     <div id="map"></div>
767 767
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
768 768
         <script type="text/javascript">
769 769
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
770 770
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
771 771
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
772
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
772
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
773 773
 
774 774
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
775 775
 
776 776
         var marker = new L.Marker(latlng);
777 777
         map.addLayer(marker);
778 778
 
779
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
779
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
780 780
     </script>
781 781
     <?php } ?>
782 782
     <div style="height:100px"><?php echo $content; ?></div>
@@ -784,31 +784,31 @@  discard block
 block discarded – undo
784 784
 <?php
785 785
     exit;
786 786
 }
787
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
788
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
787
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
788
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
789 789
 
790 790
 // Set up the template for the invoice.
791
-function wpinv_template( $template ) {
791
+function wpinv_template($template) {
792 792
     global $post, $wp_query;
793 793
     
794
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
795
-        if ( wpinv_user_can_print_invoice( $post->ID ) ) {
796
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
794
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
795
+        if (wpinv_user_can_print_invoice($post->ID)) {
796
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
797 797
         } else {
798
-            if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) {
798
+            if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) {
799 799
                 $user_id = $invoice->get_user_id();
800
-                $secret = sanitize_text_field( $_GET['_wpipay'] );
800
+                $secret = sanitize_text_field($_GET['_wpipay']);
801 801
 
802
-                if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link
803
-                    $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
802
+                if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link
803
+                    $redirect_to = remove_query_arg('_wpipay', get_permalink());
804 804
 
805
-                    wpinv_guest_redirect( $redirect_to, $user_id );
805
+                    wpinv_guest_redirect($redirect_to, $user_id);
806 806
                     wpinv_die();
807 807
                 }
808 808
             }
809
-            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
809
+            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
810 810
 
811
-            wp_redirect( $redirect_to );
811
+            wp_redirect($redirect_to);
812 812
             wpinv_die();
813 813
         }
814 814
     }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 
819 819
 function wpinv_get_business_address() {
820 820
     $business_address   = wpinv_store_address();
821
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
821
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
822 822
     
823 823
     /*
824 824
     $default_country    = wpinv_get_default_country();
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     
843 843
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
844 844
     
845
-    return apply_filters( 'wpinv_get_business_address', $business_address );
845
+    return apply_filters('wpinv_get_business_address', $business_address);
846 846
 }
847 847
 
848 848
 function wpinv_display_from_address() {
@@ -852,185 +852,185 @@  discard block
 block discarded – undo
852 852
     if (empty($from_name)) {
853 853
         $from_name = wpinv_get_business_name();
854 854
     }
855
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
855
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
856 856
     <div class="wrapper col-xs-10">
857
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
858
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
859
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
857
+        <div class="name"><?php echo esc_html($from_name); ?></div>
858
+        <?php if ($address = wpinv_get_business_address()) { ?>
859
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
860 860
         <?php } ?>
861
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
862
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div>
861
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
862
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div>
863 863
         <?php } ?>
864 864
     </div>
865 865
     <?php
866 866
 }
867 867
 
868
-function wpinv_watermark( $id = 0 ) {
869
-    $output = wpinv_get_watermark( $id );
868
+function wpinv_watermark($id = 0) {
869
+    $output = wpinv_get_watermark($id);
870 870
     
871
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
871
+    return apply_filters('wpinv_get_watermark', $output, $id);
872 872
 }
873 873
 
874
-function wpinv_get_watermark( $id ) {
875
-    if ( !$id > 0 ) {
874
+function wpinv_get_watermark($id) {
875
+    if (!$id > 0) {
876 876
         return NULL;
877 877
     }
878
-    $invoice = wpinv_get_invoice( $id );
878
+    $invoice = wpinv_get_invoice($id);
879 879
     
880
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
881
-        if ( $invoice->is_paid() ) {
882
-            return __( 'Paid', 'invoicing' );
880
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
881
+        if ($invoice->is_paid()) {
882
+            return __('Paid', 'invoicing');
883 883
         }
884
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
885
-            return __( 'Cancelled', 'invoicing' );
884
+        if ($invoice->has_status(array('wpi-cancelled'))) {
885
+            return __('Cancelled', 'invoicing');
886 886
         }
887 887
     }
888 888
     
889 889
     return NULL;
890 890
 }
891 891
 
892
-function wpinv_display_invoice_details( $invoice ) {
892
+function wpinv_display_invoice_details($invoice) {
893 893
     global $wpinv_euvat;
894 894
     
895 895
     $invoice_id = $invoice->ID;
896 896
     $vat_name   = $wpinv_euvat->get_vat_name();
897 897
     $use_taxes  = wpinv_use_taxes();
898 898
     
899
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
899
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
900 900
     
901
-    if($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
-    elseif($invoice->post_type == 'wpi_quote') $type = 'Quote';
901
+    if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
+    elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote';
903 903
     ?>
904 904
     <table class="table table-bordered table-sm">
905
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
905
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
906 906
             <tr class="wpi-row-number">
907
-                <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th>
908
-                <td><?php echo esc_html( $invoice_number ); ?></td>
907
+                <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th>
908
+                <td><?php echo esc_html($invoice_number); ?></td>
909 909
             </tr>
910 910
         <?php } ?>
911 911
         <tr class="wpi-row-status">
912
-            <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th>
913
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
912
+            <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th>
913
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
914 914
         </tr>
915
-        <?php if ( $invoice->is_renewal() ) { ?>
915
+        <?php if ($invoice->is_renewal()) { ?>
916 916
         <tr class="wpi-row-parent">
917
-            <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th>
918
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
917
+            <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th>
918
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
919 919
         </tr>
920 920
         <?php } ?>
921 921
         <tr class="wpi-row-gateway">
922
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
923
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
922
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
923
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
924 924
         </tr>
925
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
925
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
926 926
             <tr class="wpi-row-date">
927
-                <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th>
927
+                <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th>
928 928
                 <td><?php echo $invoice_date; ?></td>
929 929
             </tr>
930 930
         <?php } ?>
931
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
931
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
932 932
             <tr class="wpi-row-date">
933
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
933
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
934 934
                 <td><?php echo $due_date; ?></td>
935 935
             </tr>
936 936
         <?php } ?>
937
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
937
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
938 938
             <tr class="wpi-row-ovatno">
939
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
939
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
940 940
                 <td><?php echo $owner_vat_number; ?></td>
941 941
             </tr>
942 942
         <?php } ?>
943
-        <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
943
+        <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
944 944
             <tr class="wpi-row-uvatno">
945
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
945
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
946 946
                 <td><?php echo $user_vat_number; ?></td>
947 947
             </tr>
948 948
         <?php } ?>
949 949
         <tr class="table-active tr-total wpi-row-total">
950
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
951
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
950
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
951
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
952 952
         </tr>
953 953
     </table>
954 954
 <?php
955 955
 }
956 956
 
957
-function wpinv_display_to_address( $invoice_id = 0 ) {
958
-    $invoice = wpinv_get_invoice( $invoice_id );
957
+function wpinv_display_to_address($invoice_id = 0) {
958
+    $invoice = wpinv_get_invoice($invoice_id);
959 959
     
960
-    if ( empty( $invoice ) ) {
960
+    if (empty($invoice)) {
961 961
         return NULL;
962 962
     }
963 963
     
964 964
     $billing_details = $invoice->get_user_info();
965
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
965
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
966 966
     $output .= '<div class="wrapper col-xs-10">';
967 967
     
968 968
     ob_start();
969
-    do_action( 'wpinv_display_to_address_top', $invoice );
969
+    do_action('wpinv_display_to_address_top', $invoice);
970 970
     $output .= ob_get_clean();
971 971
     
972
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
973
-    if ( $company = $billing_details['company'] ) {
974
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
972
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
973
+    if ($company = $billing_details['company']) {
974
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
975 975
     }
976 976
     $address_row = '';
977
-    if ( $address = $billing_details['address'] ) {
978
-        $address_row .= wpautop( wp_kses_post( $address ) );
977
+    if ($address = $billing_details['address']) {
978
+        $address_row .= wpautop(wp_kses_post($address));
979 979
     }
980 980
     
981 981
     $address_fields = array();
982
-    if ( !empty( $billing_details['city'] ) ) {
982
+    if (!empty($billing_details['city'])) {
983 983
         $address_fields[] = $billing_details['city'];
984 984
     }
985 985
     
986
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
987
-    if ( !empty( $billing_details['state'] ) ) {
988
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
986
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
987
+    if (!empty($billing_details['state'])) {
988
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
989 989
     }
990 990
     
991
-    if ( !empty( $billing_country ) ) {
992
-        $address_fields[] = wpinv_country_name( $billing_country );
991
+    if (!empty($billing_country)) {
992
+        $address_fields[] = wpinv_country_name($billing_country);
993 993
     }
994 994
     
995
-    if ( !empty( $address_fields ) ) {
996
-        $address_fields = implode( ", ", $address_fields );
995
+    if (!empty($address_fields)) {
996
+        $address_fields = implode(", ", $address_fields);
997 997
         
998
-        if ( !empty( $billing_details['zip'] ) ) {
998
+        if (!empty($billing_details['zip'])) {
999 999
             $address_fields .= ' ' . $billing_details['zip'];
1000 1000
         }
1001 1001
         
1002
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1002
+        $address_row .= wpautop(wp_kses_post($address_fields));
1003 1003
     }
1004 1004
     
1005
-    if ( $address_row ) {
1005
+    if ($address_row) {
1006 1006
         $output .= '<div class="address">' . $address_row . '</div>';
1007 1007
     }
1008 1008
     
1009
-    if ( $phone = $invoice->get_phone() ) {
1010
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>';
1009
+    if ($phone = $invoice->get_phone()) {
1010
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>';
1011 1011
     }
1012
-    if ( $email = $invoice->get_email() ) {
1013
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>';
1012
+    if ($email = $invoice->get_email()) {
1013
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>';
1014 1014
     }
1015 1015
     
1016 1016
     ob_start();
1017
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
1017
+    do_action('wpinv_display_to_address_bottom', $invoice);
1018 1018
     $output .= ob_get_clean();
1019 1019
     
1020 1020
     $output .= '</div>';
1021
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1021
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1022 1022
 
1023 1023
     echo $output;
1024 1024
 }
1025 1025
 
1026
-function wpinv_display_line_items( $invoice_id = 0 ) {
1026
+function wpinv_display_line_items($invoice_id = 0) {
1027 1027
     global $wpinv_euvat, $ajax_cart_details;
1028
-    $invoice            = wpinv_get_invoice( $invoice_id );
1028
+    $invoice            = wpinv_get_invoice($invoice_id);
1029 1029
     $quantities_enabled = wpinv_item_quantities_enabled();
1030 1030
     $use_taxes          = wpinv_use_taxes();
1031 1031
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1032
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1033
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1032
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1033
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1034 1034
     
1035 1035
     $cart_details       = $invoice->get_cart_details();
1036 1036
     $ajax_cart_details  = $cart_details;
@@ -1039,68 +1039,68 @@  discard block
 block discarded – undo
1039 1039
     <table class="table table-sm table-bordered table-responsive">
1040 1040
         <thead>
1041 1041
             <tr>
1042
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1043
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1042
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1043
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1044 1044
                 <?php if ($quantities_enabled) { ?>
1045
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1045
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1046 1046
                 <?php } ?>
1047 1047
                 <?php if ($use_taxes && !$zero_tax) { ?>
1048 1048
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1049 1049
                 <?php } ?>
1050
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1050
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1051 1051
             </tr>
1052 1052
         </thead>
1053 1053
         <tbody>
1054 1054
         <?php 
1055
-            if ( !empty( $cart_details ) ) {
1056
-                do_action( 'wpinv_display_line_items_start', $invoice );
1055
+            if (!empty($cart_details)) {
1056
+                do_action('wpinv_display_line_items_start', $invoice);
1057 1057
                 
1058 1058
                 $count = 0;
1059 1059
                 $cols  = 3;
1060
-                foreach ( $cart_details as $key => $cart_item ) {
1061
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1062
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1063
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1064
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1060
+                foreach ($cart_details as $key => $cart_item) {
1061
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1062
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1063
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1064
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1065 1065
                     
1066
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1066
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1067 1067
                     $summary    = '';
1068 1068
                     $cols       = 3;
1069
-                    if ( !empty($item) ) {
1069
+                    if (!empty($item)) {
1070 1070
                         $item_name  = $item->get_name();
1071 1071
                         $summary    = $item->get_summary();
1072 1072
                     }
1073
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1073
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1074 1074
                     
1075 1075
                     if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) {
1076
-                        $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1077
-                        $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link );
1076
+                        $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1077
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link);
1078 1078
                     }
1079
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1079
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1080 1080
                     
1081 1081
                     $item_tax       = '';
1082 1082
                     $tax_rate       = '';
1083
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1084
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1085
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1086
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1083
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1084
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1085
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1086
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1087 1087
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1088 1088
                     }
1089 1089
                     
1090 1090
                     $line_item_tax = $item_tax . $tax_rate;
1091 1091
                     
1092
-                    if ( $line_item_tax === '' ) {
1092
+                    if ($line_item_tax === '') {
1093 1093
                         $line_item_tax = 0; // Zero tax
1094 1094
                     }
1095 1095
                     
1096
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1097
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1098
-                        if ( $summary !== '' ) {
1099
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1096
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1097
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1098
+                        if ($summary !== '') {
1099
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1100 1100
                         }
1101 1101
                         $line_item .= '</td>';
1102 1102
                         
1103
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1103
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1104 1104
                         if ($quantities_enabled) {
1105 1105
                             $cols++;
1106 1106
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1109,55 +1109,55 @@  discard block
 block discarded – undo
1109 1109
                             $cols++;
1110 1110
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1111 1111
                         }
1112
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1112
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1113 1113
                     $line_item .= '</tr>';
1114 1114
                     
1115
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1115
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1116 1116
 
1117 1117
                     $count++;
1118 1118
                 }
1119 1119
                 
1120
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1120
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1121 1121
                 ?>
1122 1122
                 <tr class="row-sub-total row_odd">
1123
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1124
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1123
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1124
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1125 1125
                 </tr>
1126 1126
                 <?php
1127
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1127
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1128 1128
                 
1129
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1130
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1129
+                if (wpinv_discount($invoice_id, false) > 0) {
1130
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1131 1131
                     ?>
1132 1132
                         <tr class="row-discount">
1133
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1134
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1133
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1134
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1135 1135
                         </tr>
1136 1136
                     <?php
1137
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1137
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1138 1138
                 }
1139 1139
                 
1140
-                if ( $use_taxes ) {
1141
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1140
+                if ($use_taxes) {
1141
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1142 1142
                     ?>
1143 1143
                     <tr class="row-tax">
1144
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1145
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1144
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1145
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1146 1146
                     </tr>
1147 1147
                     <?php
1148
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1148
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1149 1149
                 }
1150 1150
                 
1151
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1151
+                do_action('wpinv_display_before_total', $invoice, $cols);
1152 1152
                 ?>
1153 1153
                 <tr class="table-active row-total">
1154
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1155
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1154
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1155
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1156 1156
                 </tr>
1157 1157
                 <?php
1158
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1158
+                do_action('wpinv_display_after_total', $invoice, $cols);
1159 1159
                 
1160
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1160
+                do_action('wpinv_display_line_end', $invoice, $cols);
1161 1161
             }
1162 1162
         ?>
1163 1163
         </tbody>
@@ -1166,35 +1166,35 @@  discard block
 block discarded – undo
1166 1166
     echo ob_get_clean();
1167 1167
 }
1168 1168
 
1169
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {    
1169
+function wpinv_display_invoice_totals($invoice_id = 0) {    
1170 1170
     $use_taxes = wpinv_use_taxes();
1171 1171
     
1172
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1172
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1173 1173
     ?>
1174 1174
     <table class="table table-sm table-bordered table-responsive">
1175 1175
         <tbody>
1176
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1176
+            <?php do_action('wpinv_before_display_totals'); ?>
1177 1177
             <tr class="row-sub-total">
1178
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1179
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1178
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1179
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1180 1180
             </tr>
1181
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1182
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1181
+            <?php do_action('wpinv_after_display_totals'); ?>
1182
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1183 1183
                 <tr class="row-discount">
1184
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1185
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1184
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1185
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1186 1186
                 </tr>
1187
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1187
+            <?php do_action('wpinv_after_display_discount'); ?>
1188 1188
             <?php } ?>
1189
-            <?php if ( $use_taxes ) { ?>
1189
+            <?php if ($use_taxes) { ?>
1190 1190
             <tr class="row-tax">
1191
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1192
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1191
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1192
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1193 1193
             </tr>
1194
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1194
+            <?php do_action('wpinv_after_display_tax'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1197
-                <?php foreach ( $fees as $fee ) { ?>
1196
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1197
+                <?php foreach ($fees as $fee) { ?>
1198 1198
                     <tr class="row-fee">
1199 1199
                         <td class="rate"><?php echo $fee['label']; ?></td>
1200 1200
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1202,72 +1202,72 @@  discard block
 block discarded – undo
1202 1202
                 <?php } ?>
1203 1203
             <?php } ?>
1204 1204
             <tr class="table-active row-total">
1205
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1206
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1205
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1206
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1207 1207
             </tr>
1208
-            <?php do_action( 'wpinv_after_totals' ); ?>
1208
+            <?php do_action('wpinv_after_totals'); ?>
1209 1209
         </tbody>
1210 1210
 
1211 1211
     </table>
1212 1212
 
1213
-    <?php do_action( 'wpinv_after_totals_table' );
1213
+    <?php do_action('wpinv_after_totals_table');
1214 1214
 }
1215 1215
 
1216
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1217
-    $invoice = wpinv_get_invoice( $invoice_id );
1216
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1217
+    $invoice = wpinv_get_invoice($invoice_id);
1218 1218
     
1219 1219
     ob_start();
1220
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1221
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) {
1220
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1221
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) {
1222 1222
         ?>
1223 1223
         <div class="wpi-payment-info">
1224
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1225
-            <?php if ( $gateway_title ) { ?>
1226
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1224
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1225
+            <?php if ($gateway_title) { ?>
1226
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1227 1227
             <?php } ?>
1228 1228
         </div>
1229 1229
         <?php
1230 1230
     }
1231
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1231
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1232 1232
     $outout = ob_get_clean();
1233 1233
     
1234
-    if ( $echo ) {
1234
+    if ($echo) {
1235 1235
         echo $outout;
1236 1236
     } else {
1237 1237
         return $outout;
1238 1238
     }
1239 1239
 }
1240 1240
 
1241
-function wpinv_display_style( $invoice ) {
1242
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1241
+function wpinv_display_style($invoice) {
1242
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1243 1243
     
1244
-    wp_print_styles( 'open-sans' );
1245
-    wp_print_styles( 'wpinv-single-style' );
1244
+    wp_print_styles('open-sans');
1245
+    wp_print_styles('wpinv-single-style');
1246 1246
 }
1247
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1247
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1248 1248
 
1249 1249
 function wpinv_checkout_billing_details() {  
1250 1250
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1251 1251
     if (empty($invoice_id)) {
1252
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1252
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1253 1253
         return null;
1254 1254
     }
1255 1255
     
1256
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1256
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1257 1257
     if (empty($invoice)) {
1258
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1258
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1259 1259
         return null;
1260 1260
     }
1261 1261
     $user_id        = $invoice->get_user_id();
1262 1262
     $user_info      = $invoice->get_user_info();
1263
-    $address_info   = wpinv_get_user_address( $user_id );
1263
+    $address_info   = wpinv_get_user_address($user_id);
1264 1264
     
1265
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1265
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1266 1266
         $user_info['first_name'] = $user_info['first_name'];
1267 1267
         $user_info['last_name'] = $user_info['last_name'];
1268 1268
     }
1269 1269
     
1270
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1270
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1271 1271
         $user_info['country']   = $address_info['country'];
1272 1272
         $user_info['state']     = $address_info['state'];
1273 1273
         $user_info['city']      = $address_info['city'];
@@ -1283,103 +1283,103 @@  discard block
 block discarded – undo
1283 1283
         'address'
1284 1284
     );
1285 1285
     
1286
-    foreach ( $address_fields as $field ) {
1287
-        if ( empty( $user_info[$field] ) ) {
1286
+    foreach ($address_fields as $field) {
1287
+        if (empty($user_info[$field])) {
1288 1288
             $user_info[$field] = $address_info[$field];
1289 1289
         }
1290 1290
     }
1291 1291
     
1292
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1292
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1293 1293
 }
1294 1294
 
1295 1295
 function wpinv_admin_get_line_items($invoice = array()) {
1296 1296
     $item_quantities    = wpinv_item_quantities_enabled();
1297 1297
     $use_taxes          = wpinv_use_taxes();
1298 1298
     
1299
-    if ( empty( $invoice ) ) {
1299
+    if (empty($invoice)) {
1300 1300
         return NULL;
1301 1301
     }
1302 1302
     
1303 1303
     $cart_items = $invoice->get_cart_details();
1304
-    if ( empty( $cart_items ) ) {
1304
+    if (empty($cart_items)) {
1305 1305
         return NULL;
1306 1306
     }
1307 1307
     ob_start();
1308 1308
     
1309
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1309
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1310 1310
     
1311 1311
     $count = 0;
1312
-    foreach ( $cart_items as $key => $cart_item ) {
1312
+    foreach ($cart_items as $key => $cart_item) {
1313 1313
         $item_id    = $cart_item['id'];
1314
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1314
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1315 1315
         
1316 1316
         if (empty($wpi_item)) {
1317 1317
             continue;
1318 1318
         }
1319 1319
         
1320
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) );
1321
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) );
1320
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']));
1321
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']));
1323 1323
         $can_remove     = true;
1324 1324
         
1325 1325
         $summary = '';
1326 1326
         if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) {
1327
-            $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1328
-            $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
1327
+            $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1328
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
1329 1329
         }
1330
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1330
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1331 1331
         
1332 1332
         $item_tax       = '';
1333 1333
         $tax_rate       = '';
1334
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1335
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1336
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1337
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1334
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1335
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1336
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1337
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1338 1338
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1339 1339
         }
1340 1340
         $line_item_tax = $item_tax . $tax_rate;
1341 1341
         
1342
-        if ( $line_item_tax === '' ) {
1342
+        if ($line_item_tax === '') {
1343 1343
             $line_item_tax = 0; // Zero tax
1344 1344
         }
1345 1345
 
1346
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1346
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1347 1347
             $line_item .= '<td class="id">' . $item_id . '</td>';
1348
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1349
-            if ( $summary !== '' ) {
1350
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1348
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1349
+            if ($summary !== '') {
1350
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1351 1351
             }
1352 1352
             $line_item .= '</td>';
1353 1353
             $line_item .= '<td class="price">' . $item_price . '</td>';
1354 1354
             
1355
-            if ( $item_quantities ) {
1356
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1355
+            if ($item_quantities) {
1356
+                if (count($cart_items) == 1 && $quantity <= 1) {
1357 1357
                     $can_remove = false;
1358 1358
                 }
1359 1359
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1360 1360
             } else {
1361
-                if ( count( $cart_items ) == 1 ) {
1361
+                if (count($cart_items) == 1) {
1362 1362
                     $can_remove = false;
1363 1363
                 }
1364 1364
             }
1365 1365
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1366 1366
             
1367
-            if ( $use_taxes ) {
1367
+            if ($use_taxes) {
1368 1368
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1369 1369
             }
1370 1370
             $line_item .= '<td class="action">';
1371
-            if ( !$invoice->is_paid() && $can_remove ) {
1371
+            if (!$invoice->is_paid() && $can_remove) {
1372 1372
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1373 1373
             }
1374 1374
             $line_item .= '</td>';
1375 1375
         $line_item .= '</tr>';
1376 1376
         
1377
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1377
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1378 1378
         
1379 1379
         $count++;
1380 1380
     } 
1381 1381
     
1382
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1382
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1383 1383
     
1384 1384
     return ob_get_clean();
1385 1385
 }
@@ -1390,35 +1390,35 @@  discard block
 block discarded – undo
1390 1390
     // Set current invoice id.
1391 1391
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1392 1392
     
1393
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1393
+    $form_action = esc_url(wpinv_get_checkout_uri());
1394 1394
 
1395 1395
     ob_start();
1396 1396
         echo '<div id="wpinv_checkout_wrap">';
1397 1397
         
1398
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1398
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1399 1399
             ?>
1400 1400
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1401
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1401
+                <?php do_action('wpinv_before_checkout_form'); ?>
1402 1402
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1403 1403
                     <?php
1404
-                    do_action( 'wpinv_checkout_form_top' );
1405
-                    do_action( 'wpinv_checkout_billing_info' );
1406
-                    do_action( 'wpinv_checkout_cart' );
1407
-                    do_action( 'wpinv_payment_mode_select'  );
1408
-                    do_action( 'wpinv_checkout_form_bottom' )
1404
+                    do_action('wpinv_checkout_form_top');
1405
+                    do_action('wpinv_checkout_billing_info');
1406
+                    do_action('wpinv_checkout_cart');
1407
+                    do_action('wpinv_payment_mode_select');
1408
+                    do_action('wpinv_checkout_form_bottom')
1409 1409
                     ?>
1410 1410
                 </form>
1411
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1411
+                <?php do_action('wpinv_after_purchase_form'); ?>
1412 1412
             </div><!--end #wpinv_checkout_form_wrap-->
1413 1413
         <?php
1414 1414
         } else {
1415
-            do_action( 'wpinv_cart_empty' );
1415
+            do_action('wpinv_cart_empty');
1416 1416
         }
1417 1417
         echo '</div><!--end #wpinv_checkout_wrap-->';
1418 1418
     return ob_get_clean();
1419 1419
 }
1420 1420
 
1421
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1421
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1422 1422
     global $ajax_cart_details;
1423 1423
     $ajax_cart_details = $cart_details;
1424 1424
     /*
@@ -1433,25 +1433,25 @@  discard block
 block discarded – undo
1433 1433
     }
1434 1434
     */
1435 1435
     ob_start();
1436
-    do_action( 'wpinv_before_checkout_cart' );
1436
+    do_action('wpinv_before_checkout_cart');
1437 1437
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1438 1438
         echo '<div id="wpinv_checkout_cart_wrap">';
1439
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1439
+            wpinv_get_template_part('wpinv-checkout-cart');
1440 1440
         echo '</div>';
1441 1441
     echo '</div>';
1442
-    do_action( 'wpinv_after_checkout_cart' );
1442
+    do_action('wpinv_after_checkout_cart');
1443 1443
     $content = ob_get_clean();
1444 1444
     
1445
-    if ( $echo ) {
1445
+    if ($echo) {
1446 1446
         echo $content;
1447 1447
     } else {
1448 1448
         return $content;
1449 1449
     }
1450 1450
 }
1451
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1451
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1452 1452
 
1453 1453
 function wpinv_empty_cart_message() {
1454
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1454
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1455 1455
 }
1456 1456
 
1457 1457
 /**
@@ -1463,91 +1463,91 @@  discard block
 block discarded – undo
1463 1463
 function wpinv_empty_checkout_cart() {
1464 1464
 	echo wpinv_empty_cart_message();
1465 1465
 }
1466
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1466
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1467 1467
 
1468 1468
 function wpinv_save_cart_button() {
1469
-    if ( wpinv_is_cart_saving_disabled() )
1469
+    if (wpinv_is_cart_saving_disabled())
1470 1470
         return;
1471 1471
 ?>
1472
-    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a>
1472
+    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a>
1473 1473
 <?php
1474 1474
 }
1475 1475
 
1476 1476
 function wpinv_update_cart_button() {
1477
-    if ( !wpinv_item_quantities_enabled() )
1477
+    if (!wpinv_item_quantities_enabled())
1478 1478
         return;
1479 1479
 ?>
1480
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1480
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1481 1481
     <input type="hidden" name="wpi_action" value="update_cart"/>
1482 1482
 <?php
1483 1483
 }
1484 1484
 
1485 1485
 function wpinv_checkout_cart_columns() {
1486 1486
     $default = 3;
1487
-    if ( wpinv_item_quantities_enabled() ) {
1487
+    if (wpinv_item_quantities_enabled()) {
1488 1488
         $default++;
1489 1489
     }
1490 1490
     
1491
-    if ( wpinv_use_taxes() ) {
1491
+    if (wpinv_use_taxes()) {
1492 1492
         $default++;
1493 1493
     }
1494 1494
 
1495
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1495
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1496 1496
 }
1497 1497
 
1498 1498
 function wpinv_display_cart_messages() {
1499 1499
     global $wpi_session;
1500 1500
 
1501
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1501
+    $messages = $wpi_session->get('wpinv_cart_messages');
1502 1502
 
1503
-    if ( $messages ) {
1504
-        foreach ( $messages as $message_id => $message ) {
1503
+    if ($messages) {
1504
+        foreach ($messages as $message_id => $message) {
1505 1505
             // Try and detect what type of message this is
1506
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1506
+            if (strpos(strtolower($message), 'error')) {
1507 1507
                 $type = 'error';
1508
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1508
+            } elseif (strpos(strtolower($message), 'success')) {
1509 1509
                 $type = 'success';
1510 1510
             } else {
1511 1511
                 $type = 'info';
1512 1512
             }
1513 1513
 
1514
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1514
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1515 1515
 
1516
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1516
+            echo '<div class="' . implode(' ', $classes) . '">';
1517 1517
                 // Loop message codes and display messages
1518 1518
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1519 1519
             echo '</div>';
1520 1520
         }
1521 1521
 
1522 1522
         // Remove all of the cart saving messages
1523
-        $wpi_session->set( 'wpinv_cart_messages', null );
1523
+        $wpi_session->set('wpinv_cart_messages', null);
1524 1524
     }
1525 1525
 }
1526
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1526
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1527 1527
 
1528 1528
 function wpinv_discount_field() {
1529
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1529
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1530 1530
         return; // Only show before a payment method has been selected if ajax is disabled
1531 1531
     }
1532 1532
 
1533
-    if ( !wpinv_is_checkout() ) {
1533
+    if (!wpinv_is_checkout()) {
1534 1534
         return;
1535 1535
     }
1536 1536
 
1537
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1537
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1538 1538
     ?>
1539 1539
     <div id="wpinv-discount-field" class="panel panel-default">
1540 1540
         <div class="panel-body">
1541 1541
             <p>
1542
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1543
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1542
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1543
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1544 1544
             </p>
1545 1545
             <div class="form-group row">
1546 1546
                 <div class="col-sm-4">
1547
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1547
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1548 1548
                 </div>
1549 1549
                 <div class="col-sm-3">
1550
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1550
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1551 1551
                 </div>
1552 1552
                 <div class="col-sm-12 wpinv-discount-msg">
1553 1553
                     <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div>
@@ -1559,10 +1559,10 @@  discard block
 block discarded – undo
1559 1559
 <?php
1560 1560
     }
1561 1561
 }
1562
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1562
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1563 1563
 
1564 1564
 function wpinv_agree_to_terms_js() {
1565
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1565
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1566 1566
 ?>
1567 1567
 <script type="text/javascript">
1568 1568
     jQuery(document).ready(function($){
@@ -1577,126 +1577,126 @@  discard block
 block discarded – undo
1577 1577
 <?php
1578 1578
     }
1579 1579
 }
1580
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1580
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1581 1581
 
1582 1582
 function wpinv_payment_mode_select() {
1583
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1584
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1583
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1584
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1585 1585
     $page_URL = wpinv_get_current_page_url();
1586
-    $invoice = wpinv_get_invoice( 0, true );
1586
+    $invoice = wpinv_get_invoice(0, true);
1587 1587
     
1588 1588
     do_action('wpinv_payment_mode_top');
1589 1589
     $invoice_id = (int)$invoice->ID;
1590
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1590
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1591 1591
     ?>
1592
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>>
1593
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1592
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>>
1593
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1594 1594
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1595
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1595
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1596 1596
                 <div class="panel-body list-group wpi-payment_methods">
1597 1597
                     <?php
1598
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1598
+                    do_action('wpinv_payment_mode_before_gateways');
1599 1599
                     
1600
-                    if(!empty($gateways)){
1601
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1602
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1603
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1604
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1600
+                    if (!empty($gateways)) {
1601
+	                    foreach ($gateways as $gateway_id => $gateway) {
1602
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1603
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1604
+		                    $description = wpinv_get_gateway_description($gateway_id);
1605 1605
 		                    ?>
1606 1606
 		                    <div class="list-group-item">
1607 1607
 			                    <div class="radio">
1608
-				                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1608
+				                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label>
1609 1609
 			                    </div>
1610
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1611
-				                    <?php if ( !empty( $description ) ) { ?>
1612
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1610
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1611
+				                    <?php if (!empty($description)) { ?>
1612
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1613 1613
 				                    <?php } ?>
1614
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1614
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1615 1615
 			                    </div>
1616 1616
 		                    </div>
1617 1617
 		                    <?php
1618 1618
 	                    }
1619
-                    }else{
1620
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1619
+                    } else {
1620
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1621 1621
                     }
1622 1622
 
1623
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1623
+                    do_action('wpinv_payment_mode_after_gateways');
1624 1624
                     ?>
1625 1625
                 </div>
1626 1626
             </div>
1627
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1627
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1628 1628
     </div>
1629 1629
     <?php
1630 1630
     do_action('wpinv_payment_mode_bottom');
1631 1631
 }
1632
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1632
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1633 1633
 
1634 1634
 function wpinv_checkout_billing_info() {    
1635
-    if ( wpinv_is_checkout() ) {
1635
+    if (wpinv_is_checkout()) {
1636 1636
         $logged_in          = is_user_logged_in();
1637 1637
         $billing_details    = wpinv_checkout_billing_details();
1638
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1638
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1639 1639
         ?>
1640 1640
         <div id="wpinv-fields" class="clearfix">
1641 1641
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1642
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1642
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1643 1643
                 <div id="wpinv-fields-box" class="panel-body">
1644
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1644
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1645 1645
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1646
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1646
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1647 1647
                         <?php
1648
-                        echo wpinv_html_text( array(
1648
+                        echo wpinv_html_text(array(
1649 1649
                                 'id'            => 'wpinv_first_name',
1650 1650
                                 'name'          => 'wpinv_first_name',
1651 1651
                                 'value'         => $billing_details['first_name'],
1652 1652
                                 'class'         => 'wpi-input form-control required',
1653
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1654
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1655
-                            ) );
1653
+                                'placeholder'   => __('First name', 'invoicing'),
1654
+                                'required'      => (bool)wpinv_get_option('fname_mandatory'),
1655
+                            ));
1656 1656
                         ?>
1657 1657
                     </p>
1658 1658
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1659
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1659
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1660 1660
                         <?php
1661
-                        echo wpinv_html_text( array(
1661
+                        echo wpinv_html_text(array(
1662 1662
                                 'id'            => 'wpinv_last_name',
1663 1663
                                 'name'          => 'wpinv_last_name',
1664 1664
                                 'value'         => $billing_details['last_name'],
1665 1665
                                 'class'         => 'wpi-input form-control',
1666
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1667
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1668
-                            ) );
1666
+                                'placeholder'   => __('Last name', 'invoicing'),
1667
+                                'required'      => (bool)wpinv_get_option('lname_mandatory'),
1668
+                            ));
1669 1669
                         ?>
1670 1670
                     </p>
1671 1671
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1672
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1672
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1673 1673
                         <?php
1674
-                        echo wpinv_html_text( array(
1674
+                        echo wpinv_html_text(array(
1675 1675
                                 'id'            => 'wpinv_address',
1676 1676
                                 'name'          => 'wpinv_address',
1677 1677
                                 'value'         => $billing_details['address'],
1678 1678
                                 'class'         => 'wpi-input form-control required',
1679
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1680
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1681
-                            ) );
1679
+                                'placeholder'   => __('Address', 'invoicing'),
1680
+                                'required'      => (bool)wpinv_get_option('address_mandatory'),
1681
+                            ));
1682 1682
                         ?>
1683 1683
                     </p>
1684 1684
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1685
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1685
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1686 1686
                         <?php
1687
-                        echo wpinv_html_text( array(
1687
+                        echo wpinv_html_text(array(
1688 1688
                                 'id'            => 'wpinv_city',
1689 1689
                                 'name'          => 'wpinv_city',
1690 1690
                                 'value'         => $billing_details['city'],
1691 1691
                                 'class'         => 'wpi-input form-control required',
1692
-                                'placeholder'   => __( 'City', 'invoicing' ),
1693
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1694
-                            ) );
1692
+                                'placeholder'   => __('City', 'invoicing'),
1693
+                                'required'      => (bool)wpinv_get_option('city_mandatory'),
1694
+                            ));
1695 1695
                         ?>
1696 1696
                     </p>
1697 1697
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1698
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1699
-                        <?php echo wpinv_html_select( array(
1698
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1699
+                        <?php echo wpinv_html_select(array(
1700 1700
                             'options'          => wpinv_get_country_list(),
1701 1701
                             'name'             => 'wpinv_country',
1702 1702
                             'id'               => 'wpinv_country',
@@ -1704,16 +1704,16 @@  discard block
 block discarded – undo
1704 1704
                             'show_option_all'  => false,
1705 1705
                             'show_option_none' => false,
1706 1706
                             'class'            => 'wpi-input form-control required',
1707
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1708
-                            'required'          => (bool)wpinv_get_option( 'country_mandatory' ),
1709
-                        ) ); ?>
1707
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1708
+                            'required'          => (bool)wpinv_get_option('country_mandatory'),
1709
+                        )); ?>
1710 1710
                     </p>
1711 1711
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1712
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1712
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1713 1713
                         <?php
1714
-                        $states = wpinv_get_country_states( $selected_country );
1715
-                        if( !empty( $states ) ) {
1716
-                            echo wpinv_html_select( array(
1714
+                        $states = wpinv_get_country_states($selected_country);
1715
+                        if (!empty($states)) {
1716
+                            echo wpinv_html_select(array(
1717 1717
                                 'options'          => $states,
1718 1718
                                 'name'             => 'wpinv_state',
1719 1719
                                 'id'               => 'wpinv_state',
@@ -1721,61 +1721,61 @@  discard block
 block discarded – undo
1721 1721
                                 'show_option_all'  => false,
1722 1722
                                 'show_option_none' => false,
1723 1723
                                 'class'            => 'wpi-input form-control required',
1724
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1725
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1726
-                            ) );
1724
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1725
+                                'required'         => (bool)wpinv_get_option('state_mandatory'),
1726
+                            ));
1727 1727
                         } else {
1728
-                            echo wpinv_html_text( array(
1728
+                            echo wpinv_html_text(array(
1729 1729
                                 'name'          => 'wpinv_state',
1730 1730
                                 'value'         => $billing_details['state'],
1731 1731
                                 'id'            => 'wpinv_state',
1732 1732
                                 'class'         => 'wpi-input form-control required',
1733
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1734
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1735
-                            ) );
1733
+                                'placeholder'   => __('State / Province', 'invoicing'),
1734
+                                'required'      => (bool)wpinv_get_option('state_mandatory'),
1735
+                            ));
1736 1736
                         }
1737 1737
                         ?>
1738 1738
                     </p>
1739 1739
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1740
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1740
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1741 1741
                         <?php
1742
-                        echo wpinv_html_text( array(
1742
+                        echo wpinv_html_text(array(
1743 1743
                                 'name'          => 'wpinv_zip',
1744 1744
                                 'value'         => $billing_details['zip'],
1745 1745
                                 'id'            => 'wpinv_zip',
1746 1746
                                 'class'         => 'wpi-input form-control',
1747
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1748
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1749
-                            ) );
1747
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1748
+                                'required'      => (bool)wpinv_get_option('zip_mandatory'),
1749
+                            ));
1750 1750
                         ?>
1751 1751
                     </p>
1752 1752
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1753
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1753
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1754 1754
                         <?php
1755
-                        echo wpinv_html_text( array(
1755
+                        echo wpinv_html_text(array(
1756 1756
                                 'id'            => 'wpinv_phone',
1757 1757
                                 'name'          => 'wpinv_phone',
1758 1758
                                 'value'         => $billing_details['phone'],
1759 1759
                                 'class'         => 'wpi-input form-control',
1760
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1761
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1762
-                            ) );
1760
+                                'placeholder'   => __('Phone', 'invoicing'),
1761
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1762
+                            ));
1763 1763
                         ?>
1764 1764
                     </p>
1765
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1765
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1766 1766
                     <div class="clearfix"></div>
1767 1767
                 </div>
1768 1768
             </div>
1769
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1769
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1770 1770
         </div>
1771 1771
         <?php
1772 1772
     }
1773 1773
 }
1774
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1774
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1775 1775
 
1776 1776
 function wpinv_checkout_hidden_fields() {
1777 1777
 ?>
1778
-    <?php if ( is_user_logged_in() ) { ?>
1778
+    <?php if (is_user_logged_in()) { ?>
1779 1779
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1780 1780
     <?php } ?>
1781 1781
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1785,9 +1785,9 @@  discard block
 block discarded – undo
1785 1785
 function wpinv_checkout_button_purchase() {
1786 1786
     ob_start();
1787 1787
 ?>
1788
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1788
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1789 1789
 <?php
1790
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1790
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1791 1791
 }
1792 1792
 
1793 1793
 function wpinv_checkout_total() {
@@ -1796,96 +1796,96 @@  discard block
 block discarded – undo
1796 1796
 <div id="wpinv_checkout_total" class="panel panel-info">
1797 1797
     <div class="panel-body">
1798 1798
     <?php
1799
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1799
+    do_action('wpinv_purchase_form_before_checkout_total');
1800 1800
     ?>
1801
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1801
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1802 1802
     <?php
1803
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1803
+    do_action('wpinv_purchase_form_after_checkout_total');
1804 1804
     ?>
1805 1805
     </div>
1806 1806
 </div>
1807 1807
 <?php
1808 1808
 }
1809
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1809
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1810 1810
 
1811 1811
 function wpinv_checkout_submit() {
1812 1812
 ?>
1813 1813
 <div id="wpinv_purchase_submit" class="panel panel-success">
1814 1814
     <div class="panel-body text-center">
1815 1815
     <?php
1816
-    do_action( 'wpinv_purchase_form_before_submit' );
1816
+    do_action('wpinv_purchase_form_before_submit');
1817 1817
     wpinv_checkout_hidden_fields();
1818 1818
     echo wpinv_checkout_button_purchase();
1819
-    do_action( 'wpinv_purchase_form_after_submit' );
1819
+    do_action('wpinv_purchase_form_after_submit');
1820 1820
     ?>
1821 1821
     </div>
1822 1822
 </div>
1823 1823
 <?php
1824 1824
 }
1825
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1825
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1826 1826
 
1827
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1828
-    $invoice = wpinv_get_invoice( $invoice_id );
1827
+function wpinv_receipt_billing_address($invoice_id = 0) {
1828
+    $invoice = wpinv_get_invoice($invoice_id);
1829 1829
     
1830
-    if ( empty( $invoice ) ) {
1830
+    if (empty($invoice)) {
1831 1831
         return NULL;
1832 1832
     }
1833 1833
     
1834 1834
     $billing_details = $invoice->get_user_info();
1835 1835
     $address_row = '';
1836
-    if ( $address = $billing_details['address'] ) {
1837
-        $address_row .= wpautop( wp_kses_post( $address ) );
1836
+    if ($address = $billing_details['address']) {
1837
+        $address_row .= wpautop(wp_kses_post($address));
1838 1838
     }
1839 1839
     
1840 1840
     $address_fields = array();
1841
-    if ( !empty( $billing_details['city'] ) ) {
1841
+    if (!empty($billing_details['city'])) {
1842 1842
         $address_fields[] = $billing_details['city'];
1843 1843
     }
1844 1844
     
1845
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1846
-    if ( !empty( $billing_details['state'] ) ) {
1847
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1845
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1846
+    if (!empty($billing_details['state'])) {
1847
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1848 1848
     }
1849 1849
     
1850
-    if ( !empty( $billing_country ) ) {
1851
-        $address_fields[] = wpinv_country_name( $billing_country );
1850
+    if (!empty($billing_country)) {
1851
+        $address_fields[] = wpinv_country_name($billing_country);
1852 1852
     }
1853 1853
     
1854
-    if ( !empty( $address_fields ) ) {
1855
-        $address_fields = implode( ", ", $address_fields );
1854
+    if (!empty($address_fields)) {
1855
+        $address_fields = implode(", ", $address_fields);
1856 1856
         
1857
-        if ( !empty( $billing_details['zip'] ) ) {
1857
+        if (!empty($billing_details['zip'])) {
1858 1858
             $address_fields .= ' ' . $billing_details['zip'];
1859 1859
         }
1860 1860
         
1861
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1861
+        $address_row .= wpautop(wp_kses_post($address_fields));
1862 1862
     }
1863 1863
     ob_start();
1864 1864
     ?>
1865 1865
     <table class="table table-bordered table-sm wpi-billing-details">
1866 1866
         <tbody>
1867 1867
             <tr class="wpi-receipt-name">
1868
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1869
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1868
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1869
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1870 1870
             </tr>
1871 1871
             <tr class="wpi-receipt-email">
1872
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1873
-                <td><?php echo $billing_details['email'] ;?></td>
1872
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1873
+                <td><?php echo $billing_details['email']; ?></td>
1874 1874
             </tr>
1875
-            <?php if ( $billing_details['company'] ) { ?>
1875
+            <?php if ($billing_details['company']) { ?>
1876 1876
             <tr class="wpi-receipt-company">
1877
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1878
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1877
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1878
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1879 1879
             </tr>
1880 1880
             <?php } ?>
1881 1881
             <tr class="wpi-receipt-address">
1882
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1883
-                <td><?php echo $address_row ;?></td>
1882
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1883
+                <td><?php echo $address_row; ?></td>
1884 1884
             </tr>
1885
-            <?php if ( $billing_details['phone'] ) { ?>
1885
+            <?php if ($billing_details['phone']) { ?>
1886 1886
             <tr class="wpi-receipt-phone">
1887
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1888
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1887
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1888
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1889 1889
             </tr>
1890 1890
             <?php } ?>
1891 1891
         </tbody>
@@ -1893,98 +1893,98 @@  discard block
 block discarded – undo
1893 1893
     <?php
1894 1894
     $output = ob_get_clean();
1895 1895
     
1896
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1896
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1897 1897
 
1898 1898
     echo $output;
1899 1899
 }
1900 1900
 
1901
-function wpinv_filter_success_page_content( $content ) {
1902
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1903
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1904
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1901
+function wpinv_filter_success_page_content($content) {
1902
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1903
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1904
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1905 1905
         }
1906 1906
     }
1907 1907
 
1908 1908
     return $content;
1909 1909
 }
1910
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1910
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1911 1911
 
1912
-function wpinv_receipt_actions( $invoice ) {
1913
-    if ( !empty( $invoice ) ) {
1912
+function wpinv_receipt_actions($invoice) {
1913
+    if (!empty($invoice)) {
1914 1914
         $actions = array(
1915 1915
             'print'   => array(
1916 1916
                 'url'  => $invoice->get_view_url(),
1917
-                'name' => __( 'Print Invoice', 'invoicing' ),
1917
+                'name' => __('Print Invoice', 'invoicing'),
1918 1918
                 'class' => 'btn-primary',
1919 1919
             ),
1920 1920
             'history'   => array(
1921 1921
                 'url'  => wpinv_get_history_page_uri(),
1922
-                'name' => __( 'Invoice History', 'invoicing' ),
1922
+                'name' => __('Invoice History', 'invoicing'),
1923 1923
                 'class' => 'btn-warning',
1924 1924
             )
1925 1925
         );
1926 1926
 
1927
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1927
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1928 1928
         
1929
-        if ( !empty( $actions ) ) {
1929
+        if (!empty($actions)) {
1930 1930
         ?>
1931 1931
         <div class="wpinv-receipt-actions text-right">
1932
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1933
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1932
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1933
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1934 1934
             <?php } ?>
1935 1935
         </div>
1936 1936
         <?php
1937 1937
         }
1938 1938
     }
1939 1939
 }
1940
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1940
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1941 1941
 
1942
-function wpinv_invoice_link( $invoice_id ) {
1943
-    $invoice = wpinv_get_invoice( $invoice_id );
1942
+function wpinv_invoice_link($invoice_id) {
1943
+    $invoice = wpinv_get_invoice($invoice_id);
1944 1944
     
1945
-    if ( empty( $invoice ) ) {
1945
+    if (empty($invoice)) {
1946 1946
         return NULL;
1947 1947
     }
1948 1948
     
1949
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1949
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1950 1950
     
1951
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1951
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1952 1952
 }
1953 1953
 
1954
-function wpinv_invoice_subscription_details( $invoice ) {
1955
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1954
+function wpinv_invoice_subscription_details($invoice) {
1955
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1956 1956
         $total_payments = (int)$invoice->get_total_payments();
1957 1957
         $payments       = $invoice->get_child_payments();
1958 1958
         
1959 1959
         $subscription   = $invoice->get_subscription_data();
1960 1960
         
1961
-        if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) {
1961
+        if (!(!empty($subscription) && !empty($subscription['item_id']))) {
1962 1962
             return;
1963 1963
         }
1964 1964
         
1965
-        $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() );
1966
-        $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
1965
+        $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());
1966
+        $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
1967 1967
         
1968 1968
         $subscription_status = $invoice->get_subscription_status();
1969 1969
         
1970 1970
         $status_desc = '';
1971
-        if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) {
1972
-            $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date );
1973
-        } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) {
1974
-            $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date );
1971
+        if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) {
1972
+            $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date);
1973
+        } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) {
1974
+            $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date);
1975 1975
         }
1976 1976
         $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : '';
1977 1977
         ?>
1978 1978
         <div class="wpinv-subscriptions-details">
1979
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1979
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1980 1980
             <table class="table">
1981 1981
                 <thead>
1982 1982
                     <tr>
1983
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1984
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1985
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1986
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1987
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1983
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1984
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1985
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1986
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1987
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1988 1988
                     </tr>
1989 1989
                 </thead>
1990 1990
                 <tbody>
@@ -1993,32 +1993,32 @@  discard block
 block discarded – undo
1993 1993
                         <td><?php echo $invoice->get_subscription_start(); ?></td>
1994 1994
                         <td><?php echo $invoice->get_subscription_end(); ?></td>
1995 1995
                         <td class="text-center"><?php echo $times_billed; ?></td>
1996
-                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?>
1996
+                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?>
1997 1997
                         <?php echo $status_desc; ?>
1998 1998
                         </td>
1999 1999
                     </tr>
2000 2000
                 </tbody>
2001 2001
             </table>
2002 2002
         </div>
2003
-        <?php if ( !empty( $payments ) ) { ?>
2003
+        <?php if (!empty($payments)) { ?>
2004 2004
         <div class="wpinv-renewal-payments">
2005
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2005
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2006 2006
             <table class="table">
2007 2007
                 <thead>
2008 2008
                     <tr>
2009 2009
                         <th>#</th>
2010
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2011
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2012
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2010
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2011
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2012
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2013 2013
                     </tr>
2014 2014
                 </thead>
2015 2015
                 <tbody>
2016
-                    <?php foreach ( $payments as $key => $invoice_id ) { ?>
2016
+                    <?php foreach ($payments as $key => $invoice_id) { ?>
2017 2017
                     <tr>
2018
-                        <th scope="row"><?php echo ( $key + 1 );?></th>
2019
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2020
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2021
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2018
+                        <th scope="row"><?php echo ($key + 1); ?></th>
2019
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2020
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2021
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2022 2022
                     </tr>
2023 2023
                     <?php } ?>
2024 2024
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -2030,52 +2030,52 @@  discard block
 block discarded – undo
2030 2030
     }
2031 2031
 }
2032 2032
 
2033
-function wpinv_cart_total_label( $label, $invoice ) {
2034
-    if ( empty( $invoice ) ) {
2033
+function wpinv_cart_total_label($label, $invoice) {
2034
+    if (empty($invoice)) {
2035 2035
         return $label;
2036 2036
     }
2037 2037
     
2038 2038
     $prefix_label = '';
2039
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {        
2040
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2041
-    } else if ( $invoice->is_renewal() ) {
2042
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2039
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {        
2040
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2041
+    } else if ($invoice->is_renewal()) {
2042
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2043 2043
     }
2044 2044
     
2045
-    if ( $prefix_label != '' ) {
2046
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2045
+    if ($prefix_label != '') {
2046
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2047 2047
     }
2048 2048
     
2049 2049
     return $label;
2050 2050
 }
2051
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2052
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2053
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2051
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2052
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2053
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2054 2054
 
2055
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2055
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2056 2056
 
2057
-function wpinv_invoice_print_description( $invoice ) {
2058
-    if ( empty( $invoice ) ) {
2057
+function wpinv_invoice_print_description($invoice) {
2058
+    if (empty($invoice)) {
2059 2059
         return NULL;
2060 2060
     }
2061
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2061
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2062 2062
         ?>
2063 2063
         <div class="row wpinv-lower">
2064 2064
             <div class="col-sm-12 wpinv-description">
2065
-                <?php echo wpautop( $description ); ?>
2065
+                <?php echo wpautop($description); ?>
2066 2066
             </div>
2067 2067
         </div>
2068 2068
         <?php
2069 2069
     }
2070 2070
 }
2071
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2071
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2072 2072
 
2073
-function wpinv_invoice_print_payment_info( $invoice ) {
2074
-    if ( empty( $invoice ) ) {
2073
+function wpinv_invoice_print_payment_info($invoice) {
2074
+    if (empty($invoice)) {
2075 2075
         return NULL;
2076 2076
     }
2077 2077
     
2078
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2078
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2079 2079
         ?>
2080 2080
         <div class="row wpinv-payments">
2081 2081
             <div class="col-sm-12">
@@ -2087,43 +2087,43 @@  discard block
 block discarded – undo
2087 2087
 }
2088 2088
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2089 2089
 
2090
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2091
-    if ( empty( $note ) ) {
2090
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2091
+    if (empty($note)) {
2092 2092
         return NULL;
2093 2093
     }
2094 2094
     
2095
-    if ( is_int( $note ) ) {
2096
-        $note = get_comment( $note );
2095
+    if (is_int($note)) {
2096
+        $note = get_comment($note);
2097 2097
     }
2098 2098
     
2099
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2099
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2100 2100
         return NULL;
2101 2101
     }
2102 2102
     
2103
-    $note_classes   = array( 'note' );
2104
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2105
-    $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : '';
2106
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2107
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2103
+    $note_classes   = array('note');
2104
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2105
+    $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : '';
2106
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2107
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2108 2108
     
2109 2109
     ob_start();
2110 2110
     ?>
2111
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2111
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2112 2112
         <div class="note_content">
2113
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2113
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2114 2114
         </div>
2115 2115
         <p class="meta">
2116
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2117
-            <?php if($note->comment_author !== 'System') {?>
2118
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2116
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2117
+            <?php if ($note->comment_author !== 'System') {?>
2118
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2119 2119
             <?php } ?>
2120 2120
         </p>
2121 2121
     </li>
2122 2122
     <?php
2123 2123
     $note_content = ob_get_clean();
2124
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2124
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2125 2125
     
2126
-    if ( $echo ) {
2126
+    if ($echo) {
2127 2127
         echo $note_content;
2128 2128
     } else {
2129 2129
         return $note_content;
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = get_post( $value );
14
+            $item = get_post($value);
15 15
 
16
-            if( get_post_type( $item ) != 'wpi_item' ) {
16
+            if (get_post_type($item) != 'wpi_item') {
17 17
                 return false;
18 18
             }
19 19
 
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
 
22 22
         case 'slug':
23 23
         case 'name':
24
-            $posts = get_posts( array(
24
+            $posts = get_posts(array(
25 25
                 'post_type'      => 'wpi_item',
26 26
                 'name'           => $value,
27 27
                 'posts_per_page' => 1,
28 28
                 'post_status'    => 'any'
29
-            ) );
29
+            ));
30 30
 
31 31
             break;
32 32
         case 'custom_id':
33
-            if ( empty( $value ) || empty( $type ) ) {
33
+            if (empty($value) || empty($type)) {
34 34
                 return false;
35 35
             }
36 36
             
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
                 'post_status'    => 'any',
51 51
                 'orderby'        => 'ID',
52 52
                 'order'          => 'ASC',
53
-                'meta_query'     => array( $meta_query )
53
+                'meta_query'     => array($meta_query)
54 54
             );
55 55
             
56
-            $posts = get_posts( $args );
56
+            $posts = get_posts($args);
57 57
 
58 58
             break;
59 59
 
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
             return false;
62 62
     }
63 63
     
64
-    if ( !empty( $posts[0] ) ) {
65
-        return new WPInv_Item( $posts[0]->ID );
64
+    if (!empty($posts[0])) {
65
+        return new WPInv_Item($posts[0]->ID);
66 66
     }
67 67
 
68 68
     return false;
69 69
 }
70 70
 
71
-function wpinv_get_item( $item = 0 ) {
72
-    if ( is_numeric( $item ) ) {
73
-        $item = get_post( $item );
74
-        if ( ! $item || 'wpi_item' !== $item->post_type )
71
+function wpinv_get_item($item = 0) {
72
+    if (is_numeric($item)) {
73
+        $item = get_post($item);
74
+        if (!$item || 'wpi_item' !== $item->post_type)
75 75
             return null;
76 76
         return $item;
77 77
     }
@@ -84,136 +84,136 @@  discard block
 block discarded – undo
84 84
 
85 85
     $item = get_posts($args);
86 86
 
87
-    if ( $item ) {
87
+    if ($item) {
88 88
         return $item[0];
89 89
     }
90 90
 
91 91
     return null;
92 92
 }
93 93
 
94
-function wpinv_is_free_item( $item_id = 0 ) {
95
-    if( empty( $item_id ) ) {
94
+function wpinv_is_free_item($item_id = 0) {
95
+    if (empty($item_id)) {
96 96
         return false;
97 97
     }
98 98
 
99
-    $item = new WPInv_Item( $item_id );
99
+    $item = new WPInv_Item($item_id);
100 100
     
101 101
     return $item->is_free();
102 102
 }
103 103
 
104
-function wpinv_get_item_price( $item_id = 0 ) {
105
-    if( empty( $item_id ) ) {
104
+function wpinv_get_item_price($item_id = 0) {
105
+    if (empty($item_id)) {
106 106
         return false;
107 107
     }
108 108
 
109
-    $item = new WPInv_Item( $item_id );
109
+    $item = new WPInv_Item($item_id);
110 110
     
111 111
     return $item->get_price();
112 112
 }
113 113
 
114
-function wpinv_is_recurring_item( $item_id = 0 ) {
115
-    if( empty( $item_id ) ) {
114
+function wpinv_is_recurring_item($item_id = 0) {
115
+    if (empty($item_id)) {
116 116
         return false;
117 117
     }
118 118
 
119
-    $item = new WPInv_Item( $item_id );
119
+    $item = new WPInv_Item($item_id);
120 120
     
121 121
     return $item->is_recurring();
122 122
 }
123 123
 
124
-function wpinv_item_price( $item_id = 0 ) {
125
-    if( empty( $item_id ) ) {
124
+function wpinv_item_price($item_id = 0) {
125
+    if (empty($item_id)) {
126 126
         return false;
127 127
     }
128 128
 
129
-    $price = wpinv_get_item_price( $item_id );
130
-    $price = wpinv_price( wpinv_format_amount( $price ) );
129
+    $price = wpinv_get_item_price($item_id);
130
+    $price = wpinv_price(wpinv_format_amount($price));
131 131
     
132
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
132
+    return apply_filters('wpinv_item_price', $price, $item_id);
133 133
 }
134 134
 
135
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
136
-    if ( empty( $item_id ) ) {
135
+function wpinv_item_show_price($item_id = 0, $echo = true) {
136
+    if (empty($item_id)) {
137 137
         $item_id = get_the_ID();
138 138
     }
139 139
 
140
-    $price = wpinv_item_price( $item_id );
140
+    $price = wpinv_item_price($item_id);
141 141
 
142
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
142
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
143 143
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
144
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
144
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
145 145
 
146
-    if ( $echo ) {
146
+    if ($echo) {
147 147
         echo $formatted_price;
148 148
     } else {
149 149
         return $formatted_price;
150 150
     }
151 151
 }
152 152
 
153
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
154
-    if ( is_null( $amount_override ) ) {
155
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
153
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
154
+    if (is_null($amount_override)) {
155
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
156 156
     } else {
157 157
         $original_price = $amount_override;
158 158
     }
159 159
     
160 160
     $price = $original_price;
161 161
 
162
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
162
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
163 163
 }
164 164
 
165
-function wpinv_item_custom_singular_name( $item_id ) {
166
-    if( empty( $item_id ) ) {
165
+function wpinv_item_custom_singular_name($item_id) {
166
+    if (empty($item_id)) {
167 167
         return false;
168 168
     }
169 169
 
170
-    $item = new WPInv_Item( $item_id );
170
+    $item = new WPInv_Item($item_id);
171 171
     
172 172
     return $item->get_custom_singular_name();
173 173
 }
174 174
 
175 175
 function wpinv_get_item_types() {
176 176
     $item_types = array(
177
-            'custom'    => __( 'Standard', 'invoicing' ),
178
-            'fee'       => __( 'Fee', 'invoicing' ),
177
+            'custom'    => __('Standard', 'invoicing'),
178
+            'fee'       => __('Fee', 'invoicing'),
179 179
         );
180
-    return apply_filters( 'wpinv_get_item_types', $item_types );
180
+    return apply_filters('wpinv_get_item_types', $item_types);
181 181
 }
182 182
 
183 183
 function wpinv_item_types() {
184 184
     $item_types = wpinv_get_item_types();
185 185
     
186
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
186
+    return (!empty($item_types) ? array_keys($item_types) : array());
187 187
 }
188 188
 
189
-function wpinv_get_item_type( $item_id ) {
190
-    if( empty( $item_id ) ) {
189
+function wpinv_get_item_type($item_id) {
190
+    if (empty($item_id)) {
191 191
         return false;
192 192
     }
193 193
 
194
-    $item = new WPInv_Item( $item_id );
194
+    $item = new WPInv_Item($item_id);
195 195
     
196 196
     return $item->get_type();
197 197
 }
198 198
 
199
-function wpinv_item_type( $item_id ) {
199
+function wpinv_item_type($item_id) {
200 200
     $item_types = wpinv_get_item_types();
201 201
     
202
-    $item_type = wpinv_get_item_type( $item_id );
202
+    $item_type = wpinv_get_item_type($item_id);
203 203
     
204
-    if ( empty( $item_type ) ) {
204
+    if (empty($item_type)) {
205 205
         $item_type = '-';
206 206
     }
207 207
     
208
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
208
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
209 209
 
210
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
210
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
211 211
 }
212 212
 
213
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
213
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
214 214
     global $wpinv_logs;
215 215
     
216
-    if ( empty( $wpinv_logs ) ) {
216
+    if (empty($wpinv_logs)) {
217 217
         return false;
218 218
     }
219 219
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
         'log_type'		=> 'wpi_item'
223 223
     );
224 224
 
225
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
225
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
226 226
 
227 227
     $log_meta = array(
228 228
         'user_info'	=> $user_info,
@@ -232,253 +232,253 @@  discard block
 block discarded – undo
232 232
         'invoice_id'=> $invoice_id,
233 233
     );
234 234
 
235
-    $wpinv_logs->insert_log( $log_data, $log_meta );
235
+    $wpinv_logs->insert_log($log_data, $log_meta);
236 236
 }
237 237
 
238
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
239
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
238
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
239
+    if ('wpi_item' !== get_post_type($item_id))
240 240
         return;
241 241
 
242 242
     global $wpinv_logs;
243 243
     
244
-    if ( empty( $wpinv_logs ) ) {
244
+    if (empty($wpinv_logs)) {
245 245
         return false;
246 246
     }
247 247
 
248 248
     // Remove all log entries related to this item
249
-    $wpinv_logs->delete_logs( $item_id );
249
+    $wpinv_logs->delete_logs($item_id);
250 250
 }
251
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
251
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
252 252
 
253
-function wpinv_get_random_item( $post_ids = true ) {
254
-    wpinv_get_random_items( 1, $post_ids );
253
+function wpinv_get_random_item($post_ids = true) {
254
+    wpinv_get_random_items(1, $post_ids);
255 255
 }
256 256
 
257
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
258
-    if ( $post_ids ) {
259
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
257
+function wpinv_get_random_items($num = 3, $post_ids = true) {
258
+    if ($post_ids) {
259
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
260 260
     } else {
261
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
261
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
262 262
     }
263 263
     
264
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
264
+    $args = apply_filters('wpinv_get_random_items', $args);
265 265
     
266
-    return get_posts( $args );
266
+    return get_posts($args);
267 267
 }
268 268
 
269
-function wpinv_get_item_token( $url = '' ) {
269
+function wpinv_get_item_token($url = '') {
270 270
     $args    = array();
271
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
272
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
271
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
272
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
273 273
 
274
-    $parts   = parse_url( $url );
274
+    $parts   = parse_url($url);
275 275
     $options = array();
276 276
 
277
-    if ( isset( $parts['query'] ) ) {
278
-        wp_parse_str( $parts['query'], $query_args );
277
+    if (isset($parts['query'])) {
278
+        wp_parse_str($parts['query'], $query_args);
279 279
 
280
-        if ( ! empty( $query_args['o'] ) ) {
281
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
280
+        if (!empty($query_args['o'])) {
281
+            $options = explode(':', rawurldecode($query_args['o']));
282 282
 
283
-            if ( in_array( 'ip', $options ) ) {
283
+            if (in_array('ip', $options)) {
284 284
                 $args['ip'] = wpinv_get_ip();
285 285
             }
286 286
 
287
-            if ( in_array( 'ua', $options ) ) {
287
+            if (in_array('ua', $options)) {
288 288
                 $ua = wpinv_get_user_agent();
289
-                $args['user_agent'] = rawurlencode( $ua );
289
+                $args['user_agent'] = rawurlencode($ua);
290 290
             }
291 291
         }
292 292
     }
293 293
 
294
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
294
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
295 295
 
296 296
     $args['secret'] = $secret;
297 297
     $args['token']  = false;
298 298
 
299
-    $url   = add_query_arg( $args, $url );
300
-    $parts = parse_url( $url );
299
+    $url   = add_query_arg($args, $url);
300
+    $parts = parse_url($url);
301 301
 
302
-    if ( ! isset( $parts['path'] ) ) {
302
+    if (!isset($parts['path'])) {
303 303
         $parts['path'] = '';
304 304
     }
305 305
 
306
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
306
+    $token = md5($parts['path'] . '?' . $parts['query']);
307 307
 
308 308
     return $token;
309 309
 }
310 310
 
311
-function wpinv_validate_url_token( $url = '' ) {
311
+function wpinv_validate_url_token($url = '') {
312 312
     $ret   = false;
313
-    $parts = parse_url( $url );
313
+    $parts = parse_url($url);
314 314
 
315
-    if ( isset( $parts['query'] ) ) {
316
-        wp_parse_str( $parts['query'], $query_args );
315
+    if (isset($parts['query'])) {
316
+        wp_parse_str($parts['query'], $query_args);
317 317
 
318
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
318
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
319 319
             'item',
320 320
             'ttl',
321 321
             'token'
322
-        ) );
322
+        ));
323 323
 
324 324
         $remove = array();
325 325
 
326
-        foreach( $query_args as $key => $value ) {
327
-            if( false === in_array( $key, $allowed ) ) {
326
+        foreach ($query_args as $key => $value) {
327
+            if (false === in_array($key, $allowed)) {
328 328
                 $remove[] = $key;
329 329
             }
330 330
         }
331 331
 
332
-        if( ! empty( $remove ) ) {
333
-            $url = remove_query_arg( $remove, $url );
332
+        if (!empty($remove)) {
333
+            $url = remove_query_arg($remove, $url);
334 334
         }
335 335
 
336
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
337
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
336
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
337
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
338 338
         }
339 339
 
340
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
340
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
341 341
             $ret = true;
342 342
         }
343 343
 
344 344
     }
345 345
 
346
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
346
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
347 347
 }
348 348
 
349
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
349
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
350 350
     $cart_items = wpinv_get_cart_contents();
351 351
 
352 352
     $ret = false;
353 353
 
354
-    if ( is_array( $cart_items ) ) {
355
-        foreach ( $cart_items as $item ) {
356
-            if ( $item['id'] == $item_id ) {
354
+    if (is_array($cart_items)) {
355
+        foreach ($cart_items as $item) {
356
+            if ($item['id'] == $item_id) {
357 357
                 $ret = true;
358 358
                 break;
359 359
             }
360 360
         }
361 361
     }
362 362
 
363
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
363
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
364 364
 }
365 365
 
366
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
366
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
367 367
     $tax = 0;
368
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
369
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
370
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
368
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
369
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
370
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
371 371
 
372
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
372
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
373 373
     }
374 374
 
375
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
375
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
376 376
 }
377 377
 
378
-function wpinv_cart_item_price( $item ) {
378
+function wpinv_cart_item_price($item) {
379 379
     $use_taxes  = wpinv_use_taxes();
380
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
381
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
382
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
383
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
384
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
385
-    
386
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
387
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
380
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
381
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
382
+    $options    = isset($item['options']) ? $item['options'] : array();
383
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
384
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
385
+    
386
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
387
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
388 388
             $price += $tax;
389 389
         }
390 390
         
391
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
391
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
392 392
             $price -= $tax;
393 393
         }        
394 394
     }
395 395
 
396
-    $price = wpinv_price( wpinv_format_amount( $price ) );
396
+    $price = wpinv_price(wpinv_format_amount($price));
397 397
 
398
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
398
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
399 399
 }
400 400
 
401
-function wpinv_cart_item_subtotal( $item ) {
402
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
403
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
401
+function wpinv_cart_item_subtotal($item) {
402
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
403
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
404 404
 
405
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
405
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
406 406
 }
407 407
 
408
-function wpinv_cart_item_tax( $item ) {
408
+function wpinv_cart_item_tax($item) {
409 409
     $tax        = '';
410 410
     $tax_rate   = '';
411 411
     
412
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
413
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
414
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
415
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
412
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
413
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
414
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
415
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
416 416
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
417 417
     }
418 418
     
419
-    $tax        = $tax . $tax_rate;
419
+    $tax = $tax . $tax_rate;
420 420
     
421
-    if ( $tax === '' ) {
421
+    if ($tax === '') {
422 422
         $tax = 0; // Zero tax
423 423
     }
424 424
 
425
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
425
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
426 426
 }
427 427
 
428
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
428
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
429 429
     $price = 0;
430 430
     
431 431
     // Set custom price
432
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
432
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
433 433
         $price = $cart_item['custom_price'];
434 434
     } else {
435
-        $variable_prices = wpinv_has_variable_prices( $item_id );
435
+        $variable_prices = wpinv_has_variable_prices($item_id);
436 436
 
437
-        if ( $variable_prices ) {
438
-            $prices = wpinv_get_variable_prices( $item_id );
437
+        if ($variable_prices) {
438
+            $prices = wpinv_get_variable_prices($item_id);
439 439
 
440
-            if ( $prices ) {
441
-                if( ! empty( $options ) ) {
442
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
440
+            if ($prices) {
441
+                if (!empty($options)) {
442
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
443 443
                 } else {
444 444
                     $price = false;
445 445
                 }
446 446
             }
447 447
         }
448 448
 
449
-        if( ! $variable_prices || false === $price ) {
449
+        if (!$variable_prices || false === $price) {
450 450
             // Get the standard Item price if not using variable prices
451
-            $price = wpinv_get_item_price( $item_id );
451
+            $price = wpinv_get_item_price($item_id);
452 452
         }
453 453
     }
454 454
 
455
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
456
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
455
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
456
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
457 457
     }
458 458
 
459
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
459
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
460 460
 }
461 461
 
462
-function wpinv_get_cart_item_price_id( $item = array() ) {
463
-    if( isset( $item['item_number'] ) ) {
464
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
462
+function wpinv_get_cart_item_price_id($item = array()) {
463
+    if (isset($item['item_number'])) {
464
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
465 465
     } else {
466
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
466
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
467 467
     }
468 468
     return $price_id;
469 469
 }
470 470
 
471
-function wpinv_get_cart_item_price_name( $item = array() ) {
472
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
473
-    $prices   = wpinv_get_variable_prices( $item['id'] );
474
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
475
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
471
+function wpinv_get_cart_item_price_name($item = array()) {
472
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
473
+    $prices   = wpinv_get_variable_prices($item['id']);
474
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
475
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
476 476
 }
477 477
 
478
-function wpinv_get_cart_item_name( $item = array() ) {
479
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
478
+function wpinv_get_cart_item_name($item = array()) {
479
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
480 480
 
481
-    if ( empty( $item_title ) ) {
481
+    if (empty($item_title)) {
482 482
         $item_title = $item['id'];
483 483
     }
484 484
 
@@ -488,23 +488,23 @@  discard block
 block discarded – undo
488 488
     }
489 489
     */
490 490
 
491
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
491
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
492 492
 }
493 493
 
494
-function wpinv_has_variable_prices( $item_id = 0 ) {
494
+function wpinv_has_variable_prices($item_id = 0) {
495 495
     return false;
496 496
 }
497 497
 
498
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
498
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
499 499
     $cart_items = wpinv_get_cart_contents();
500 500
 
501
-    if ( !is_array( $cart_items ) ) {
501
+    if (!is_array($cart_items)) {
502 502
         return false; // Empty cart
503 503
     } else {
504
-        foreach ( $cart_items as $position => $item ) {
505
-            if ( $item['id'] == $item_id ) {
506
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
507
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
504
+        foreach ($cart_items as $position => $item) {
505
+            if ($item['id'] == $item_id) {
506
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
507
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
508 508
                         return $position;
509 509
                     }
510 510
                 } else {
@@ -517,80 +517,80 @@  discard block
 block discarded – undo
517 517
     return false; // Not found
518 518
 }
519 519
 
520
-function wpinv_get_cart_item_quantity( $item ) {
521
-    if ( wpinv_item_quantities_enabled() ) {
522
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
520
+function wpinv_get_cart_item_quantity($item) {
521
+    if (wpinv_item_quantities_enabled()) {
522
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
523 523
     } else {
524 524
         $quantity = 1;
525 525
     }
526 526
     
527
-    if ( $quantity < 1 ) {
527
+    if ($quantity < 1) {
528 528
         $quantity = 1;
529 529
     }
530 530
     
531
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
531
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
532 532
 }
533 533
 
534
-function wpinv_get_item_suffix( $item, $html = true ) {
535
-    if ( empty( $item ) ) {
534
+function wpinv_get_item_suffix($item, $html = true) {
535
+    if (empty($item)) {
536 536
         return NULL;
537 537
     }
538 538
     
539
-    if ( is_int( $item ) ) {
540
-        $item = new WPInv_Item( $item );
539
+    if (is_int($item)) {
540
+        $item = new WPInv_Item($item);
541 541
     }
542 542
     
543
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
543
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
544 544
         return NULL;
545 545
     }
546 546
     
547
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
547
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
548 548
     
549
-    if ( !$html && $suffix ) {
550
-        $suffix = strip_tags( $suffix );
549
+    if (!$html && $suffix) {
550
+        $suffix = strip_tags($suffix);
551 551
     }
552 552
     
553
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
553
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
554 554
 }
555 555
 
556
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
557
-    if ( empty( $item ) ) {
556
+function wpinv_remove_item($item = 0, $force_delete = false) {
557
+    if (empty($item)) {
558 558
         return NULL;
559 559
     }
560 560
     
561
-    if ( is_int( $item ) ) {
562
-        $item = new WPInv_Item( $item );
561
+    if (is_int($item)) {
562
+        $item = new WPInv_Item($item);
563 563
     }
564 564
     
565
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
565
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
566 566
         return NULL;
567 567
     }
568 568
     
569
-    do_action( 'wpinv_pre_delete_item', $item );
569
+    do_action('wpinv_pre_delete_item', $item);
570 570
 
571
-    wp_delete_post( $item->ID, $force_delete );
571
+    wp_delete_post($item->ID, $force_delete);
572 572
 
573
-    do_action( 'wpinv_post_delete_item', $item );
573
+    do_action('wpinv_post_delete_item', $item);
574 574
 }
575 575
 
576
-function wpinv_can_delete_item( $post_id ) {
577
-    $return = current_user_can( 'manage_options' ) ? true : false;
576
+function wpinv_can_delete_item($post_id) {
577
+    $return = current_user_can('manage_options') ? true : false;
578 578
     
579
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
579
+    if ($return && wpinv_item_in_use($post_id)) {
580 580
         $return = false; // Don't delete item already use in invoices.
581 581
     }
582 582
     
583
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
583
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
584 584
 }
585 585
 
586 586
 function wpinv_admin_action_delete() {
587 587
     $screen = get_current_screen();
588 588
     
589
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
589
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
590 590
         $post_ids = array();
591 591
         
592
-        foreach ( $_REQUEST['post'] as $post_id ) {
593
-            if ( !wpinv_can_delete_item( $post_id ) ) {
592
+        foreach ($_REQUEST['post'] as $post_id) {
593
+            if (!wpinv_can_delete_item($post_id)) {
594 594
                 continue;
595 595
             }
596 596
             
@@ -600,80 +600,80 @@  discard block
 block discarded – undo
600 600
         $_REQUEST['post'] = $post_ids;
601 601
     }
602 602
 }
603
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
604
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
603
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
604
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
605 605
 
606
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
607
-    if ( $post->post_type == 'wpi_item' ) {
608
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
606
+function wpinv_check_delete_item($check, $post, $force_delete) {
607
+    if ($post->post_type == 'wpi_item') {
608
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
609 609
             return true;
610 610
         }
611 611
     }
612 612
     
613 613
     return $check;
614 614
 }
615
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
615
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
616 616
 
617
-function wpinv_item_in_use( $item_id ) {
617
+function wpinv_item_in_use($item_id) {
618 618
     global $wpdb, $wpi_items_in_use;
619 619
     
620
-    if ( !$item_id > 0 ) {
620
+    if (!$item_id > 0) {
621 621
         return false;
622 622
     }
623 623
     
624
-    if ( !empty( $wpi_items_in_use ) ) {
625
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
624
+    if (!empty($wpi_items_in_use)) {
625
+        if (isset($wpi_items_in_use[$item_id])) {
626 626
             return $wpi_items_in_use[$item_id];
627 627
         }
628 628
     } else {
629 629
         $wpi_items_in_use = array();
630 630
     }
631 631
     
632
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
632
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
633 633
     
634
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
635
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
634
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
635
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
636 636
     
637 637
     $wpi_items_in_use[$item_id] = $in_use;
638 638
     
639 639
     return $in_use;
640 640
 }
641 641
 
642
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
642
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
643 643
     // Set some defaults
644 644
     $defaults = array(
645
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
646
-        'title'                => '',                                                      // Required. Item title.
647
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
648
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
649
-        'status'               => 'pending',                                               // Optional. pending, publish
650
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
651
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
652
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
653
-        'excerpt'              => '',                                                      // Optional. Item short description
645
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
646
+        'title'                => '', // Required. Item title.
647
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
648
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
649
+        'status'               => 'pending', // Optional. pending, publish
650
+        'custom_name'          => '', // Optional. Plural sub title for item.
651
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
652
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
653
+        'excerpt'              => '', // Optional. Item short description
654 654
         /* Recurring item fields */
655
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
656
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
657
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
658
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
659
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
660
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
661
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
655
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
656
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
657
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
658
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
659
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
660
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
661
+        'trial_interval'       => 0, // Optional. Any integer number.
662 662
     );
663 663
     
664
-    $data = wp_parse_args( $args, $defaults );
664
+    $data = wp_parse_args($args, $defaults);
665 665
     
666
-    if ( empty( $data['type'] ) ) {
666
+    if (empty($data['type'])) {
667 667
         $data['type'] = 'custom';
668 668
     }
669 669
     
670
-    if ( !empty( $data['custom_id'] ) ) {
671
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
670
+    if (!empty($data['custom_id'])) {
671
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
672 672
     } else {
673 673
         $item = NULL;
674 674
     }
675 675
     
676
-    if ( !$force_update && !empty( $item ) ) {
676
+    if (!$force_update && !empty($item)) {
677 677
         return $item;
678 678
     }
679 679
         
@@ -682,18 +682,18 @@  discard block
 block discarded – undo
682 682
     $meta['custom_id']              = $data['custom_id'];
683 683
     $meta['custom_singular_name']   = $data['custom_singular_name'];
684 684
     $meta['custom_name']            = $data['custom_name'];
685
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
685
+    $meta['price']                  = wpinv_round_amount($data['price']);
686 686
     $meta['vat_rule']               = $data['vat_rule'];
687 687
     $meta['vat_class']              = '_standard';
688 688
     
689
-    if ( !empty( $data['is_recurring'] ) ) {
689
+    if (!empty($data['is_recurring'])) {
690 690
         $meta['is_recurring']       = $data['is_recurring'];
691 691
         $meta['recurring_period']   = $data['recurring_period'];
692
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
693
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
692
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
693
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
694 694
         $meta['free_trial']         = $data['free_trial'];
695 695
         $meta['trial_period']       = $data['trial_period'];
696
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
696
+        $meta['trial_interval']     = absint($data['trial_interval']);
697 697
     } else {
698 698
         $meta['is_recurring']       = 0;
699 699
         $meta['recurring_period']   = '';
@@ -704,18 +704,18 @@  discard block
 block discarded – undo
704 704
         $meta['trial_interval']     = '';
705 705
     }
706 706
     
707
-    $post_data  = array( 
707
+    $post_data = array( 
708 708
         'post_title'    => $data['title'],
709 709
         'post_excerpt'  => $data['excerpt'],
710 710
         'post_status'   => $data['status'],
711 711
         'meta'          => $meta
712 712
     );
713 713
 
714
-    if ( !empty( $item ) ) {
715
-        $item->update( $post_data, $wp_error );
714
+    if (!empty($item)) {
715
+        $item->update($post_data, $wp_error);
716 716
     } else {
717 717
         $item = new WPInv_Item();
718
-        $item->create( $post_data, $wp_error );
718
+        $item->create($post_data, $wp_error);
719 719
     }
720 720
     
721 721
     return $item;
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -7,89 +7,89 @@  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
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
     
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
     
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
     
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double)$amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double)$amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $trashed = false ) {
92
+function wpinv_get_invoice_statuses($trashed = false) {
93 93
     global $post;
94 94
     $invoice_statuses = array();
95 95
     $invoice_statuses = array(
@@ -103,32 +103,32 @@  discard block
 block discarded – undo
103 103
         'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
     
106
-    if ( $trashed ) {
107
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
106
+    if ($trashed) {
107
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
108 108
     }
109 109
 
110
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
110
+    return apply_filters('wpinv_statuses', $invoice_statuses);
111 111
 }
112 112
 
113
-function wpinv_status_nicename( $status ) {
113
+function wpinv_status_nicename($status) {
114 114
     $statuses = wpinv_get_invoice_statuses();
115
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
115
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
116 116
 
117 117
     return $status;
118 118
 }
119 119
 
120 120
 function wpinv_get_currency() {
121
-    $currency = wpinv_get_option( 'currency', 'USD' );
121
+    $currency = wpinv_get_option('currency', 'USD');
122 122
     
123
-    return apply_filters( 'wpinv_currency', $currency );
123
+    return apply_filters('wpinv_currency', $currency);
124 124
 }
125 125
 
126
-function wpinv_currency_symbol( $currency = '' ) {
127
-    if ( empty( $currency ) ) {
126
+function wpinv_currency_symbol($currency = '') {
127
+    if (empty($currency)) {
128 128
         $currency = wpinv_get_currency();
129 129
     }
130 130
     
131
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
131
+    $symbols = apply_filters('wpinv_currency_symbols', array(
132 132
         'AED' => 'د.إ',
133 133
         'ARS' => '&#36;',
134 134
         'AUD' => '&#36;',
@@ -180,78 +180,78 @@  discard block
 block discarded – undo
180 180
         'USD' => '&#36;',
181 181
         'VND' => '&#8363;',
182 182
         'ZAR' => '&#82;',
183
-    ) );
183
+    ));
184 184
 
185
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
185
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
186 186
 
187
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
187
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
188 188
 }
189 189
 
190 190
 function wpinv_currency_position() {
191
-    $position = wpinv_get_option( 'currency_position', 'left' );
191
+    $position = wpinv_get_option('currency_position', 'left');
192 192
     
193
-    return apply_filters( 'wpinv_currency_position', $position );
193
+    return apply_filters('wpinv_currency_position', $position);
194 194
 }
195 195
 
196 196
 function wpinv_thousands_separator() {
197
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
197
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
198 198
     
199
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
199
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
200 200
 }
201 201
 
202 202
 function wpinv_decimal_separator() {
203
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
203
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
204 204
     
205
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
205
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
206 206
 }
207 207
 
208 208
 function wpinv_decimals() {
209
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
209
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
210 210
     
211
-    return absint( $decimals );
211
+    return absint($decimals);
212 212
 }
213 213
 
214 214
 function wpinv_get_currencies() {
215 215
     $currencies = array(
216
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
217
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
218
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
219
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
220
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
221
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
222
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
223
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
224
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
225
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
226
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
227
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
228
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
229
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
230
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
231
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
232
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
233
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
234
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
235
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
236
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
237
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
238
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
239
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
240
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
241
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
242
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
243
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
244
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
245
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
216
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
217
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
218
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
219
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
220
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
221
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
222
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
223
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
224
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
225
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
226
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
227
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
228
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
229
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
230
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
231
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
232
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
233
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
234
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
235
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
236
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
237
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
238
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
239
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
240
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
241
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
242
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
243
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
244
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
245
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
246 246
     );
247 247
     
248
-    asort( $currencies );
248
+    asort($currencies);
249 249
 
250
-    return apply_filters( 'wpinv_currencies', $currencies );
250
+    return apply_filters('wpinv_currencies', $currencies);
251 251
 }
252 252
 
253
-function wpinv_price( $amount = '', $currency = '' ) {
254
-    if( empty( $currency ) ) {
253
+function wpinv_price($amount = '', $currency = '') {
254
+    if (empty($currency)) {
255 255
         $currency = wpinv_get_currency();
256 256
     }
257 257
 
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
 
260 260
     $negative = $amount < 0;
261 261
 
262
-    if ( $negative ) {
263
-        $amount = substr( $amount, 1 );
262
+    if ($negative) {
263
+        $amount = substr($amount, 1);
264 264
     }
265 265
 
266
-    $symbol = wpinv_currency_symbol( $currency );
266
+    $symbol = wpinv_currency_symbol($currency);
267 267
 
268
-    if ( $position == 'left' || $position == 'left_space' ) {
269
-        switch ( $currency ) {
268
+    if ($position == 'left' || $position == 'left_space') {
269
+        switch ($currency) {
270 270
             case "GBP" :
271 271
             case "BRL" :
272 272
             case "EUR" :
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
             case "NZD" :
279 279
             case "SGD" :
280 280
             case "JPY" :
281
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
281
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
282 282
                 break;
283 283
             default :
284 284
                 //$price = $currency . ' ' . $amount;
285
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
285
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
286 286
                 break;
287 287
         }
288 288
     } else {
289
-        switch ( $currency ) {
289
+        switch ($currency) {
290 290
             case "GBP" :
291 291
             case "BRL" :
292 292
             case "EUR" :
@@ -297,83 +297,83 @@  discard block
 block discarded – undo
297 297
             case "MXN" :
298 298
             case "SGD" :
299 299
             case "JPY" :
300
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
300
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
301 301
                 break;
302 302
             default :
303 303
                 //$price = $amount . ' ' . $currency;
304
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
304
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
305 305
                 break;
306 306
         }
307 307
     }
308 308
     
309
-    if ( $negative ) {
309
+    if ($negative) {
310 310
         $price = '-' . $price;
311 311
     }
312 312
     
313
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
313
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
314 314
 
315 315
     return $price;
316 316
 }
317 317
 
318
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
318
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
319 319
     $thousands_sep = wpinv_thousands_separator();
320 320
     $decimal_sep   = wpinv_decimal_separator();
321 321
 
322
-    if ( $decimals === NULL ) {
322
+    if ($decimals === NULL) {
323 323
         $decimals = wpinv_decimals();
324 324
     }
325 325
 
326
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
327
-        $whole = substr( $amount, 0, $sep_found );
328
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
326
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
327
+        $whole = substr($amount, 0, $sep_found);
328
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
329 329
         $amount = $whole . '.' . $part;
330 330
     }
331 331
 
332
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
333
-        $amount = str_replace( ',', '', $amount );
332
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
333
+        $amount = str_replace(',', '', $amount);
334 334
     }
335 335
 
336
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
337
-        $amount = str_replace( ' ', '', $amount );
336
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
337
+        $amount = str_replace(' ', '', $amount);
338 338
     }
339 339
 
340
-    if ( empty( $amount ) ) {
340
+    if (empty($amount)) {
341 341
         $amount = 0;
342 342
     }
343 343
     
344
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
345
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
344
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
345
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
346 346
     
347
-    if ( $calculate ) {
348
-        if ( $thousands_sep === "," ) {
349
-            $formatted = str_replace( ",", "", $formatted );
347
+    if ($calculate) {
348
+        if ($thousands_sep === ",") {
349
+            $formatted = str_replace(",", "", $formatted);
350 350
         }
351 351
         
352
-        if ( $decimal_sep === "," ) {
353
-            $formatted = str_replace( ",", ".", $formatted );
352
+        if ($decimal_sep === ",") {
353
+            $formatted = str_replace(",", ".", $formatted);
354 354
         }
355 355
     }
356 356
 
357
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
357
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
358 358
 }
359
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
359
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
360 360
 
361
-function wpinv_sanitize_key( $key ) {
361
+function wpinv_sanitize_key($key) {
362 362
     $raw_key = $key;
363
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
363
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
364 364
 
365
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
365
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
366 366
 }
367 367
 
368
-function wpinv_get_file_extension( $str ) {
369
-    $parts = explode( '.', $str );
370
-    return end( $parts );
368
+function wpinv_get_file_extension($str) {
369
+    $parts = explode('.', $str);
370
+    return end($parts);
371 371
 }
372 372
 
373
-function wpinv_string_is_image_url( $str ) {
374
-    $ext = wpinv_get_file_extension( $str );
373
+function wpinv_string_is_image_url($str) {
374
+    $ext = wpinv_get_file_extension($str);
375 375
 
376
-    switch ( strtolower( $ext ) ) {
376
+    switch (strtolower($ext)) {
377 377
         case 'jpeg';
378 378
         case 'jpg';
379 379
             $return = true;
@@ -389,32 +389,32 @@  discard block
 block discarded – undo
389 389
             break;
390 390
     }
391 391
 
392
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
392
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
393 393
 }
394 394
 
395
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
396
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
395
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
396
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
397 397
     
398
-    if ( true === $should_log ) {
398
+    if (true === $should_log) {
399 399
         $label = '';
400
-        if ( $file && $file !== '' ) {
401
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
400
+        if ($file && $file !== '') {
401
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
402 402
         }
403 403
         
404
-        if ( $title && $title !== '' ) {
404
+        if ($title && $title !== '') {
405 405
             $label = $label !== '' ? $label . ' ' : '';
406 406
             $label .= $title . ' ';
407 407
         }
408 408
         
409
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
409
+        $label = $label !== '' ? trim($label) . ' : ' : '';
410 410
         
411
-        if ( is_array( $log ) || is_object( $log ) ) {
412
-            error_log( $label . print_r( $log, true ) );
411
+        if (is_array($log) || is_object($log)) {
412
+            error_log($label . print_r($log, true));
413 413
         } else {
414
-            error_log( $label . $log );
414
+            error_log($label . $log);
415 415
         }
416 416
         
417
-        if ( $exit ) {
417
+        if ($exit) {
418 418
             exit;
419 419
         }
420 420
     }
@@ -422,65 +422,65 @@  discard block
 block discarded – undo
422 422
 
423 423
 function wpinv_is_ajax_disabled() {
424 424
     $retval = false;
425
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
425
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
426 426
 }
427 427
 
428
-function wpinv_get_current_page_url( $nocache = false ) {
428
+function wpinv_get_current_page_url($nocache = false) {
429 429
     global $wp;
430 430
 
431
-    if ( get_option( 'permalink_structure' ) ) {
432
-        $base = trailingslashit( home_url( $wp->request ) );
431
+    if (get_option('permalink_structure')) {
432
+        $base = trailingslashit(home_url($wp->request));
433 433
     } else {
434
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
435
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
434
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
435
+        $base = remove_query_arg(array('post_type', 'name'), $base);
436 436
     }
437 437
 
438 438
     $scheme = is_ssl() ? 'https' : 'http';
439
-    $uri    = set_url_scheme( $base, $scheme );
439
+    $uri    = set_url_scheme($base, $scheme);
440 440
 
441
-    if ( is_front_page() ) {
442
-        $uri = home_url( '/' );
443
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
441
+    if (is_front_page()) {
442
+        $uri = home_url('/');
443
+    } elseif (wpinv_is_checkout(array(), false)) {
444 444
         $uri = wpinv_get_checkout_uri();
445 445
     }
446 446
 
447
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
447
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
448 448
 
449
-    if ( $nocache ) {
450
-        $uri = wpinv_add_cache_busting( $uri );
449
+    if ($nocache) {
450
+        $uri = wpinv_add_cache_busting($uri);
451 451
     }
452 452
 
453 453
     return $uri;
454 454
 }
455 455
 
456 456
 function wpinv_get_php_arg_separator_output() {
457
-	return ini_get( 'arg_separator.output' );
457
+	return ini_get('arg_separator.output');
458 458
 }
459 459
 
460
-function wpinv_rgb_from_hex( $color ) {
461
-    $color = str_replace( '#', '', $color );
460
+function wpinv_rgb_from_hex($color) {
461
+    $color = str_replace('#', '', $color);
462 462
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
463
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
463
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
464 464
 
465 465
     $rgb      = array();
466
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
467
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
468
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
466
+    $rgb['R'] = hexdec($color{0} . $color{1} );
467
+    $rgb['G'] = hexdec($color{2} . $color{3} );
468
+    $rgb['B'] = hexdec($color{4} . $color{5} );
469 469
 
470 470
     return $rgb;
471 471
 }
472 472
 
473
-function wpinv_hex_darker( $color, $factor = 30 ) {
474
-    $base  = wpinv_rgb_from_hex( $color );
473
+function wpinv_hex_darker($color, $factor = 30) {
474
+    $base  = wpinv_rgb_from_hex($color);
475 475
     $color = '#';
476 476
 
477
-    foreach ( $base as $k => $v ) {
477
+    foreach ($base as $k => $v) {
478 478
         $amount      = $v / 100;
479
-        $amount      = round( $amount * $factor );
479
+        $amount      = round($amount * $factor);
480 480
         $new_decimal = $v - $amount;
481 481
 
482
-        $new_hex_component = dechex( $new_decimal );
483
-        if ( strlen( $new_hex_component ) < 2 ) {
482
+        $new_hex_component = dechex($new_decimal);
483
+        if (strlen($new_hex_component) < 2) {
484 484
             $new_hex_component = "0" . $new_hex_component;
485 485
         }
486 486
         $color .= $new_hex_component;
@@ -489,18 +489,18 @@  discard block
 block discarded – undo
489 489
     return $color;
490 490
 }
491 491
 
492
-function wpinv_hex_lighter( $color, $factor = 30 ) {
493
-    $base  = wpinv_rgb_from_hex( $color );
492
+function wpinv_hex_lighter($color, $factor = 30) {
493
+    $base  = wpinv_rgb_from_hex($color);
494 494
     $color = '#';
495 495
 
496
-    foreach ( $base as $k => $v ) {
496
+    foreach ($base as $k => $v) {
497 497
         $amount      = 255 - $v;
498 498
         $amount      = $amount / 100;
499
-        $amount      = round( $amount * $factor );
499
+        $amount      = round($amount * $factor);
500 500
         $new_decimal = $v + $amount;
501 501
 
502
-        $new_hex_component = dechex( $new_decimal );
503
-        if ( strlen( $new_hex_component ) < 2 ) {
502
+        $new_hex_component = dechex($new_decimal);
503
+        if (strlen($new_hex_component) < 2) {
504 504
             $new_hex_component = "0" . $new_hex_component;
505 505
         }
506 506
         $color .= $new_hex_component;
@@ -509,22 +509,22 @@  discard block
 block discarded – undo
509 509
     return $color;
510 510
 }
511 511
 
512
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
513
-    $hex = str_replace( '#', '', $color );
512
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
513
+    $hex = str_replace('#', '', $color);
514 514
 
515
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
516
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
517
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
515
+    $c_r = hexdec(substr($hex, 0, 2));
516
+    $c_g = hexdec(substr($hex, 2, 2));
517
+    $c_b = hexdec(substr($hex, 4, 2));
518 518
 
519
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
519
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
520 520
 
521 521
     return $brightness > 155 ? $dark : $light;
522 522
 }
523 523
 
524
-function wpinv_format_hex( $hex ) {
525
-    $hex = trim( str_replace( '#', '', $hex ) );
524
+function wpinv_format_hex($hex) {
525
+    $hex = trim(str_replace('#', '', $hex));
526 526
 
527
-    if ( strlen( $hex ) == 3 ) {
527
+    if (strlen($hex) == 3) {
528 528
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
529 529
     }
530 530
 
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
545 545
  * @return string
546 546
  */
547
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
548
-    if ( function_exists( 'mb_strimwidth' ) ) {
549
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
547
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
548
+    if (function_exists('mb_strimwidth')) {
549
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
550 550
     }
551 551
     
552
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
552
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
553 553
 }
554 554
 
555 555
 /**
@@ -561,28 +561,28 @@  discard block
 block discarded – undo
561 561
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
562 562
  * @return int Returns the number of characters in string.
563 563
  */
564
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
565
-    if ( function_exists( 'mb_strlen' ) ) {
566
-        return mb_strlen( $str, $encoding );
564
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
565
+    if (function_exists('mb_strlen')) {
566
+        return mb_strlen($str, $encoding);
567 567
     }
568 568
         
569
-    return strlen( $str );
569
+    return strlen($str);
570 570
 }
571 571
 
572
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
573
-    if ( function_exists( 'mb_strtolower' ) ) {
574
-        return mb_strtolower( $str, $encoding );
572
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
573
+    if (function_exists('mb_strtolower')) {
574
+        return mb_strtolower($str, $encoding);
575 575
     }
576 576
     
577
-    return strtolower( $str );
577
+    return strtolower($str);
578 578
 }
579 579
 
580
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
581
-    if ( function_exists( 'mb_strtoupper' ) ) {
582
-        return mb_strtoupper( $str, $encoding );
580
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
581
+    if (function_exists('mb_strtoupper')) {
582
+        return mb_strtoupper($str, $encoding);
583 583
     }
584 584
     
585
-    return strtoupper( $str );
585
+    return strtoupper($str);
586 586
 }
587 587
 
588 588
 /**
@@ -596,12 +596,12 @@  discard block
 block discarded – undo
596 596
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
597 597
  * @return int Returns the position of the first occurrence of search in the string.
598 598
  */
599
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
600
-    if ( function_exists( 'mb_strpos' ) ) {
601
-        return mb_strpos( $str, $find, $offset, $encoding );
599
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
600
+    if (function_exists('mb_strpos')) {
601
+        return mb_strpos($str, $find, $offset, $encoding);
602 602
     }
603 603
         
604
-    return strpos( $str, $find, $offset );
604
+    return strpos($str, $find, $offset);
605 605
 }
606 606
 
607 607
 /**
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
616 616
  * @return int Returns the position of the last occurrence of search.
617 617
  */
618
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
619
-    if ( function_exists( 'mb_strrpos' ) ) {
620
-        return mb_strrpos( $str, $find, $offset, $encoding );
618
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
619
+    if (function_exists('mb_strrpos')) {
620
+        return mb_strrpos($str, $find, $offset, $encoding);
621 621
     }
622 622
         
623
-    return strrpos( $str, $find, $offset );
623
+    return strrpos($str, $find, $offset);
624 624
 }
625 625
 
626 626
 /**
@@ -635,16 +635,16 @@  discard block
 block discarded – undo
635 635
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
636 636
  * @return string
637 637
  */
638
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
639
-    if ( function_exists( 'mb_substr' ) ) {
640
-        if ( $length === null ) {
641
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
638
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
639
+    if (function_exists('mb_substr')) {
640
+        if ($length === null) {
641
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
642 642
         } else {
643
-            return mb_substr( $str, $start, $length, $encoding );
643
+            return mb_substr($str, $start, $length, $encoding);
644 644
         }
645 645
     }
646 646
         
647
-    return substr( $str, $start, $length );
647
+    return substr($str, $start, $length);
648 648
 }
649 649
 
650 650
 /**
@@ -656,48 +656,48 @@  discard block
 block discarded – undo
656 656
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
657 657
  * @return string The width of string.
658 658
  */
659
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
660
-    if ( function_exists( 'mb_strwidth' ) ) {
661
-        return mb_strwidth( $str, $encoding );
659
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
660
+    if (function_exists('mb_strwidth')) {
661
+        return mb_strwidth($str, $encoding);
662 662
     }
663 663
     
664
-    return wpinv_utf8_strlen( $str, $encoding );
664
+    return wpinv_utf8_strlen($str, $encoding);
665 665
 }
666 666
 
667
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
668
-    if ( function_exists( 'mb_strlen' ) ) {
669
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
667
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
668
+    if (function_exists('mb_strlen')) {
669
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
670 670
         $str_end = "";
671 671
         
672
-        if ( $lower_str_end ) {
673
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
672
+        if ($lower_str_end) {
673
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
674 674
         } else {
675
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
675
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
676 676
         }
677 677
 
678 678
         return $first_letter . $str_end;
679 679
     }
680 680
     
681
-    return ucfirst( $str );
681
+    return ucfirst($str);
682 682
 }
683 683
 
684
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
685
-    if ( function_exists( 'mb_convert_case' ) ) {
686
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
684
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
685
+    if (function_exists('mb_convert_case')) {
686
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
687 687
     }
688 688
     
689
-    return ucwords( $str );
689
+    return ucwords($str);
690 690
 }
691 691
 
692
-function wpinv_period_in_days( $period, $unit ) {
693
-    $period = absint( $period );
692
+function wpinv_period_in_days($period, $unit) {
693
+    $period = absint($period);
694 694
     
695
-    if ( $period > 0 ) {
696
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
695
+    if ($period > 0) {
696
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
697 697
             $period = $period * 7;
698
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
698
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
699 699
             $period = $period * 30;
700
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
700
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
701 701
             $period = $period * 365;
702 702
         }
703 703
     }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  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_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
             self::$instance->reports    = new WPInv_Reports();
24 24
         }
25 25
         
26
-        do_action( 'wpinv_loaded' );
26
+        do_action('wpinv_loaded');
27 27
         
28 28
         return self::$instance;
29 29
     }
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array('WPInv_Shortcodes', 'init'));
48
+        add_action('init', array(&$this, 'wpinv_actions'));
49 49
         
50
-        if ( class_exists( 'BuddyPress' ) ) {
51
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
50
+        if (class_exists('BuddyPress')) {
51
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
52 52
         }
53 53
 
54
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
55 55
         
56
-        if ( is_admin() ) {
57
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
56
+        if (is_admin()) {
57
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
58
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
59 59
         } else {
60
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
60
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
61 61
         }
62 62
         
63 63
         /**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69 69
          */
70
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
70
+        do_action_ref_array('wpinv_actions', array(&$this));
71 71
 
72
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
72
+        add_action('admin_init', array(&$this, 'activation_redirect'));
73 73
     }
74 74
     
75 75
     public function plugins_loaded() {
@@ -83,193 +83,193 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
86
+        $locale = apply_filters('plugin_locale', get_locale(), 'invoicing');
87 87
         
88
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
88
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
89
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
90 90
         
91 91
         /**
92 92
          * Define language constants.
93 93
          */
94
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
94
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
95 95
     }
96 96
         
97 97
     public function includes() {
98 98
         global $wpinv_options;
99 99
         
100
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
100
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
101 101
         $wpinv_options = wpinv_get_settings();
102 102
         
103
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
103
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
104
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
118 118
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
119 119
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
121 121
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
126
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
127
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
128
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
129
-        if ( !class_exists( 'Geodir_EUVat' ) ) {
130
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
126
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
127
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
128
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
129
+        if (!class_exists('Geodir_EUVat')) {
130
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
131 131
         }
132 132
         
133
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
134
-        if ( !empty( $gateways ) ) {
135
-            foreach ( $gateways as $gateway ) {
136
-                if ( $gateway == 'manual' ) {
133
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
134
+        if (!empty($gateways)) {
135
+            foreach ($gateways as $gateway) {
136
+                if ($gateway == 'manual') {
137 137
                     continue;
138 138
                 }
139 139
                 
140 140
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
141 141
                 
142
-                if ( file_exists( $gateway_file ) ) {
143
-                    require_once( $gateway_file );
142
+                if (file_exists($gateway_file)) {
143
+                    require_once($gateway_file);
144 144
                 }
145 145
             }
146 146
         }
147
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
147
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
148 148
         
149
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
152
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
149
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
152
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
153 153
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
155
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
156
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
157
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
158
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
155
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
156
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
157
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
158
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
159 159
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
160 160
         }
161 161
         
162 162
         // include css inliner
163
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
164
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
163
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
164
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
165 165
         }
166 166
         
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
168 168
     }
169 169
     
170 170
     public function init() {
171 171
     }
172 172
     
173 173
     public function admin_init() {
174
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
174
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
175 175
         }
176 176
         
177
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
177
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
178 178
     }
179 179
 
180 180
     public function activation_redirect() {
181 181
         // Bail if no activation redirect
182
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
182
+        if (!get_transient('_wpinv_activation_redirect')) {
183 183
             return;
184 184
         }
185 185
 
186 186
         // Delete the redirect transient
187
-        delete_transient( '_wpinv_activation_redirect' );
187
+        delete_transient('_wpinv_activation_redirect');
188 188
 
189 189
         // Bail if activating from network, or bulk
190
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
190
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
191 191
             return;
192 192
         }
193 193
 
194
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
194
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
195 195
         exit;
196 196
     }
197 197
     
198 198
     public function enqueue_scripts() {
199
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
199
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
200 200
         
201
-        wp_deregister_style( 'font-awesome' );
202
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
203
-        wp_enqueue_style( 'font-awesome' );
201
+        wp_deregister_style('font-awesome');
202
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
203
+        wp_enqueue_style('font-awesome');
204 204
         
205
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
206
-        wp_enqueue_style( 'wpinv_front_style' );
205
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
206
+        wp_enqueue_style('wpinv_front_style');
207 207
                
208 208
         // Register scripts
209
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
210
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
209
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
210
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
211 211
         
212 212
         $localize                         = array();
213
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
214
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
213
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
214
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
215 215
         $localize['currency_symbol']      = wpinv_currency_symbol();
216 216
         $localize['currency_pos']         = wpinv_currency_position();
217 217
         $localize['thousand_sep']         = wpinv_thousands_separator();
218 218
         $localize['decimal_sep']          = wpinv_decimal_separator();
219 219
         $localize['decimals']             = wpinv_decimals();
220 220
         
221
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
221
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
222 222
         
223
-        wp_enqueue_script( 'jquery-blockui' );
224
-        wp_enqueue_script( 'wpinv-front-script' );
225
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
223
+        wp_enqueue_script('jquery-blockui');
224
+        wp_enqueue_script('wpinv-front-script');
225
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
226 226
     }
227 227
     
228 228
     public function admin_enqueue_scripts() {
229 229
         global $post, $pagenow;
230 230
         
231 231
         $post_type  = wpinv_admin_post_type();
232
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
232
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
233 233
         
234
-        wp_deregister_style( 'font-awesome' );
235
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
236
-        wp_enqueue_style( 'font-awesome' );
234
+        wp_deregister_style('font-awesome');
235
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
236
+        wp_enqueue_style('font-awesome');
237 237
         
238
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
239
-        wp_enqueue_style( 'jquery-ui-css' );
238
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
239
+        wp_enqueue_style('jquery-ui-css');
240 240
         
241
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
242
-        wp_enqueue_style( 'jquery-chosen' );
241
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
242
+        wp_enqueue_style('jquery-chosen');
243 243
 
244
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
245
-        wp_enqueue_script( 'jquery-chosen' );
244
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
245
+        wp_enqueue_script('jquery-chosen');
246 246
         
247
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
248
-        wp_enqueue_style( 'wpinv_meta_box_style' );
247
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
248
+        wp_enqueue_style('wpinv_meta_box_style');
249 249
         
250
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
251
-        wp_enqueue_style( 'wpinv_admin_style' );
250
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
251
+        wp_enqueue_style('wpinv_admin_style');
252 252
         
253
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
254
-            wp_enqueue_script( 'jquery-ui-datepicker' );
253
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
254
+            wp_enqueue_script('jquery-ui-datepicker');
255 255
         }
256 256
 
257
-        wp_enqueue_style( 'wp-color-picker' );
258
-        wp_enqueue_script( 'wp-color-picker' );
257
+        wp_enqueue_style('wp-color-picker');
258
+        wp_enqueue_script('wp-color-picker');
259 259
         
260
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
260
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
261 261
         
262
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
263
-        wp_enqueue_script( 'wpinv-admin-script' );
262
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION);
263
+        wp_enqueue_script('wpinv-admin-script');
264 264
         
265 265
         $localize                               = array();
266
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
267
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
268
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
269
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
270
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
271
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
272
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
266
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
267
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
268
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
269
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
270
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
271
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
272
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
273 273
         $localize['tax']                        = wpinv_tax_amount();
274 274
         $localize['discount']                   = wpinv_discount_amount();
275 275
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -277,55 +277,55 @@  discard block
 block discarded – undo
277 277
         $localize['thousand_sep']               = wpinv_thousands_separator();
278 278
         $localize['decimal_sep']                = wpinv_decimal_separator();
279 279
         $localize['decimals']                   = wpinv_decimals();
280
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
281
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
282
-        $localize['status_pending']             = wpinv_status_nicename( 'pending' );
283
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
284
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
285
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
286
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
287
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
288
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
289
-        $localize['hasGD']                      = wpinv_gd_active();;
280
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
281
+        $localize['status_publish']             = wpinv_status_nicename('publish');
282
+        $localize['status_pending']             = wpinv_status_nicename('pending');
283
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
284
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
285
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
286
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
287
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
288
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
289
+        $localize['hasGD']                      = wpinv_gd_active(); ;
290 290
         $localize['hasPM']                      = wpinv_pm_active();
291
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
292
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
293
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
294
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
291
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
292
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
293
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
294
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
295 295
         
296
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
296
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
297 297
     }
298 298
     
299
-    public function admin_body_class( $classes ) {
299
+    public function admin_body_class($classes) {
300 300
         global $pagenow;
301 301
         
302
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
302
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
303 303
 
304 304
         $add_class = false;
305
-        if ( $pagenow == 'admin.php' && $page ) {
306
-            $add_class = strpos( $page, 'wpinv-' );
305
+        if ($pagenow == 'admin.php' && $page) {
306
+            $add_class = strpos($page, 'wpinv-');
307 307
         }
308 308
         
309 309
         $settings_class = array();
310
-        if ( $page == 'wpinv-settings' ) {
311
-            if ( !empty( $_REQUEST['tab'] ) ) {
312
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
310
+        if ($page == 'wpinv-settings') {
311
+            if (!empty($_REQUEST['tab'])) {
312
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
313 313
             }
314 314
             
315
-            if ( !empty( $_REQUEST['section'] ) ) {
316
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
315
+            if (!empty($_REQUEST['section'])) {
316
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
317 317
             }
318 318
             
319
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
319
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
320 320
         }
321 321
         
322
-        if ( !empty( $settings_class ) ) {
323
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
322
+        if (!empty($settings_class)) {
323
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
324 324
         }
325 325
         
326 326
         $post_type = wpinv_admin_post_type();
327 327
         
328
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
328
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
329 329
             return $classes .= ' wpinv';
330 330
         } else {
331 331
             return $classes;
@@ -337,26 +337,26 @@  discard block
 block discarded – undo
337 337
     public function admin_print_scripts_edit_php() {
338 338
         $post_type = wpinv_admin_post_type();
339 339
         
340
-        if ( $post_type == 'wpi_item' ) {
341
-            wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
340
+        if ($post_type == 'wpi_item') {
341
+            wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true);
342 342
         }
343 343
     }
344 344
     
345 345
     public function wpinv_actions() {
346
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
347
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
346
+        if (isset($_REQUEST['wpi_action'])) {
347
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
348 348
         }
349 349
     }
350 350
     
351
-    public function pre_get_posts( $wp_query ) {
352
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
353
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
351
+    public function pre_get_posts($wp_query) {
352
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
353
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
354 354
         }
355 355
         
356 356
         return $wp_query;
357 357
     }
358 358
     
359 359
     public function bp_invoicing_init() {
360
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
360
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
361 361
     }
362 362
 }
363 363
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +798 added lines, -798 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  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
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,51 +83,51 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
130
+        $this->ID              = absint($invoice_id);
131 131
         $this->post_type       = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
144 144
 
145 145
         // Items
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
         
162 162
         // User based
163 163
         $this->ip              = $this->setup_ip();
164
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
165
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
164
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
165
+        $this->email           = get_the_author_meta('email', $this->user_id);
166 166
         
167 167
         $this->user_info       = $this->setup_user_info();
168 168
                 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $this->company         = $this->user_info['company'];
172 172
         $this->vat_number      = $this->user_info['vat_number'];
173 173
         $this->vat_rate        = $this->user_info['vat_rate'];
174
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
174
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
175 175
         $this->address         = $this->user_info['address'];
176 176
         $this->city            = $this->user_info['city'];
177 177
         $this->country         = $this->user_info['country'];
@@ -186,47 +186,47 @@  discard block
 block discarded – undo
186 186
         // Other Identifiers
187 187
         $this->key             = $this->setup_invoice_key();
188 188
         $this->number          = $this->setup_invoice_number();
189
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
189
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
190 190
         
191
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
191
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
192 192
         
193 193
         // Allow extensions to add items to this object via hook
194
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
194
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
195 195
 
196 196
         return true;
197 197
     }
198 198
     
199 199
     private function setup_status_nicename($status) {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
201
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
201
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
202 202
 
203
-        return apply_filters( 'setup_status_nicename', $status );
203
+        return apply_filters('setup_status_nicename', $status);
204 204
     }
205 205
     
206
-    private function setup_post_name( $post = NULL ) {
206
+    private function setup_post_name($post = NULL) {
207 207
         $post_name = '';
208 208
         
209
-        if ( !empty( $post ) ) {
210
-            if( !empty( $post->post_name ) ) {
209
+        if (!empty($post)) {
210
+            if (!empty($post->post_name)) {
211 211
                 $post_name = $post->post_name;
212
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
213
-                $post_name = sanitize_title( $post->post_title );
212
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
213
+                $post_name = sanitize_title($post->post_title);
214 214
                 
215 215
                 global $wpdb;
216
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
216
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
217 217
             }
218 218
         }
219 219
 
220
-        $this->post_name   = $post_name;
220
+        $this->post_name = $post_name;
221 221
     }
222 222
     
223 223
     private function setup_due_date() {
224
-        $due_date = $this->get_meta( '_wpinv_due_date' );
224
+        $due_date = $this->get_meta('_wpinv_due_date');
225 225
         
226
-        if ( empty( $due_date ) ) {
227
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
228
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
229
-        } else if ( $due_date == 'none' ) {
226
+        if (empty($due_date)) {
227
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
228
+            $due_date = date_i18n('Y-m-d', $overdue_time);
229
+        } else if ($due_date == 'none') {
230 230
             $due_date = '';
231 231
         }
232 232
 
@@ -234,63 +234,63 @@  discard block
 block discarded – undo
234 234
     }
235 235
     
236 236
     private function setup_completed_date() {
237
-        $invoice = get_post( $this->ID );
237
+        $invoice = get_post($this->ID);
238 238
 
239
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
239
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
240 240
             return false; // This invoice was never paid
241 241
         }
242 242
 
243
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
243
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
244 244
 
245 245
         return $date;
246 246
     }
247 247
     
248 248
     private function setup_cart_details() {
249
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
249
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
250 250
         return $cart_details;
251 251
     }
252 252
     
253 253
     public function array_convert() {
254
-        return get_object_vars( $this );
254
+        return get_object_vars($this);
255 255
     }
256 256
     
257 257
     private function setup_items() {
258
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
258
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
259 259
         return $items;
260 260
     }
261 261
     
262 262
     private function setup_fees() {
263
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
263
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
264 264
         return $payment_fees;
265 265
     }
266 266
         
267 267
     private function setup_currency() {
268
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
268
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
269 269
         return $currency;
270 270
     }
271 271
     
272 272
     private function setup_discount() {
273 273
         //$discount = $this->get_meta( '_wpinv_discount', true );
274
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
275
-        if ( $discount < 0 ) {
274
+        $discount = (float)$this->subtotal - ((float)$this->total - (float)$this->tax - (float)$this->fees_total);
275
+        if ($discount < 0) {
276 276
             $discount = 0;
277 277
         }
278
-        $discount = wpinv_round_amount( $discount );
278
+        $discount = wpinv_round_amount($discount);
279 279
         
280 280
         return $discount;
281 281
     }
282 282
     
283 283
     private function setup_discount_code() {
284
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
284
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
285 285
         return $discount_code;
286 286
     }
287 287
     
288 288
     private function setup_tax() {
289
-        $tax = $this->get_meta( '_wpinv_tax', true );
289
+        $tax = $this->get_meta('_wpinv_tax', true);
290 290
 
291 291
         // We don't have tax as it's own meta and no meta was passed
292
-        if ( '' === $tax ) {            
293
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
292
+        if ('' === $tax) {            
293
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
294 294
         }
295 295
 
296 296
         return $tax;
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
         $subtotal     = 0;
301 301
         $cart_details = $this->cart_details;
302 302
 
303
-        if ( is_array( $cart_details ) ) {
304
-            foreach ( $cart_details as $item ) {
305
-                if ( isset( $item['subtotal'] ) ) {
303
+        if (is_array($cart_details)) {
304
+            foreach ($cart_details as $item) {
305
+                if (isset($item['subtotal'])) {
306 306
                     $subtotal += $item['subtotal'];
307 307
                 }
308 308
             }
@@ -316,18 +316,18 @@  discard block
 block discarded – undo
316 316
     }
317 317
     
318 318
     private function setup_discounts() {
319
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
319
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
320 320
         return $discounts;
321 321
     }
322 322
     
323 323
     private function setup_total() {
324
-        $amount = $this->get_meta( '_wpinv_total', true );
324
+        $amount = $this->get_meta('_wpinv_total', true);
325 325
 
326
-        if ( empty( $amount ) && '0.00' != $amount ) {
327
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
328
-            $meta   = maybe_unserialize( $meta );
326
+        if (empty($amount) && '0.00' != $amount) {
327
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
328
+            $meta   = maybe_unserialize($meta);
329 329
 
330
-            if ( isset( $meta['amount'] ) ) {
330
+            if (isset($meta['amount'])) {
331 331
                 $amount = $meta['amount'];
332 332
             }
333 333
         }
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
     }
337 337
     
338 338
     private function setup_mode() {
339
-        return $this->get_meta( '_wpinv_mode' );
339
+        return $this->get_meta('_wpinv_mode');
340 340
     }
341 341
 
342 342
     private function setup_gateway() {
343
-        $gateway = $this->get_meta( '_wpinv_gateway' );
343
+        $gateway = $this->get_meta('_wpinv_gateway');
344 344
         
345
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
345
+        if (empty($gateway) && 'publish' === $this->status) {
346 346
             $gateway = 'manual';
347 347
         }
348 348
         
@@ -350,23 +350,23 @@  discard block
 block discarded – undo
350 350
     }
351 351
     
352 352
     private function setup_gateway_title() {
353
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
353
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
354 354
         return $gateway_title;
355 355
     }
356 356
 
357 357
     private function setup_transaction_id() {
358
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
358
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
359 359
 
360
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
360
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
361 361
             $gateway        = $this->gateway;
362
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
362
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
363 363
         }
364 364
 
365 365
         return $transaction_id;
366 366
     }
367 367
 
368 368
     private function setup_ip() {
369
-        $ip = $this->get_meta( '_wpinv_user_ip' );
369
+        $ip = $this->get_meta('_wpinv_user_ip');
370 370
         return $ip;
371 371
     }
372 372
 
@@ -376,62 +376,62 @@  discard block
 block discarded – undo
376 376
     ///}
377 377
         
378 378
     private function setup_first_name() {
379
-        $first_name = $this->get_meta( '_wpinv_first_name' );
379
+        $first_name = $this->get_meta('_wpinv_first_name');
380 380
         return $first_name;
381 381
     }
382 382
     
383 383
     private function setup_last_name() {
384
-        $last_name = $this->get_meta( '_wpinv_last_name' );
384
+        $last_name = $this->get_meta('_wpinv_last_name');
385 385
         return $last_name;
386 386
     }
387 387
     
388 388
     private function setup_company() {
389
-        $company = $this->get_meta( '_wpinv_company' );
389
+        $company = $this->get_meta('_wpinv_company');
390 390
         return $company;
391 391
     }
392 392
     
393 393
     private function setup_vat_number() {
394
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
394
+        $vat_number = $this->get_meta('_wpinv_vat_number');
395 395
         return $vat_number;
396 396
     }
397 397
     
398 398
     private function setup_vat_rate() {
399
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
399
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
400 400
         return $vat_rate;
401 401
     }
402 402
     
403 403
     private function setup_adddress_confirmed() {
404
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
404
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
405 405
         return $adddress_confirmed;
406 406
     }
407 407
     
408 408
     private function setup_phone() {
409
-        $phone = $this->get_meta( '_wpinv_phone' );
409
+        $phone = $this->get_meta('_wpinv_phone');
410 410
         return $phone;
411 411
     }
412 412
     
413 413
     private function setup_address() {
414
-        $address = $this->get_meta( '_wpinv_address', true );
414
+        $address = $this->get_meta('_wpinv_address', true);
415 415
         return $address;
416 416
     }
417 417
     
418 418
     private function setup_city() {
419
-        $city = $this->get_meta( '_wpinv_city', true );
419
+        $city = $this->get_meta('_wpinv_city', true);
420 420
         return $city;
421 421
     }
422 422
     
423 423
     private function setup_country() {
424
-        $country = $this->get_meta( '_wpinv_country', true );
424
+        $country = $this->get_meta('_wpinv_country', true);
425 425
         return $country;
426 426
     }
427 427
     
428 428
     private function setup_state() {
429
-        $state = $this->get_meta( '_wpinv_state', true );
429
+        $state = $this->get_meta('_wpinv_state', true);
430 430
         return $state;
431 431
     }
432 432
     
433 433
     private function setup_zip() {
434
-        $zip = $this->get_meta( '_wpinv_zip', true );
434
+        $zip = $this->get_meta('_wpinv_zip', true);
435 435
         return $zip;
436 436
     }
437 437
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
             'user_id'        => $this->user_id,
441 441
             'first_name'     => $this->first_name,
442 442
             'last_name'      => $this->last_name,
443
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
443
+            'email'          => get_the_author_meta('email', $this->user_id),
444 444
             'phone'          => $this->phone,
445 445
             'address'        => $this->address,
446 446
             'city'           => $this->city,
@@ -455,12 +455,12 @@  discard block
 block discarded – undo
455 455
         );
456 456
         
457 457
         $user_info = array();
458
-        if ( isset( $this->payment_meta['user_info'] ) ) {
459
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
458
+        if (isset($this->payment_meta['user_info'])) {
459
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
460 460
             
461
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
461
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
462 462
                 $this->user_id = $post->post_author;
463
-                $this->email = get_the_author_meta( 'email', $this->user_id );
463
+                $this->email = get_the_author_meta('email', $this->user_id);
464 464
                 
465 465
                 $user_info['user_id'] = $this->user_id;
466 466
                 $user_info['email'] = $this->email;
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
             }
470 470
         }
471 471
         
472
-        $user_info    = wp_parse_args( $user_info, $defaults );
472
+        $user_info = wp_parse_args($user_info, $defaults);
473 473
         
474 474
         // Get the user, but only if it's been created
475
-        $user = get_userdata( $this->user_id );
475
+        $user = get_userdata($this->user_id);
476 476
         
477
-        if ( !empty( $user ) && $user->ID > 0 ) {
478
-            if ( empty( $user_info ) ) {
477
+        if (!empty($user) && $user->ID > 0) {
478
+            if (empty($user_info)) {
479 479
                 $user_info = array(
480 480
                     'user_id'    => $user->ID,
481 481
                     'first_name' => $user->first_name,
@@ -484,23 +484,23 @@  discard block
 block discarded – undo
484 484
                     'discount'   => '',
485 485
                 );
486 486
             } else {
487
-                foreach ( $user_info as $key => $value ) {
488
-                    if ( ! empty( $value ) ) {
487
+                foreach ($user_info as $key => $value) {
488
+                    if (!empty($value)) {
489 489
                         continue;
490 490
                     }
491 491
 
492
-                    switch( $key ) {
492
+                    switch ($key) {
493 493
                         case 'user_id':
494
-                            $user_info[ $key ] = $user->ID;
494
+                            $user_info[$key] = $user->ID;
495 495
                             break;
496 496
                         case 'first_name':
497
-                            $user_info[ $key ] = $user->first_name;
497
+                            $user_info[$key] = $user->first_name;
498 498
                             break;
499 499
                         case 'last_name':
500
-                            $user_info[ $key ] = $user->last_name;
500
+                            $user_info[$key] = $user->last_name;
501 501
                             break;
502 502
                         case 'email':
503
-                            $user_info[ $key ] = $user->user_email;
503
+                            $user_info[$key] = $user->user_email;
504 504
                             break;
505 505
                     }
506 506
                 }
@@ -511,16 +511,16 @@  discard block
 block discarded – undo
511 511
     }
512 512
 
513 513
     private function setup_invoice_key() {
514
-        $key = $this->get_meta( '_wpinv_key', true );
514
+        $key = $this->get_meta('_wpinv_key', true);
515 515
         
516 516
         return $key;
517 517
     }
518 518
 
519 519
     private function setup_invoice_number() {
520
-        $number = $this->get_meta( '_wpinv_number', true );
520
+        $number = $this->get_meta('_wpinv_number', true);
521 521
 
522
-        if ( !$number ) {
523
-            $number = wpinv_format_invoice_number( $this->ID );
522
+        if (!$number) {
523
+            $number = wpinv_format_invoice_number($this->ID);
524 524
         }
525 525
 
526 526
         return $number;
@@ -531,18 +531,18 @@  discard block
 block discarded – undo
531 531
 
532 532
         if ($number = $this->get_number()) {
533 533
             $invoice_title = $number;
534
-        } else if ( ! empty( $this->ID ) ) {
535
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
534
+        } else if (!empty($this->ID)) {
535
+            $invoice_title = wpinv_format_invoice_number($this->ID);
536 536
         } else {
537
-            $invoice_title = wpinv_format_invoice_number( 0 );
537
+            $invoice_title = wpinv_format_invoice_number(0);
538 538
         }
539 539
 
540
-        if ( empty( $this->key ) ) {
540
+        if (empty($this->key)) {
541 541
             $this->key = self::generate_key();
542 542
             $this->pending['key'] = $this->key;
543 543
         }
544 544
 
545
-        if ( empty( $this->ip ) ) {
545
+        if (empty($this->ip)) {
546 546
             $this->ip = wpinv_get_ip();
547 547
             $this->pending['ip'] = $this->ip;
548 548
         }
@@ -574,75 +574,75 @@  discard block
 block discarded – undo
574 574
             'fees'         => $this->fees,
575 575
         );
576 576
         
577
-        $post_name      = sanitize_title( $invoice_title );
577
+        $post_name = sanitize_title($invoice_title);
578 578
 
579 579
         $post_data = array(
580 580
                         'post_title'    => $invoice_title,
581 581
                         'post_status'   => $this->status,
582 582
                         'post_author'   => $this->user_id,
583 583
                         'post_type'     => $this->post_type,
584
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
585
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
584
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
585
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
586 586
                         'post_parent'   => $this->parent_invoice,
587 587
                     );
588
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
588
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
589 589
 
590 590
         // Create a blank invoice
591
-        if ( !empty( $this->ID ) ) {
591
+        if (!empty($this->ID)) {
592 592
             $args['ID']         = $this->ID;
593 593
             $args['post_name']  = $post_name;
594 594
             
595
-            $invoice_id = wp_update_post( $args );
595
+            $invoice_id = wp_update_post($args);
596 596
         } else {
597
-            $invoice_id = wp_insert_post( $args );
597
+            $invoice_id = wp_insert_post($args);
598 598
             
599
-            $post_title = wpinv_format_invoice_number( $invoice_id );
599
+            $post_title = wpinv_format_invoice_number($invoice_id);
600 600
             global $wpdb;
601
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
602
-            clean_post_cache( $invoice_id );
601
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
602
+            clean_post_cache($invoice_id);
603 603
         }
604 604
 
605
-        if ( !empty( $invoice_id ) ) {             
605
+        if (!empty($invoice_id)) {             
606 606
             $this->ID  = $invoice_id;
607 607
             $this->_ID = $invoice_id;
608 608
             
609 609
             ///$this->pending['user_id'] = $this->user_id;
610
-            if ( isset( $this->pending['number'] ) ) {
610
+            if (isset($this->pending['number'])) {
611 611
                 $this->pending['number'] = $post_name;
612 612
             }
613 613
             
614
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
615
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
616
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
617
-                foreach( $this->fees as $fee ) {
618
-                    $this->increase_fees( $fee['amount'] );
614
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
615
+            if (!empty($this->payment_meta['fees'])) {
616
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
617
+                foreach ($this->fees as $fee) {
618
+                    $this->increase_fees($fee['amount']);
619 619
                 }
620 620
             }
621 621
 
622
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
622
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
623 623
             $this->new = true;
624 624
         }
625 625
 
626 626
         return $this->ID;
627 627
     }
628 628
 
629
-    public function save( $setup = false ) {
629
+    public function save($setup = false) {
630 630
         global $wpi_session;
631 631
         
632 632
         $saved = false;
633
-        if ( empty( $this->items ) ) {
633
+        if (empty($this->items)) {
634 634
             return $saved; // Don't save empty invoice.
635 635
         }
636 636
         
637
-        if ( empty( $this->key ) ) {
637
+        if (empty($this->key)) {
638 638
             $this->key = self::generate_key();
639 639
             $this->pending['key'] = $this->key;
640 640
         }
641 641
         
642
-        if ( empty( $this->ID ) ) {
642
+        if (empty($this->ID)) {
643 643
             $invoice_id = $this->insert_invoice();
644 644
 
645
-            if ( false === $invoice_id ) {
645
+            if (false === $invoice_id) {
646 646
                 $saved = false;
647 647
             } else {
648 648
                 $this->ID = $invoice_id;
@@ -650,27 +650,27 @@  discard block
 block discarded – undo
650 650
         }        
651 651
 
652 652
         // If we have something pending, let's save it
653
-        if ( !empty( $this->pending ) ) {
653
+        if (!empty($this->pending)) {
654 654
             $total_increase = 0;
655 655
             $total_decrease = 0;
656 656
 
657
-            foreach ( $this->pending as $key => $value ) {
658
-                switch( $key ) {
657
+            foreach ($this->pending as $key => $value) {
658
+                switch ($key) {
659 659
                     case 'items':
660 660
                         // Update totals for pending items
661
-                        foreach ( $this->pending[ $key ] as $item ) {
662
-                            switch( $item['action'] ) {
661
+                        foreach ($this->pending[$key] as $item) {
662
+                            switch ($item['action']) {
663 663
                                 case 'add':
664 664
                                     $price = $item['price'];
665 665
                                     $taxes = $item['tax'];
666 666
 
667
-                                    if ( 'publish' === $this->status ) {
667
+                                    if ('publish' === $this->status) {
668 668
                                         $total_increase += $price;
669 669
                                     }
670 670
                                     break;
671 671
 
672 672
                                 case 'remove':
673
-                                    if ( 'publish' === $this->status ) {
673
+                                    if ('publish' === $this->status) {
674 674
                                         $total_decrease += $item['price'];
675 675
                                     }
676 676
                                     break;
@@ -678,16 +678,16 @@  discard block
 block discarded – undo
678 678
                         }
679 679
                         break;
680 680
                     case 'fees':
681
-                        if ( 'publish' !== $this->status ) {
681
+                        if ('publish' !== $this->status) {
682 682
                             break;
683 683
                         }
684 684
 
685
-                        if ( empty( $this->pending[ $key ] ) ) {
685
+                        if (empty($this->pending[$key])) {
686 686
                             break;
687 687
                         }
688 688
 
689
-                        foreach ( $this->pending[ $key ] as $fee ) {
690
-                            switch( $fee['action'] ) {
689
+                        foreach ($this->pending[$key] as $fee) {
690
+                            switch ($fee['action']) {
691 691
                                 case 'add':
692 692
                                     $total_increase += $fee['amount'];
693 693
                                     break;
@@ -699,86 +699,86 @@  discard block
 block discarded – undo
699 699
                         }
700 700
                         break;
701 701
                     case 'status':
702
-                        $this->update_status( $this->status );
702
+                        $this->update_status($this->status);
703 703
                         break;
704 704
                     case 'gateway':
705
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
705
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
706 706
                         break;
707 707
                     case 'mode':
708
-                        $this->update_meta( '_wpinv_mode', $this->mode );
708
+                        $this->update_meta('_wpinv_mode', $this->mode);
709 709
                         break;
710 710
                     case 'transaction_id':
711
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
711
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
712 712
                         break;
713 713
                     case 'ip':
714
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
714
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
715 715
                         break;
716 716
                     ///case 'user_id':
717 717
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
718 718
                         ///$this->user_info['user_id'] = $this->user_id;
719 719
                         ///break;
720 720
                     case 'first_name':
721
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
721
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
722 722
                         $this->user_info['first_name'] = $this->first_name;
723 723
                         break;
724 724
                     case 'last_name':
725
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
725
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
726 726
                         $this->user_info['last_name'] = $this->last_name;
727 727
                         break;
728 728
                     case 'phone':
729
-                        $this->update_meta( '_wpinv_phone', $this->phone );
729
+                        $this->update_meta('_wpinv_phone', $this->phone);
730 730
                         $this->user_info['phone'] = $this->phone;
731 731
                         break;
732 732
                     case 'address':
733
-                        $this->update_meta( '_wpinv_address', $this->address );
733
+                        $this->update_meta('_wpinv_address', $this->address);
734 734
                         $this->user_info['address'] = $this->address;
735 735
                         break;
736 736
                     case 'city':
737
-                        $this->update_meta( '_wpinv_city', $this->city );
737
+                        $this->update_meta('_wpinv_city', $this->city);
738 738
                         $this->user_info['city'] = $this->city;
739 739
                         break;
740 740
                     case 'country':
741
-                        $this->update_meta( '_wpinv_country', $this->country );
741
+                        $this->update_meta('_wpinv_country', $this->country);
742 742
                         $this->user_info['country'] = $this->country;
743 743
                         break;
744 744
                     case 'state':
745
-                        $this->update_meta( '_wpinv_state', $this->state );
745
+                        $this->update_meta('_wpinv_state', $this->state);
746 746
                         $this->user_info['state'] = $this->state;
747 747
                         break;
748 748
                     case 'zip':
749
-                        $this->update_meta( '_wpinv_zip', $this->zip );
749
+                        $this->update_meta('_wpinv_zip', $this->zip);
750 750
                         $this->user_info['zip'] = $this->zip;
751 751
                         break;
752 752
                     case 'company':
753
-                        $this->update_meta( '_wpinv_company', $this->company );
753
+                        $this->update_meta('_wpinv_company', $this->company);
754 754
                         $this->user_info['company'] = $this->company;
755 755
                         break;
756 756
                     case 'vat_number':
757
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
757
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
758 758
                         $this->user_info['vat_number'] = $this->vat_number;
759 759
                         
760
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
761
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
762
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
763
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
760
+                        $vat_info = $wpi_session->get('user_vat_data');
761
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
762
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
763
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
764 764
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
765 765
                         }
766 766
     
767 767
                         break;
768 768
                     case 'vat_rate':
769
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
769
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
770 770
                         $this->user_info['vat_rate'] = $this->vat_rate;
771 771
                         break;
772 772
                     case 'adddress_confirmed':
773
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
773
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
774 774
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
775 775
                         break;
776 776
                     
777 777
                     case 'key':
778
-                        $this->update_meta( '_wpinv_key', $this->key );
778
+                        $this->update_meta('_wpinv_key', $this->key);
779 779
                         break;
780 780
                     case 'number':
781
-                        $this->update_meta( '_wpinv_number', $this->number );
781
+                        $this->update_meta('_wpinv_number', $this->number);
782 782
                         break;
783 783
                     case 'date':
784 784
                         $args = array(
@@ -787,34 +787,34 @@  discard block
 block discarded – undo
787 787
                             'edit_date' => true,
788 788
                         );
789 789
 
790
-                        wp_update_post( $args );
790
+                        wp_update_post($args);
791 791
                         break;
792 792
                     case 'due_date':
793
-                        if ( empty( $this->due_date ) ) {
793
+                        if (empty($this->due_date)) {
794 794
                             $this->due_date = 'none';
795 795
                         }
796 796
                         
797
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
797
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
798 798
                         break;
799 799
                     case 'completed_date':
800
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
800
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
801 801
                         break;
802 802
                     case 'discounts':
803
-                        if ( ! is_array( $this->discounts ) ) {
804
-                            $this->discounts = explode( ',', $this->discounts );
803
+                        if (!is_array($this->discounts)) {
804
+                            $this->discounts = explode(',', $this->discounts);
805 805
                         }
806 806
 
807
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
807
+                        $this->user_info['discount'] = implode(',', $this->discounts);
808 808
                         break;
809 809
                         
810 810
                     //case 'tax':
811 811
                         //$this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
812 812
                         //break;
813 813
                     case 'discount':
814
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
814
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
815 815
                         break;
816 816
                     case 'discount_code':
817
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
817
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
818 818
                         break;
819 819
                     //case 'fees':
820 820
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -824,19 +824,19 @@  discard block
 block discarded – undo
824 824
                             'ID'          => $this->ID,
825 825
                             'post_parent' => $this->parent_invoice,
826 826
                         );
827
-                        wp_update_post( $args );
827
+                        wp_update_post($args);
828 828
                         break;
829 829
                     default:
830
-                        do_action( 'wpinv_save', $this, $key );
830
+                        do_action('wpinv_save', $this, $key);
831 831
                         break;
832 832
                 }
833 833
             }       
834 834
 
835
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
836
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
837
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
835
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
836
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
837
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
838 838
             
839
-            $this->items    = array_values( $this->items );
839
+            $this->items = array_values($this->items);
840 840
             
841 841
             $new_meta = array(
842 842
                 'items'         => $this->items,
@@ -847,12 +847,12 @@  discard block
 block discarded – undo
847 847
             );
848 848
             
849 849
             $meta        = $this->get_meta();
850
-            $merged_meta = array_merge( $meta, $new_meta );
850
+            $merged_meta = array_merge($meta, $new_meta);
851 851
 
852 852
             // Only save the payment meta if it's changed
853
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
854
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
855
-                if ( false !== $updated ) {
853
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
854
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
855
+                if (false !== $updated) {
856 856
                     $saved = true;
857 857
                 }
858 858
             }
@@ -860,15 +860,15 @@  discard block
 block discarded – undo
860 860
             $this->pending = array();
861 861
             $saved         = true;
862 862
         } else {
863
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
864
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
865
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
863
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
864
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
865
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
866 866
         }
867 867
         
868
-        do_action( 'wpinv_invoice_save', $this, $saved );
868
+        do_action('wpinv_invoice_save', $this, $saved);
869 869
 
870
-        if ( true === $saved || $setup ) {
871
-            $this->setup_invoice( $this->ID );
870
+        if (true === $saved || $setup) {
871
+            $this->setup_invoice($this->ID);
872 872
         }
873 873
         
874 874
         $this->refresh_item_ids();
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
         return $saved;
877 877
     }
878 878
     
879
-    public function add_fee( $args, $global = true ) {
879
+    public function add_fee($args, $global = true) {
880 880
         $default_args = array(
881 881
             'label'       => '',
882 882
             'amount'      => 0,
@@ -886,75 +886,75 @@  discard block
 block discarded – undo
886 886
             'item_id'     => 0,
887 887
         );
888 888
 
889
-        $fee = wp_parse_args( $args, $default_args );
889
+        $fee = wp_parse_args($args, $default_args);
890 890
         
891
-        if ( !empty( $fee['label'] ) ) {
891
+        if (!empty($fee['label'])) {
892 892
             return false;
893 893
         }
894 894
         
895
-        $fee['id']  = sanitize_title( $fee['label'] );
895
+        $fee['id'] = sanitize_title($fee['label']);
896 896
         
897
-        $this->fees[]               = $fee;
897
+        $this->fees[] = $fee;
898 898
         
899 899
         $added_fee               = $fee;
900 900
         $added_fee['action']     = 'add';
901 901
         $this->pending['fees'][] = $added_fee;
902
-        reset( $this->fees );
902
+        reset($this->fees);
903 903
 
904
-        $this->increase_fees( $fee['amount'] );
904
+        $this->increase_fees($fee['amount']);
905 905
         return true;
906 906
     }
907 907
 
908
-    public function remove_fee( $key ) {
908
+    public function remove_fee($key) {
909 909
         $removed = false;
910 910
 
911
-        if ( is_numeric( $key ) ) {
912
-            $removed = $this->remove_fee_by( 'index', $key );
911
+        if (is_numeric($key)) {
912
+            $removed = $this->remove_fee_by('index', $key);
913 913
         }
914 914
 
915 915
         return $removed;
916 916
     }
917 917
 
918
-    public function remove_fee_by( $key, $value, $global = false ) {
919
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
918
+    public function remove_fee_by($key, $value, $global = false) {
919
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
920 920
             'index', 'label', 'amount', 'type',
921
-        ) );
921
+        ));
922 922
 
923
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
923
+        if (!in_array($key, $allowed_fee_keys)) {
924 924
             return false;
925 925
         }
926 926
 
927 927
         $removed = false;
928
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
929
-            $removed_fee             = $this->fees[ $value ];
928
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
929
+            $removed_fee             = $this->fees[$value];
930 930
             $removed_fee['action']   = 'remove';
931 931
             $this->pending['fees'][] = $removed_fee;
932 932
 
933
-            $this->decrease_fees( $removed_fee['amount'] );
933
+            $this->decrease_fees($removed_fee['amount']);
934 934
 
935
-            unset( $this->fees[ $value ] );
935
+            unset($this->fees[$value]);
936 936
             $removed = true;
937
-        } else if ( 'index' !== $key ) {
938
-            foreach ( $this->fees as $index => $fee ) {
939
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
937
+        } else if ('index' !== $key) {
938
+            foreach ($this->fees as $index => $fee) {
939
+                if (isset($fee[$key]) && $fee[$key] == $value) {
940 940
                     $removed_fee             = $fee;
941 941
                     $removed_fee['action']   = 'remove';
942 942
                     $this->pending['fees'][] = $removed_fee;
943 943
 
944
-                    $this->decrease_fees( $removed_fee['amount'] );
944
+                    $this->decrease_fees($removed_fee['amount']);
945 945
 
946
-                    unset( $this->fees[ $index ] );
946
+                    unset($this->fees[$index]);
947 947
                     $removed = true;
948 948
 
949
-                    if ( false === $global ) {
949
+                    if (false === $global) {
950 950
                         break;
951 951
                     }
952 952
                 }
953 953
             }
954 954
         }
955 955
 
956
-        if ( true === $removed ) {
957
-            $this->fees = array_values( $this->fees );
956
+        if (true === $removed) {
957
+            $this->fees = array_values($this->fees);
958 958
         }
959 959
 
960 960
         return $removed;
@@ -962,35 +962,35 @@  discard block
 block discarded – undo
962 962
 
963 963
     
964 964
 
965
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
965
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
966 966
         // Bail if no note specified
967
-        if( !$note ) {
967
+        if (!$note) {
968 968
             return false;
969 969
         }
970 970
 
971
-        if ( empty( $this->ID ) )
971
+        if (empty($this->ID))
972 972
             return false;
973 973
         
974
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
975
-            $user                 = get_user_by( 'id', get_current_user_id() );
974
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
975
+            $user                 = get_user_by('id', get_current_user_id());
976 976
             $comment_author       = $user->display_name;
977 977
             $comment_author_email = $user->user_email;
978 978
         } else {
979
-            $comment_author       = __( 'System', 'invoicing' );
980
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
981
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
982
-            $comment_author_email = sanitize_email( $comment_author_email );
979
+            $comment_author       = __('System', 'invoicing');
980
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
981
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
982
+            $comment_author_email = sanitize_email($comment_author_email);
983 983
         }
984 984
 
985
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
985
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
986 986
 
987
-        $note_id = wp_insert_comment( wp_filter_comment( array(
987
+        $note_id = wp_insert_comment(wp_filter_comment(array(
988 988
             'comment_post_ID'      => $this->ID,
989 989
             'comment_content'      => $note,
990 990
             'comment_agent'        => 'GeoDirectory',
991 991
             'user_id'              => is_admin() ? get_current_user_id() : 0,
992
-            'comment_date'         => current_time( 'mysql' ),
993
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
992
+            'comment_date'         => current_time('mysql'),
993
+            'comment_date_gmt'     => current_time('mysql', 1),
994 994
             'comment_approved'     => 1,
995 995
             'comment_parent'       => 0,
996 996
             'comment_author'       => $comment_author,
@@ -998,53 +998,53 @@  discard block
 block discarded – undo
998 998
             'comment_author_url'   => '',
999 999
             'comment_author_email' => $comment_author_email,
1000 1000
             'comment_type'         => 'wpinv_note'
1001
-        ) ) );
1001
+        )));
1002 1002
 
1003
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1003
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1004 1004
         
1005
-        if ( $customer_type ) {
1006
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1005
+        if ($customer_type) {
1006
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1007 1007
 
1008
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1008
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1009 1009
         }
1010 1010
 
1011 1011
         return $note_id;
1012 1012
     }
1013 1013
 
1014
-    private function increase_subtotal( $amount = 0.00 ) {
1015
-        $amount          = (float) $amount;
1014
+    private function increase_subtotal($amount = 0.00) {
1015
+        $amount          = (float)$amount;
1016 1016
         $this->subtotal += $amount;
1017
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1017
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1018 1018
 
1019 1019
         $this->recalculate_total();
1020 1020
     }
1021 1021
 
1022
-    private function decrease_subtotal( $amount = 0.00 ) {
1023
-        $amount          = (float) $amount;
1022
+    private function decrease_subtotal($amount = 0.00) {
1023
+        $amount          = (float)$amount;
1024 1024
         $this->subtotal -= $amount;
1025
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1025
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1026 1026
 
1027
-        if ( $this->subtotal < 0 ) {
1027
+        if ($this->subtotal < 0) {
1028 1028
             $this->subtotal = 0;
1029 1029
         }
1030 1030
 
1031 1031
         $this->recalculate_total();
1032 1032
     }
1033 1033
 
1034
-    private function increase_fees( $amount = 0.00 ) {
1034
+    private function increase_fees($amount = 0.00) {
1035 1035
         $amount            = (float)$amount;
1036 1036
         $this->fees_total += $amount;
1037
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1037
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1038 1038
 
1039 1039
         $this->recalculate_total();
1040 1040
     }
1041 1041
 
1042
-    private function decrease_fees( $amount = 0.00 ) {
1043
-        $amount            = (float) $amount;
1042
+    private function decrease_fees($amount = 0.00) {
1043
+        $amount            = (float)$amount;
1044 1044
         $this->fees_total -= $amount;
1045
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1045
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1046 1046
 
1047
-        if ( $this->fees_total < 0 ) {
1047
+        if ($this->fees_total < 0) {
1048 1048
             $this->fees_total = 0;
1049 1049
         }
1050 1050
 
@@ -1055,54 +1055,54 @@  discard block
 block discarded – undo
1055 1055
         global $wpi_nosave;
1056 1056
         
1057 1057
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1058
-        $this->total = wpinv_round_amount( $this->total );
1058
+        $this->total = wpinv_round_amount($this->total);
1059 1059
         
1060
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1060
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1061 1061
     }
1062 1062
     
1063
-    public function increase_tax( $amount = 0.00 ) {
1064
-        $amount       = (float) $amount;
1063
+    public function increase_tax($amount = 0.00) {
1064
+        $amount       = (float)$amount;
1065 1065
         $this->tax   += $amount;
1066 1066
 
1067 1067
         $this->recalculate_total();
1068 1068
     }
1069 1069
 
1070
-    public function decrease_tax( $amount = 0.00 ) {
1071
-        $amount     = (float) $amount;
1070
+    public function decrease_tax($amount = 0.00) {
1071
+        $amount     = (float)$amount;
1072 1072
         $this->tax -= $amount;
1073 1073
 
1074
-        if ( $this->tax < 0 ) {
1074
+        if ($this->tax < 0) {
1075 1075
             $this->tax = 0;
1076 1076
         }
1077 1077
 
1078 1078
         $this->recalculate_total();
1079 1079
     }
1080 1080
 
1081
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1082
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1081
+    public function update_status($new_status = false, $note = '', $manual = false) {
1082
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1083 1083
         
1084
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1084
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1085 1085
             return false; // Don't permit status changes that aren't changes
1086 1086
         }
1087 1087
 
1088
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1088
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1089 1089
         $updated = false;
1090 1090
 
1091
-        if ( $do_change ) {
1092
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1091
+        if ($do_change) {
1092
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1093 1093
 
1094 1094
             $update_post_data                   = array();
1095 1095
             $update_post_data['ID']             = $this->ID;
1096 1096
             $update_post_data['post_status']    = $new_status;
1097
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1098
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1097
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1098
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1099 1099
             
1100
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1100
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1101 1101
 
1102
-            $updated = wp_update_post( $update_post_data );     
1102
+            $updated = wp_update_post($update_post_data);     
1103 1103
            
1104 1104
             // Process any specific status functions
1105
-            switch( $new_status ) {
1105
+            switch ($new_status) {
1106 1106
                 case 'wpi-refunded':
1107 1107
                     $this->process_refund();
1108 1108
                     break;
@@ -1115,9 +1115,9 @@  discard block
 block discarded – undo
1115 1115
             }
1116 1116
             
1117 1117
             // Status was changed.
1118
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1119
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1120
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1118
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1119
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1120
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1121 1121
         }
1122 1122
 
1123 1123
         return $updated;
@@ -1131,72 +1131,72 @@  discard block
 block discarded – undo
1131 1131
         $this->save();
1132 1132
     }
1133 1133
 
1134
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1135
-        if ( empty( $meta_key ) ) {
1134
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1135
+        if (empty($meta_key)) {
1136 1136
             return false;
1137 1137
         }
1138 1138
 
1139
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1139
+        if ($meta_key == 'key' || $meta_key == 'date') {
1140 1140
             $current_meta = $this->get_meta();
1141
-            $current_meta[ $meta_key ] = $meta_value;
1141
+            $current_meta[$meta_key] = $meta_value;
1142 1142
 
1143 1143
             $meta_key     = '_wpinv_payment_meta';
1144 1144
             $meta_value   = $current_meta;
1145 1145
         }
1146 1146
 
1147
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1147
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1148 1148
         
1149
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1149
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1150 1150
             $args = array(
1151 1151
                 'ID'                => $this->ID,
1152 1152
                 'post_date'         => $meta_value,
1153 1153
                 'edit_date'         => true,
1154
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1154
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1155 1155
                 'post_modified'     => $meta_value,
1156
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1156
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1157 1157
             );
1158
-            wp_update_post( $args );
1158
+            wp_update_post($args);
1159 1159
         }
1160 1160
         
1161
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1161
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1162 1162
     }
1163 1163
 
1164 1164
     private function process_refund() {
1165 1165
         $process_refund = true;
1166 1166
 
1167 1167
         // If the payment was not in publish, don't decrement stats as they were never incremented
1168
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1168
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1169 1169
             $process_refund = false;
1170 1170
         }
1171 1171
 
1172 1172
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1173
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1173
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1174 1174
 
1175
-        if ( false === $process_refund ) {
1175
+        if (false === $process_refund) {
1176 1176
             return;
1177 1177
         }
1178 1178
 
1179
-        do_action( 'wpinv_pre_refund_invoice', $this );
1179
+        do_action('wpinv_pre_refund_invoice', $this);
1180 1180
         
1181
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1182
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1183
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1181
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1182
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1183
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1184 1184
         
1185
-        do_action( 'wpinv_post_refund_invoice', $this );
1185
+        do_action('wpinv_post_refund_invoice', $this);
1186 1186
     }
1187 1187
 
1188 1188
     private function process_failure() {
1189 1189
         $discounts = $this->discounts;
1190
-        if ( empty( $discounts ) ) {
1190
+        if (empty($discounts)) {
1191 1191
             return;
1192 1192
         }
1193 1193
 
1194
-        if ( ! is_array( $discounts ) ) {
1195
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1194
+        if (!is_array($discounts)) {
1195
+            $discounts = array_map('trim', explode(',', $discounts));
1196 1196
         }
1197 1197
 
1198
-        foreach ( $discounts as $discount ) {
1199
-            wpinv_decrease_discount_usage( $discount );
1198
+        foreach ($discounts as $discount) {
1199
+            wpinv_decrease_discount_usage($discount);
1200 1200
         }
1201 1201
     }
1202 1202
     
@@ -1204,92 +1204,92 @@  discard block
 block discarded – undo
1204 1204
         $process_pending = true;
1205 1205
 
1206 1206
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1207
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1207
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1208 1208
             $process_pending = false;
1209 1209
         }
1210 1210
 
1211 1211
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1212
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1212
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1213 1213
 
1214
-        if ( false === $process_pending ) {
1214
+        if (false === $process_pending) {
1215 1215
             return;
1216 1216
         }
1217 1217
 
1218
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1219
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1220
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1218
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1219
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1220
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1221 1221
 
1222 1222
         $this->completed_date = '';
1223
-        $this->update_meta( '_wpinv_completed_date', '' );
1223
+        $this->update_meta('_wpinv_completed_date', '');
1224 1224
     }
1225 1225
     
1226 1226
     // get data
1227
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1228
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1227
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1228
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1229 1229
 
1230
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1230
+        if ($meta_key === '_wpinv_payment_meta') {
1231 1231
 
1232
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1232
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1233 1233
 
1234
-            if ( empty( $meta['key'] ) ) {
1234
+            if (empty($meta['key'])) {
1235 1235
                 $meta['key'] = $this->setup_invoice_key();
1236 1236
             }
1237 1237
 
1238
-            if ( empty( $meta['date'] ) ) {
1239
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1238
+            if (empty($meta['date'])) {
1239
+                $meta['date'] = get_post_field('post_date', $this->ID);
1240 1240
             }
1241 1241
         }
1242 1242
 
1243
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1243
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1244 1244
 
1245
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1245
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1246 1246
     }
1247 1247
     
1248 1248
     public function get_description() {
1249
-        $post = get_post( $this->ID );
1249
+        $post = get_post($this->ID);
1250 1250
         
1251
-        $description = !empty( $post ) ? $post->post_content : '';
1252
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1251
+        $description = !empty($post) ? $post->post_content : '';
1252
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1253 1253
     }
1254 1254
     
1255
-    public function get_status( $nicename = false ) {
1256
-        if ( !$nicename ) {
1255
+    public function get_status($nicename = false) {
1256
+        if (!$nicename) {
1257 1257
             $status = $this->status;
1258 1258
         } else {
1259 1259
             $status = $this->status_nicename;
1260 1260
         }
1261 1261
         
1262
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1262
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1263 1263
     }
1264 1264
     
1265 1265
     public function get_cart_details() {
1266
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1266
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1267 1267
     }
1268 1268
     
1269
-    public function get_subtotal( $currency = false ) {
1270
-        $subtotal = wpinv_round_amount( $this->subtotal );
1269
+    public function get_subtotal($currency = false) {
1270
+        $subtotal = wpinv_round_amount($this->subtotal);
1271 1271
         
1272
-        if ( $currency ) {
1273
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1272
+        if ($currency) {
1273
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1274 1274
         }
1275 1275
         
1276
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1276
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1277 1277
     }
1278 1278
     
1279
-    public function get_total( $currency = false ) {        
1280
-        if ( $this->is_free_trial() ) {
1281
-            $total = wpinv_round_amount( 0 );
1279
+    public function get_total($currency = false) {        
1280
+        if ($this->is_free_trial()) {
1281
+            $total = wpinv_round_amount(0);
1282 1282
         } else {
1283
-            $total = wpinv_round_amount( $this->total );
1283
+            $total = wpinv_round_amount($this->total);
1284 1284
         }
1285
-        if ( $currency ) {
1286
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1285
+        if ($currency) {
1286
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1287 1287
         }
1288 1288
         
1289
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1289
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1290 1290
     }
1291 1291
     
1292
-    public function get_recurring_details( $field = '', $currency = false ) {        
1292
+    public function get_recurring_details($field = '', $currency = false) {        
1293 1293
         $data                 = array();
1294 1294
         $data['cart_details'] = $this->cart_details;
1295 1295
         $data['subtotal']     = $this->get_subtotal();
@@ -1297,45 +1297,45 @@  discard block
 block discarded – undo
1297 1297
         $data['tax']          = $this->get_tax();
1298 1298
         $data['total']        = $this->get_total();
1299 1299
     
1300
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1300
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1301 1301
             $is_free_trial = $this->is_free_trial();
1302
-            $discounts = $this->get_discounts( true );
1302
+            $discounts = $this->get_discounts(true);
1303 1303
             
1304
-            if ( $is_free_trial || !empty( $discounts ) ) {
1304
+            if ($is_free_trial || !empty($discounts)) {
1305 1305
                 $first_use_only = false;
1306 1306
                 
1307
-                if ( !empty( $discounts ) ) {
1308
-                    foreach ( $discounts as $key => $code ) {
1309
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1307
+                if (!empty($discounts)) {
1308
+                    foreach ($discounts as $key => $code) {
1309
+                        if (wpinv_discount_is_recurring($code, true)) {
1310 1310
                             $first_use_only = true;
1311 1311
                             break;
1312 1312
                         }
1313 1313
                     }
1314 1314
                 }
1315 1315
                     
1316
-                if ( !$first_use_only ) {
1317
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1318
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1319
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1320
-                    $data['total']    = wpinv_round_amount( $this->total );
1316
+                if (!$first_use_only) {
1317
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1318
+                    $data['discount'] = wpinv_round_amount($this->discount);
1319
+                    $data['tax']      = wpinv_round_amount($this->tax);
1320
+                    $data['total']    = wpinv_round_amount($this->total);
1321 1321
                 } else {
1322 1322
                     $cart_subtotal   = 0;
1323 1323
                     $cart_discount   = 0;
1324 1324
                     $cart_tax        = 0;
1325 1325
 
1326
-                    foreach ( $this->cart_details as $key => $item ) {
1327
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1328
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1326
+                    foreach ($this->cart_details as $key => $item) {
1327
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1328
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1329 1329
                         $item_discount  = 0;
1330
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1330
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1331 1331
                         
1332
-                        if ( wpinv_prices_include_tax() ) {
1333
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1332
+                        if (wpinv_prices_include_tax()) {
1333
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1334 1334
                         }
1335 1335
                         
1336 1336
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1337 1337
                         // Do not allow totals to go negative
1338
-                        if ( $item_total < 0 ) {
1338
+                        if ($item_total < 0) {
1339 1339
                             $item_total = 0;
1340 1340
                         }
1341 1341
                         
@@ -1343,113 +1343,113 @@  discard block
 block discarded – undo
1343 1343
                         $cart_discount  += (float)($item_discount);
1344 1344
                         $cart_tax       += (float)($item_tax);
1345 1345
                         
1346
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1347
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1348
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1346
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1347
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1348
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1349 1349
                     }
1350 1350
                     
1351
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1352
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1353
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1354
-                    $data['total']    = wpinv_round_amount( $data['subtotal'] + $data['tax'] );
1351
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1352
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1353
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1354
+                    $data['total']    = wpinv_round_amount($data['subtotal'] + $data['tax']);
1355 1355
                 }
1356 1356
             }
1357 1357
         }
1358 1358
         
1359
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1359
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1360 1360
 
1361
-        if ( isset( $data[$field] ) ) {
1362
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1361
+        if (isset($data[$field])) {
1362
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1363 1363
         }
1364 1364
         
1365 1365
         return $data;
1366 1366
     }
1367 1367
     
1368
-    public function get_final_tax( $currency = false ) {        
1369
-        $final_total = wpinv_round_amount( $this->tax );
1370
-        if ( $currency ) {
1371
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1368
+    public function get_final_tax($currency = false) {        
1369
+        $final_total = wpinv_round_amount($this->tax);
1370
+        if ($currency) {
1371
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1372 1372
         }
1373 1373
         
1374
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1374
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1375 1375
     }
1376 1376
     
1377
-    public function get_discounts( $array = false ) {
1377
+    public function get_discounts($array = false) {
1378 1378
         $discounts = $this->discounts;
1379
-        if ( $array && $discounts ) {
1380
-            $discounts = explode( ',', $discounts );
1379
+        if ($array && $discounts) {
1380
+            $discounts = explode(',', $discounts);
1381 1381
         }
1382
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1382
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1383 1383
     }
1384 1384
     
1385
-    public function get_discount( $currency = false, $dash = false ) {
1386
-        if ( !empty( $this->discounts ) ) {
1385
+    public function get_discount($currency = false, $dash = false) {
1386
+        if (!empty($this->discounts)) {
1387 1387
             global $ajax_cart_details;
1388 1388
             $ajax_cart_details = $this->get_cart_details();
1389 1389
             
1390
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1390
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1391 1391
                 $cart_items = $ajax_cart_details;
1392 1392
             } else {
1393 1393
                 $cart_items = $this->items;
1394 1394
             }
1395 1395
 
1396
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1396
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1397 1397
         }
1398
-        $discount   = wpinv_round_amount( $this->discount );
1398
+        $discount   = wpinv_round_amount($this->discount);
1399 1399
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1400 1400
         
1401
-        if ( $currency ) {
1402
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1401
+        if ($currency) {
1402
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1403 1403
         }
1404 1404
         
1405
-        $discount   = $dash . $discount;
1405
+        $discount = $dash . $discount;
1406 1406
         
1407
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1407
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1408 1408
     }
1409 1409
     
1410 1410
     public function get_discount_code() {
1411 1411
         return $this->discount_code;
1412 1412
     }
1413 1413
     
1414
-    public function get_tax( $currency = false ) {
1415
-        $tax = wpinv_round_amount( $this->tax );
1414
+    public function get_tax($currency = false) {
1415
+        $tax = wpinv_round_amount($this->tax);
1416 1416
         
1417
-        if ( $currency ) {
1418
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1417
+        if ($currency) {
1418
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1419 1419
         }
1420 1420
         
1421
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1421
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1422 1422
     }
1423 1423
     
1424
-    public function get_fees( $type = 'all' ) {
1425
-        $fees    = array();
1424
+    public function get_fees($type = 'all') {
1425
+        $fees = array();
1426 1426
 
1427
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1428
-            foreach ( $this->fees as $fee ) {
1429
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1427
+        if (!empty($this->fees) && is_array($this->fees)) {
1428
+            foreach ($this->fees as $fee) {
1429
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1430 1430
                     continue;
1431 1431
                 }
1432 1432
 
1433
-                $fee['label'] = stripslashes( $fee['label'] );
1434
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1435
-                $fees[]    = $fee;
1433
+                $fee['label'] = stripslashes($fee['label']);
1434
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1435
+                $fees[] = $fee;
1436 1436
             }
1437 1437
         }
1438 1438
 
1439
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1439
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1440 1440
     }
1441 1441
     
1442
-    public function get_fees_total( $type = 'all' ) {
1443
-        $fees_total = (float) 0.00;
1442
+    public function get_fees_total($type = 'all') {
1443
+        $fees_total = (float)0.00;
1444 1444
 
1445
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1446
-        if ( ! empty( $payment_fees ) ) {
1447
-            foreach ( $payment_fees as $fee ) {
1448
-                $fees_total += (float) $fee['amount'];
1445
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1446
+        if (!empty($payment_fees)) {
1447
+            foreach ($payment_fees as $fee) {
1448
+                $fees_total += (float)$fee['amount'];
1449 1449
             }
1450 1450
         }
1451 1451
 
1452
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1452
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1453 1453
         /*
1454 1454
         $fees = $this->get_fees( $type );
1455 1455
 
@@ -1469,116 +1469,116 @@  discard block
 block discarded – undo
1469 1469
     }
1470 1470
 
1471 1471
     public function get_user_id() {
1472
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1472
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1473 1473
     }
1474 1474
     
1475 1475
     public function get_first_name() {
1476
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1476
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1477 1477
     }
1478 1478
     
1479 1479
     public function get_last_name() {
1480
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1480
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1481 1481
     }
1482 1482
     
1483 1483
     public function get_user_full_name() {
1484
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1484
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1485 1485
     }
1486 1486
     
1487 1487
     public function get_user_info() {
1488
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1488
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1489 1489
     }
1490 1490
     
1491 1491
     public function get_email() {
1492
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1492
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1493 1493
     }
1494 1494
     
1495 1495
     public function get_address() {
1496
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1496
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1497 1497
     }
1498 1498
     
1499 1499
     public function get_phone() {
1500
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1500
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1501 1501
     }
1502 1502
     
1503 1503
     public function get_number() {
1504
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1504
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1505 1505
     }
1506 1506
     
1507 1507
     public function get_items() {
1508
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1508
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1509 1509
     }
1510 1510
     
1511 1511
     public function get_key() {
1512
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1512
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1513 1513
     }
1514 1514
     
1515 1515
     public function get_transaction_id() {
1516
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1516
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1517 1517
     }
1518 1518
     
1519 1519
     public function get_gateway() {
1520
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1520
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1521 1521
     }
1522 1522
     
1523 1523
     public function get_gateway_title() {
1524
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1524
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1525 1525
         
1526
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1526
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1527 1527
     }
1528 1528
     
1529 1529
     public function get_currency() {
1530
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1530
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1531 1531
     }
1532 1532
     
1533 1533
     public function get_created_date() {
1534
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1534
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1535 1535
     }
1536 1536
     
1537
-    public function get_due_date( $display = false ) {
1538
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1537
+    public function get_due_date($display = false) {
1538
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1539 1539
         
1540
-        if ( !$display || empty( $due_date ) ) {
1540
+        if (!$display || empty($due_date)) {
1541 1541
             return $due_date;
1542 1542
         }
1543 1543
         
1544
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1544
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1545 1545
     }
1546 1546
     
1547 1547
     public function get_completed_date() {
1548
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1548
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1549 1549
     }
1550 1550
     
1551
-    public function get_invoice_date( $formatted = true ) {
1551
+    public function get_invoice_date($formatted = true) {
1552 1552
         $date_completed = $this->completed_date;
1553 1553
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1554 1554
         
1555
-        if ( $invoice_date == '' ) {
1555
+        if ($invoice_date == '') {
1556 1556
             $date_created   = $this->date;
1557 1557
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1558 1558
         }
1559 1559
         
1560
-        if ( $formatted && $invoice_date ) {
1561
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1560
+        if ($formatted && $invoice_date) {
1561
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1562 1562
         }
1563 1563
 
1564
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1564
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1565 1565
     }
1566 1566
     
1567 1567
     public function get_ip() {
1568
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1568
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1569 1569
     }
1570 1570
         
1571
-    public function has_status( $status ) {
1572
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1571
+    public function has_status($status) {
1572
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1573 1573
     }
1574 1574
     
1575
-    public function add_item( $item_id = 0, $args = array() ) {
1575
+    public function add_item($item_id = 0, $args = array()) {
1576 1576
         global $wpi_current_id, $wpi_item_id;
1577 1577
         
1578
-        $item = new WPInv_Item( $item_id );
1578
+        $item = new WPInv_Item($item_id);
1579 1579
 
1580 1580
         // Bail if this post isn't a item
1581
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1581
+        if (!$item || $item->post_type !== 'wpi_item') {
1582 1582
             return false;
1583 1583
         }
1584 1584
         
@@ -1597,8 +1597,8 @@  discard block
 block discarded – undo
1597 1597
             'fees'          => array()
1598 1598
         );
1599 1599
 
1600
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1601
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1600
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1601
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1602 1602
 
1603 1603
         $wpi_current_id         = $this->ID;
1604 1604
         $wpi_item_id            = $item->ID;
@@ -1610,19 +1610,19 @@  discard block
 block discarded – undo
1610 1610
         $found_cart_key         = false;
1611 1611
         
1612 1612
         if ($has_quantities) {
1613
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1613
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1614 1614
             
1615
-            foreach ( $this->items as $key => $cart_item ) {
1616
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1615
+            foreach ($this->items as $key => $cart_item) {
1616
+                if ((int)$item_id !== (int)$cart_item['id']) {
1617 1617
                     continue;
1618 1618
                 }
1619 1619
 
1620
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1620
+                $this->items[$key]['quantity'] += $args['quantity'];
1621 1621
                 break;
1622 1622
             }
1623 1623
             
1624
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1625
-                if ( $item_id != $cart_item['id'] ) {
1624
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1625
+                if ($item_id != $cart_item['id']) {
1626 1626
                     continue;
1627 1627
                 }
1628 1628
 
@@ -1634,29 +1634,29 @@  discard block
 block discarded – undo
1634 1634
         if ($has_quantities && $found_cart_key !== false) {
1635 1635
             $cart_item          = $this->cart_details[$found_cart_key];
1636 1636
             $item_price         = $cart_item['item_price'];
1637
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1638
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1637
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1638
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1639 1639
             
1640 1640
             $new_quantity       = $quantity + $args['quantity'];
1641 1641
             $subtotal           = $item_price * $new_quantity;
1642 1642
             
1643 1643
             $args['quantity']   = $new_quantity;
1644
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1645
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1644
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1645
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1646 1646
             
1647 1647
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1648 1648
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1649 1649
             // The total increase equals the number removed * the item_price
1650
-            $total_increased    = wpinv_round_amount( $item_price );
1650
+            $total_increased    = wpinv_round_amount($item_price);
1651 1651
             
1652
-            if ( wpinv_prices_include_tax() ) {
1653
-                $subtotal -= wpinv_round_amount( $tax );
1652
+            if (wpinv_prices_include_tax()) {
1653
+                $subtotal -= wpinv_round_amount($tax);
1654 1654
             }
1655 1655
 
1656
-            $total              = $subtotal - $discount + $tax;
1656
+            $total = $subtotal - $discount + $tax;
1657 1657
 
1658 1658
             // Do not allow totals to go negative
1659
-            if( $total < 0 ) {
1659
+            if ($total < 0) {
1660 1660
                 $total = 0;
1661 1661
             }
1662 1662
             
@@ -1672,25 +1672,25 @@  discard block
 block discarded – undo
1672 1672
             $this->cart_details[$found_cart_key] = $cart_item;
1673 1673
         } else {
1674 1674
             // Set custom price.
1675
-            if ( $args['custom_price'] !== '' ) {
1675
+            if ($args['custom_price'] !== '') {
1676 1676
                 $item_price = $args['custom_price'];
1677 1677
             } else {
1678 1678
                 // Allow overriding the price
1679
-                if ( false !== $args['item_price'] ) {
1679
+                if (false !== $args['item_price']) {
1680 1680
                     $item_price = $args['item_price'];
1681 1681
                 } else {
1682
-                    $item_price = wpinv_get_item_price( $item->ID );
1682
+                    $item_price = wpinv_get_item_price($item->ID);
1683 1683
                 }
1684 1684
             }
1685 1685
 
1686 1686
             // Sanitizing the price here so we don't have a dozen calls later
1687
-            $item_price = wpinv_sanitize_amount( $item_price );
1688
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1687
+            $item_price = wpinv_sanitize_amount($item_price);
1688
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1689 1689
         
1690
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1691
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1692
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1693
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1690
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1691
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1692
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1693
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1694 1694
 
1695 1695
             // Setup the items meta item
1696 1696
             $new_item = array(
@@ -1698,29 +1698,29 @@  discard block
 block discarded – undo
1698 1698
                 'quantity' => $args['quantity'],
1699 1699
             );
1700 1700
 
1701
-            $this->items[]  = $new_item;
1701
+            $this->items[] = $new_item;
1702 1702
 
1703
-            if ( wpinv_prices_include_tax() ) {
1704
-                $subtotal -= wpinv_round_amount( $tax );
1703
+            if (wpinv_prices_include_tax()) {
1704
+                $subtotal -= wpinv_round_amount($tax);
1705 1705
             }
1706 1706
 
1707
-            $total      = $subtotal - $discount + $tax;
1707
+            $total = $subtotal - $discount + $tax;
1708 1708
 
1709 1709
             // Do not allow totals to go negative
1710
-            if( $total < 0 ) {
1710
+            if ($total < 0) {
1711 1711
                 $total = 0;
1712 1712
             }
1713 1713
         
1714 1714
             $this->cart_details[] = array(
1715 1715
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1716 1716
                 'id'            => $item->ID,
1717
-                'item_price'    => wpinv_round_amount( $item_price ),
1718
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1717
+                'item_price'    => wpinv_round_amount($item_price),
1718
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1719 1719
                 'quantity'      => $args['quantity'],
1720 1720
                 'discount'      => $discount,
1721
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1722
-                'tax'           => wpinv_round_amount( $tax ),
1723
-                'price'         => wpinv_round_amount( $total ),
1721
+                'subtotal'      => wpinv_round_amount($subtotal),
1722
+                'tax'           => wpinv_round_amount($tax),
1723
+                'price'         => wpinv_round_amount($total),
1724 1724
                 'vat_rate'      => $tax_rate,
1725 1725
                 'vat_class'     => $tax_class,
1726 1726
                 'meta'          => $args['meta'],
@@ -1730,18 +1730,18 @@  discard block
 block discarded – undo
1730 1730
             $subtotal = $subtotal - $discount;
1731 1731
         }
1732 1732
         
1733
-        $added_item = end( $this->cart_details );
1734
-        $added_item['action']  = 'add';
1733
+        $added_item = end($this->cart_details);
1734
+        $added_item['action'] = 'add';
1735 1735
         
1736 1736
         $this->pending['items'][] = $added_item;
1737 1737
         
1738
-        $this->increase_subtotal( $subtotal );
1739
-        $this->increase_tax( $tax );
1738
+        $this->increase_subtotal($subtotal);
1739
+        $this->increase_tax($tax);
1740 1740
 
1741 1741
         return true;
1742 1742
     }
1743 1743
     
1744
-    public function remove_item( $item_id, $args = array() ) {
1744
+    public function remove_item($item_id, $args = array()) {
1745 1745
         // Set some defaults
1746 1746
         $defaults = array(
1747 1747
             'quantity'      => 1,
@@ -1749,51 +1749,51 @@  discard block
 block discarded – undo
1749 1749
             'custom_price'  => '',
1750 1750
             'cart_index'    => false,
1751 1751
         );
1752
-        $args = wp_parse_args( $args, $defaults );
1752
+        $args = wp_parse_args($args, $defaults);
1753 1753
 
1754 1754
         // Bail if this post isn't a item
1755
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1755
+        if (get_post_type($item_id) !== 'wpi_item') {
1756 1756
             return false;
1757 1757
         }
1758 1758
         
1759
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1759
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1760 1760
 
1761
-        foreach ( $this->items as $key => $item ) {
1762
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1761
+        foreach ($this->items as $key => $item) {
1762
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1763 1763
                 continue;
1764 1764
             }
1765 1765
 
1766
-            if ( false !== $args['cart_index'] ) {
1767
-                $cart_index = absint( $args['cart_index'] );
1768
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1766
+            if (false !== $args['cart_index']) {
1767
+                $cart_index = absint($args['cart_index']);
1768
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1769 1769
 
1770
-                if ( ! empty( $cart_item ) ) {
1770
+                if (!empty($cart_item)) {
1771 1771
                     // If the cart index item isn't the same item ID, don't remove it
1772
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1772
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1773 1773
                         continue;
1774 1774
                     }
1775 1775
                 }
1776 1776
             }
1777 1777
 
1778
-            $item_quantity = $this->items[ $key ]['quantity'];
1779
-            if ( $item_quantity > $args['quantity'] ) {
1780
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1778
+            $item_quantity = $this->items[$key]['quantity'];
1779
+            if ($item_quantity > $args['quantity']) {
1780
+                $this->items[$key]['quantity'] -= $args['quantity'];
1781 1781
                 break;
1782 1782
             } else {
1783
-                unset( $this->items[ $key ] );
1783
+                unset($this->items[$key]);
1784 1784
                 break;
1785 1785
             }
1786 1786
         }
1787 1787
 
1788 1788
         $found_cart_key = false;
1789
-        if ( false === $args['cart_index'] ) {
1790
-            foreach ( $this->cart_details as $cart_key => $item ) {
1791
-                if ( $item_id != $item['id'] ) {
1789
+        if (false === $args['cart_index']) {
1790
+            foreach ($this->cart_details as $cart_key => $item) {
1791
+                if ($item_id != $item['id']) {
1792 1792
                     continue;
1793 1793
                 }
1794 1794
 
1795
-                if ( false !== $args['item_price'] ) {
1796
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1795
+                if (false !== $args['item_price']) {
1796
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1797 1797
                         continue;
1798 1798
                     }
1799 1799
                 }
@@ -1802,13 +1802,13 @@  discard block
 block discarded – undo
1802 1802
                 break;
1803 1803
             }
1804 1804
         } else {
1805
-            $cart_index = absint( $args['cart_index'] );
1805
+            $cart_index = absint($args['cart_index']);
1806 1806
 
1807
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1807
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1808 1808
                 return false; // Invalid cart index passed.
1809 1809
             }
1810 1810
 
1811
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1811
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1812 1812
                 return false; // We still need the proper Item ID to be sure.
1813 1813
             }
1814 1814
 
@@ -1816,41 +1816,41 @@  discard block
 block discarded – undo
1816 1816
         }
1817 1817
         
1818 1818
         $cart_item  = $this->cart_details[$found_cart_key];
1819
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1819
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1820 1820
         
1821
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1821
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1822 1822
             return false; // Invoice must contain at least one item.
1823 1823
         }
1824 1824
         
1825
-        $discounts  = $this->get_discounts();
1825
+        $discounts = $this->get_discounts();
1826 1826
         
1827
-        if ( $quantity > $args['quantity'] ) {
1827
+        if ($quantity > $args['quantity']) {
1828 1828
             $item_price         = $cart_item['item_price'];
1829
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1829
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1830 1830
             
1831
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1831
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1832 1832
             $subtotal           = $item_price * $new_quantity;
1833 1833
             
1834 1834
             $args['quantity']   = $new_quantity;
1835
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1836
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1835
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1836
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1837 1837
             
1838
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1838
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;
1839 1839
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1840
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1840
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;
1841 1841
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1842 1842
             
1843 1843
             // The total increase equals the number removed * the item_price
1844
-            $total_decrease     = wpinv_round_amount( $item_price );
1844
+            $total_decrease     = wpinv_round_amount($item_price);
1845 1845
             
1846
-            if ( wpinv_prices_include_tax() ) {
1847
-                $subtotal -= wpinv_round_amount( $tax );
1846
+            if (wpinv_prices_include_tax()) {
1847
+                $subtotal -= wpinv_round_amount($tax);
1848 1848
             }
1849 1849
 
1850
-            $total              = $subtotal - $discount + $tax;
1850
+            $total = $subtotal - $discount + $tax;
1851 1851
 
1852 1852
             // Do not allow totals to go negative
1853
-            if( $total < 0 ) {
1853
+            if ($total < 0) {
1854 1854
                 $total = 0;
1855 1855
             }
1856 1856
             
@@ -1869,16 +1869,16 @@  discard block
 block discarded – undo
1869 1869
             
1870 1870
             $this->cart_details[$found_cart_key] = $cart_item;
1871 1871
             
1872
-            $remove_item = end( $this->cart_details );
1872
+            $remove_item = end($this->cart_details);
1873 1873
         } else {
1874 1874
             $item_price     = $cart_item['item_price'];
1875
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1876
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1875
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1876
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1877 1877
         
1878
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1878
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1879 1879
             $tax_decrease       = $tax;
1880 1880
 
1881
-            unset( $this->cart_details[$found_cart_key] );
1881
+            unset($this->cart_details[$found_cart_key]);
1882 1882
             
1883 1883
             $remove_item             = $args;
1884 1884
             $remove_item['id']       = $item_id;
@@ -1889,8 +1889,8 @@  discard block
 block discarded – undo
1889 1889
         $remove_item['action']      = 'remove';
1890 1890
         $this->pending['items'][]   = $remove_item;
1891 1891
                
1892
-        $this->decrease_subtotal( $subtotal_decrease );
1893
-        $this->decrease_tax( $tax_decrease );
1892
+        $this->decrease_subtotal($subtotal_decrease);
1893
+        $this->decrease_tax($tax_decrease);
1894 1894
         
1895 1895
         return true;
1896 1896
     }
@@ -1898,7 +1898,7 @@  discard block
 block discarded – undo
1898 1898
     public function update_items($temp = false) {
1899 1899
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1900 1900
         
1901
-        if ( !empty( $this->cart_details ) ) {
1901
+        if (!empty($this->cart_details)) {
1902 1902
             $wpi_nosave             = $temp;
1903 1903
             $cart_subtotal          = 0;
1904 1904
             $cart_discount          = 0;
@@ -1908,46 +1908,46 @@  discard block
 block discarded – undo
1908 1908
             $_POST['wpinv_country'] = $this->country;
1909 1909
             $_POST['wpinv_state']   = $this->state;
1910 1910
             
1911
-            foreach ( $this->cart_details as $key => $item ) {
1911
+            foreach ($this->cart_details as $key => $item) {
1912 1912
                 //$item['item_price'] = $item['custom_price'];
1913
-                wpinv_error_log( $item, 'item', __FILE__, __LINE__ );
1913
+                wpinv_error_log($item, 'item', __FILE__, __LINE__);
1914 1914
                 $item_price = $item['item_price'];
1915
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1916
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1915
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1916
+                $amount     = wpinv_round_amount($item_price * $quantity);
1917 1917
                 $subtotal   = $item_price * $quantity;
1918 1918
                 
1919 1919
                 $wpi_current_id         = $this->ID;
1920 1920
                 $wpi_item_id            = $item['id'];
1921 1921
                 
1922
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1923
-                wpinv_error_log( $discount, 'discount', __FILE__, __LINE__ );
1922
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1923
+                wpinv_error_log($discount, 'discount', __FILE__, __LINE__);
1924 1924
                 
1925
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1926
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1927
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1928
-                wpinv_error_log( $tax, 'tax', __FILE__, __LINE__ );
1925
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1926
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1927
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1928
+                wpinv_error_log($tax, 'tax', __FILE__, __LINE__);
1929 1929
 
1930
-                if ( wpinv_prices_include_tax() ) {
1931
-                    $subtotal -= wpinv_round_amount( $tax );
1930
+                if (wpinv_prices_include_tax()) {
1931
+                    $subtotal -= wpinv_round_amount($tax);
1932 1932
                 }
1933 1933
 
1934
-                $total      = $subtotal - $discount + $tax;
1934
+                $total = $subtotal - $discount + $tax;
1935 1935
 
1936 1936
                 // Do not allow totals to go negative
1937
-                if( $total < 0 ) {
1937
+                if ($total < 0) {
1938 1938
                     $total = 0;
1939 1939
                 }
1940 1940
 
1941 1941
                 $cart_details[] = array(
1942 1942
                     'id'          => $item['id'],
1943 1943
                     'name'        => $item['name'],
1944
-                    'item_price'  => wpinv_round_amount( $item_price ),
1945
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
1944
+                    'item_price'  => wpinv_round_amount($item_price),
1945
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
1946 1946
                     'quantity'    => $quantity,
1947 1947
                     'discount'    => $discount,
1948
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1949
-                    'tax'         => wpinv_round_amount( $tax ),
1950
-                    'price'       => wpinv_round_amount( $total ),
1948
+                    'subtotal'    => wpinv_round_amount($subtotal),
1949
+                    'tax'         => wpinv_round_amount($tax),
1950
+                    'price'       => wpinv_round_amount($total),
1951 1951
                     'vat_rate'    => $tax_rate,
1952 1952
                     'vat_class'   => $tax_class,
1953 1953
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1958,9 +1958,9 @@  discard block
 block discarded – undo
1958 1958
                 $cart_discount  += (float)($discount);
1959 1959
                 $cart_tax       += (float)($tax);
1960 1960
             }
1961
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1962
-            $this->tax      = wpinv_round_amount( $cart_tax );
1963
-            $this->discount = wpinv_round_amount( $cart_discount );
1961
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1962
+            $this->tax      = wpinv_round_amount($cart_tax);
1963
+            $this->discount = wpinv_round_amount($cart_discount);
1964 1964
             
1965 1965
             $this->recalculate_total();
1966 1966
             
@@ -1972,221 +1972,221 @@  discard block
 block discarded – undo
1972 1972
     
1973 1973
     public function recalculate_totals($temp = false) {        
1974 1974
         $this->update_items($temp);
1975
-        $this->save( true );
1975
+        $this->save(true);
1976 1976
         
1977 1977
         return $this;
1978 1978
     }
1979 1979
     
1980 1980
     public function needs_payment() {
1981
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1981
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1982 1982
 
1983
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() ) ) {
1983
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free())) {
1984 1984
             $needs_payment = true;
1985 1985
         } else {
1986 1986
             $needs_payment = false;
1987 1987
         }
1988 1988
 
1989
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1989
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1990 1990
     }
1991 1991
     
1992
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1992
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1993 1993
         $pay_url = wpinv_get_checkout_uri();
1994 1994
 
1995
-        if ( is_ssl() ) {
1996
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1995
+        if (is_ssl()) {
1996
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1997 1997
         }
1998 1998
         
1999 1999
         $key = $this->get_key();
2000 2000
 
2001
-        if ( $on_checkout ) {
2002
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2001
+        if ($on_checkout) {
2002
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2003 2003
         } else {
2004
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2004
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2005 2005
         }
2006 2006
         
2007
-        if ( $secret ) {
2008
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2007
+        if ($secret) {
2008
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2009 2009
         }
2010 2010
 
2011
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
2011
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
2012 2012
     }
2013 2013
     
2014
-    public function get_view_url( $secret = false ) {
2015
-        $print_url = get_permalink( $this->ID );
2014
+    public function get_view_url($secret = false) {
2015
+        $print_url = get_permalink($this->ID);
2016 2016
         
2017
-        if ( $secret ) {
2018
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
2017
+        if ($secret) {
2018
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2019 2019
         }
2020 2020
 
2021
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2021
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2022 2022
     }
2023 2023
     
2024
-    public function generate_key( $string = '' ) {
2025
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2026
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2024
+    public function generate_key($string = '') {
2025
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2026
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2027 2027
     }
2028 2028
     
2029 2029
     public function is_recurring() {
2030
-        if ( empty( $this->cart_details ) ) {
2030
+        if (empty($this->cart_details)) {
2031 2031
             return false;
2032 2032
         }
2033 2033
         
2034 2034
         $has_subscription = false;
2035
-        foreach( $this->cart_details as $cart_item ) {
2036
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2035
+        foreach ($this->cart_details as $cart_item) {
2036
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2037 2037
                 $has_subscription = true;
2038 2038
                 break;
2039 2039
             }
2040 2040
         }
2041 2041
         
2042
-        if ( count( $this->cart_details ) > 1 ) {
2042
+        if (count($this->cart_details) > 1) {
2043 2043
             $has_subscription = false;
2044 2044
         }
2045 2045
 
2046
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2046
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2047 2047
     }
2048 2048
     
2049 2049
     public function is_free_trial() {
2050 2050
         $is_free_trial = false;
2051 2051
         
2052
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2053
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2052
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2053
+            if (!empty($item) && $item->has_free_trial()) {
2054 2054
                 $is_free_trial = true;
2055 2055
             }
2056 2056
         }
2057 2057
 
2058
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2058
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2059 2059
     }
2060 2060
     
2061
-    public function get_recurring( $object = false ) {
2061
+    public function get_recurring($object = false) {
2062 2062
         $item = NULL;
2063 2063
         
2064
-        if ( empty( $this->cart_details ) ) {
2064
+        if (empty($this->cart_details)) {
2065 2065
             return $item;
2066 2066
         }
2067 2067
         
2068
-        foreach( $this->cart_details as $cart_item ) {
2069
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2068
+        foreach ($this->cart_details as $cart_item) {
2069
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2070 2070
                 $item = $cart_item['id'];
2071 2071
                 break;
2072 2072
             }
2073 2073
         }
2074 2074
         
2075
-        if ( $object ) {
2076
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2075
+        if ($object) {
2076
+            $item = $item ? new WPInv_Item($item) : NULL;
2077 2077
             
2078
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2078
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2079 2079
         }
2080 2080
 
2081
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2081
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2082 2082
     }
2083 2083
     
2084 2084
     public function get_subscription_name() {
2085
-        $item = $this->get_recurring( true );
2085
+        $item = $this->get_recurring(true);
2086 2086
         
2087
-        if ( empty( $item ) ) {
2087
+        if (empty($item)) {
2088 2088
             return NULL;
2089 2089
         }
2090 2090
         
2091
-        if ( !($name = $item->get_name()) ) {
2091
+        if (!($name = $item->get_name())) {
2092 2092
             $name = $item->post_name;
2093 2093
         }
2094 2094
 
2095
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2095
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2096 2096
     }
2097 2097
         
2098 2098
     public function get_expiration() {
2099
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2099
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2100 2100
         return $expiration;
2101 2101
     }
2102 2102
     
2103
-    public function get_cancelled_date( $formatted = true ) {
2104
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2103
+    public function get_cancelled_date($formatted = true) {
2104
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2105 2105
         
2106
-        if ( $formatted && $cancelled_date ) {
2107
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2106
+        if ($formatted && $cancelled_date) {
2107
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2108 2108
         }
2109 2109
         
2110 2110
         return $cancelled_date;
2111 2111
     }
2112 2112
     
2113
-    public function get_trial_end_date( $formatted = true ) {
2114
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2113
+    public function get_trial_end_date($formatted = true) {
2114
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2115 2115
             return NULL;
2116 2116
         }
2117 2117
         
2118
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2118
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2119 2119
         
2120
-        if ( empty( $trial_end_date ) ) {
2121
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2122
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2120
+        if (empty($trial_end_date)) {
2121
+            $trial_start_time = strtotime($this->get_subscription_start());
2122
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2123 2123
             
2124
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2124
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2125 2125
         }
2126 2126
         
2127
-        if ( $formatted && $trial_end_date ) {
2128
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2127
+        if ($formatted && $trial_end_date) {
2128
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2129 2129
         }
2130 2130
         
2131 2131
         return $trial_end_date;
2132 2132
     }
2133 2133
     
2134
-    public function get_subscription_created( $default = true ) {
2135
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2134
+    public function get_subscription_created($default = true) {
2135
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2136 2136
         
2137
-        if ( empty( $created ) && $default ) {
2137
+        if (empty($created) && $default) {
2138 2138
             $created = $this->date;
2139 2139
         }
2140 2140
         return $created;
2141 2141
     }
2142 2142
     
2143
-    public function get_subscription_start( $formatted = true ) {
2144
-        if ( !$this->is_paid() ) {
2143
+    public function get_subscription_start($formatted = true) {
2144
+        if (!$this->is_paid()) {
2145 2145
             return '-';
2146 2146
         }
2147
-        $start   = $this->get_subscription_created();
2147
+        $start = $this->get_subscription_created();
2148 2148
         
2149
-        if ( $formatted ) {
2150
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2149
+        if ($formatted) {
2150
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2151 2151
         } else {
2152
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2152
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2153 2153
         }
2154 2154
 
2155 2155
         return $date;
2156 2156
     }
2157 2157
     
2158
-    public function get_subscription_end( $formatted = true ) {
2159
-        if ( !$this->is_paid() ) {
2158
+    public function get_subscription_end($formatted = true) {
2159
+        if (!$this->is_paid()) {
2160 2160
             return '-';
2161 2161
         }
2162 2162
         $start          = $this->get_subscription_created();
2163 2163
         $interval       = $this->get_subscription_interval();
2164
-        $period         = $this->get_subscription_period( true );
2164
+        $period         = $this->get_subscription_period(true);
2165 2165
         $bill_times     = (int)$this->get_bill_times();
2166 2166
         
2167
-        if ( $bill_times == 0 ) {
2168
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2167
+        if ($bill_times == 0) {
2168
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2169 2169
         }
2170 2170
         
2171
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2171
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2172 2172
         
2173
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2173
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2174 2174
         
2175
-        if ( $this->is_free_trial() ) {
2176
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2175
+        if ($this->is_free_trial()) {
2176
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2177 2177
         }
2178 2178
         
2179
-        if ( $formatted ) {
2180
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2179
+        if ($formatted) {
2180
+            $date = date_i18n(get_option('date_format'), $end_time);
2181 2181
         } else {
2182
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2182
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2183 2183
         }
2184 2184
 
2185 2185
         return $date;
2186 2186
     }
2187 2187
     
2188 2188
     public function get_expiration_time() {
2189
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2189
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2190 2190
     }
2191 2191
     
2192 2192
     public function get_original_invoice_id() {        
@@ -2198,125 +2198,125 @@  discard block
 block discarded – undo
2198 2198
         return $subscription_data['bill_times'];
2199 2199
     }
2200 2200
 
2201
-    public function get_child_payments( $self = false ) {
2202
-        $invoices = get_posts( array(
2201
+    public function get_child_payments($self = false) {
2202
+        $invoices = get_posts(array(
2203 2203
             'post_type'         => $this->post_type,
2204 2204
             'post_parent'       => (int)$this->ID,
2205 2205
             'posts_per_page'    => '999',
2206
-            'post_status'       => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
2206
+            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'),
2207 2207
             'orderby'           => 'ID',
2208 2208
             'order'             => 'DESC',
2209 2209
             'fields'            => 'ids'
2210
-        ) );
2210
+        ));
2211 2211
         
2212
-        if ( $this->is_free_trial() ) {
2212
+        if ($this->is_free_trial()) {
2213 2213
             $self = false;
2214 2214
         }
2215 2215
         
2216
-        if ( $self && $this->is_paid() ) {
2217
-            if ( !empty( $invoices ) ) {
2216
+        if ($self && $this->is_paid()) {
2217
+            if (!empty($invoices)) {
2218 2218
                 $invoices[] = (int)$this->ID;
2219 2219
             } else {
2220
-                $invoices = array( $this->ID );
2220
+                $invoices = array($this->ID);
2221 2221
             }
2222 2222
             
2223
-            $invoices = array_unique( $invoices );
2223
+            $invoices = array_unique($invoices);
2224 2224
         }
2225 2225
 
2226 2226
         return $invoices;
2227 2227
     }
2228 2228
 
2229
-    public function get_total_payments( $self = true ) {
2230
-        return count( $this->get_child_payments( $self ) );
2229
+    public function get_total_payments($self = true) {
2230
+        return count($this->get_child_payments($self));
2231 2231
     }
2232 2232
     
2233
-    public function get_subscriptions( $limit = -1 ) {
2234
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2233
+    public function get_subscriptions($limit = -1) {
2234
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2235 2235
 
2236 2236
         return $subscriptions;
2237 2237
     }
2238 2238
     
2239 2239
     public function get_subscription_id() {
2240
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2240
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2241 2241
         
2242
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2243
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2242
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2243
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2244 2244
             
2245
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2245
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2246 2246
         }
2247 2247
         
2248 2248
         return $subscription_id;
2249 2249
     }
2250 2250
     
2251 2251
     public function get_subscription_status() {
2252
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2252
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2253 2253
 
2254
-        if ( empty( $subscription_status ) ) {
2254
+        if (empty($subscription_status)) {
2255 2255
             $status = 'pending';
2256 2256
             
2257
-            if ( $this->is_paid() ) {        
2257
+            if ($this->is_paid()) {        
2258 2258
                 $bill_times   = (int)$this->get_bill_times();
2259 2259
                 $times_billed = (int)$this->get_total_payments();
2260
-                $expiration = $this->get_subscription_end( false );
2261
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2260
+                $expiration = $this->get_subscription_end(false);
2261
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2262 2262
                 
2263
-                if ( (int)$bill_times == 0 ) {
2263
+                if ((int)$bill_times == 0) {
2264 2264
                     $status = $expired ? 'expired' : 'active';
2265
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2265
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2266 2266
                     $status = 'completed';
2267
-                } else if ( $expired ) {
2267
+                } else if ($expired) {
2268 2268
                     $status = 'expired';
2269
-                } else if ( $bill_times > 0 ) {
2269
+                } else if ($bill_times > 0) {
2270 2270
                     $status = 'active';
2271 2271
                 } else {
2272 2272
                     $status = 'pending';
2273 2273
                 }
2274 2274
             }
2275 2275
             
2276
-            if ( $status && $status != $subscription_status ) {
2276
+            if ($status && $status != $subscription_status) {
2277 2277
                 $subscription_status = $status;
2278 2278
                 
2279
-                $this->update_meta( '_wpinv_subscr_status', $status );
2279
+                $this->update_meta('_wpinv_subscr_status', $status);
2280 2280
             }
2281 2281
         }
2282 2282
         
2283 2283
         return $subscription_status;
2284 2284
     }
2285 2285
     
2286
-    public function get_subscription_status_label( $status = '' ) {
2287
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2286
+    public function get_subscription_status_label($status = '') {
2287
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2288 2288
 
2289
-        switch( $status ) {
2289
+        switch ($status) {
2290 2290
             case 'active' :
2291
-                $status_label = __( 'Active', 'invoicing' );
2291
+                $status_label = __('Active', 'invoicing');
2292 2292
                 break;
2293 2293
 
2294 2294
             case 'cancelled' :
2295
-                $status_label = __( 'Cancelled', 'invoicing' );
2295
+                $status_label = __('Cancelled', 'invoicing');
2296 2296
                 break;
2297 2297
                 
2298 2298
             case 'completed' :
2299
-                $status_label = __( 'Completed', 'invoicing' );
2299
+                $status_label = __('Completed', 'invoicing');
2300 2300
                 break;
2301 2301
 
2302 2302
             case 'expired' :
2303
-                $status_label = __( 'Expired', 'invoicing' );
2303
+                $status_label = __('Expired', 'invoicing');
2304 2304
                 break;
2305 2305
 
2306 2306
             case 'pending' :
2307
-                $status_label = __( 'Pending', 'invoicing' );
2307
+                $status_label = __('Pending', 'invoicing');
2308 2308
                 break;
2309 2309
 
2310 2310
             case 'failing' :
2311
-                $status_label = __( 'Failing', 'invoicing' );
2311
+                $status_label = __('Failing', 'invoicing');
2312 2312
                 break;
2313 2313
                 
2314 2314
             case 'stopped' :
2315
-                $status_label = __( 'Stopped', 'invoicing' );
2315
+                $status_label = __('Stopped', 'invoicing');
2316 2316
                 break;
2317 2317
                 
2318 2318
             case 'trialing' :
2319
-                $status_label = __( 'Trialing', 'invoicing' );
2319
+                $status_label = __('Trialing', 'invoicing');
2320 2320
                 break;
2321 2321
 
2322 2322
             default:
@@ -2327,26 +2327,26 @@  discard block
 block discarded – undo
2327 2327
         return $status_label;
2328 2328
     }
2329 2329
     
2330
-    public function get_subscription_period( $full = false ) {
2331
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2330
+    public function get_subscription_period($full = false) {
2331
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2332 2332
         
2333 2333
         // Fix period for old invoices
2334
-        if ( $period == 'day' ) {
2334
+        if ($period == 'day') {
2335 2335
             $period = 'D';
2336
-        } else if ( $period == 'week' ) {
2336
+        } else if ($period == 'week') {
2337 2337
             $period = 'W';
2338
-        } else if ( $period == 'month' ) {
2338
+        } else if ($period == 'month') {
2339 2339
             $period = 'M';
2340
-        } else if ( $period == 'year' ) {
2340
+        } else if ($period == 'year') {
2341 2341
             $period = 'Y';
2342 2342
         }
2343 2343
         
2344
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2344
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2345 2345
             $period = 'D';
2346 2346
         }
2347 2347
         
2348
-        if ( $full ) {
2349
-            switch( $period ) {
2348
+        if ($full) {
2349
+            switch ($period) {
2350 2350
                 case 'D':
2351 2351
                     $period = 'day';
2352 2352
                 break;
@@ -2366,39 +2366,39 @@  discard block
 block discarded – undo
2366 2366
     }
2367 2367
     
2368 2368
     public function get_subscription_interval() {
2369
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2369
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2370 2370
         
2371
-        if ( !$interval > 0 ) {
2371
+        if (!$interval > 0) {
2372 2372
             $interval = 1;
2373 2373
         }
2374 2374
         
2375 2375
         return $interval;
2376 2376
     }
2377 2377
     
2378
-    public function get_subscription_trial_period( $full = false ) {
2379
-        if ( !$this->is_free_trial() ) {
2378
+    public function get_subscription_trial_period($full = false) {
2379
+        if (!$this->is_free_trial()) {
2380 2380
             return '';
2381 2381
         }
2382 2382
         
2383
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2383
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2384 2384
         
2385 2385
         // Fix period for old invoices
2386
-        if ( $period == 'day' ) {
2386
+        if ($period == 'day') {
2387 2387
             $period = 'D';
2388
-        } else if ( $period == 'week' ) {
2388
+        } else if ($period == 'week') {
2389 2389
             $period = 'W';
2390
-        } else if ( $period == 'month' ) {
2390
+        } else if ($period == 'month') {
2391 2391
             $period = 'M';
2392
-        } else if ( $period == 'year' ) {
2392
+        } else if ($period == 'year') {
2393 2393
             $period = 'Y';
2394 2394
         }
2395 2395
         
2396
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2396
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2397 2397
             $period = 'D';
2398 2398
         }
2399 2399
         
2400
-        if ( $full ) {
2401
-            switch( $period ) {
2400
+        if ($full) {
2401
+            switch ($period) {
2402 2402
                 case 'D':
2403 2403
                     $period = 'day';
2404 2404
                 break;
@@ -2418,13 +2418,13 @@  discard block
 block discarded – undo
2418 2418
     }
2419 2419
     
2420 2420
     public function get_subscription_trial_interval() {
2421
-        if ( !$this->is_free_trial() ) {
2421
+        if (!$this->is_free_trial()) {
2422 2422
             return 0;
2423 2423
         }
2424 2424
         
2425
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2425
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2426 2426
         
2427
-        if ( !$interval > 0 ) {
2427
+        if (!$interval > 0) {
2428 2428
             $interval = 1;
2429 2429
         }
2430 2430
         
@@ -2436,8 +2436,8 @@  discard block
 block discarded – undo
2436 2436
             'status' => 'failing'
2437 2437
         );
2438 2438
 
2439
-        if ( $this->update_subscription( $args ) ) {
2440
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2439
+        if ($this->update_subscription($args)) {
2440
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2441 2441
             return true;
2442 2442
         }
2443 2443
 
@@ -2449,8 +2449,8 @@  discard block
 block discarded – undo
2449 2449
             'status' => 'stopped'
2450 2450
         );
2451 2451
 
2452
-        if ( $this->update_subscription( $args ) ) {
2453
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2452
+        if ($this->update_subscription($args)) {
2453
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2454 2454
             return true;
2455 2455
         }
2456 2456
 
@@ -2462,8 +2462,8 @@  discard block
 block discarded – undo
2462 2462
             'status' => 'active'
2463 2463
         );
2464 2464
 
2465
-        if ( $this->update_subscription( $args ) ) {
2466
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2465
+        if ($this->update_subscription($args)) {
2466
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2467 2467
             return true;
2468 2468
         }
2469 2469
 
@@ -2475,23 +2475,23 @@  discard block
 block discarded – undo
2475 2475
             'status' => 'cancelled'
2476 2476
         );
2477 2477
 
2478
-        if ( $this->update_subscription( $args ) ) {
2479
-            if ( is_user_logged_in() ) {
2480
-                $userdata = get_userdata( get_current_user_id() );
2478
+        if ($this->update_subscription($args)) {
2479
+            if (is_user_logged_in()) {
2480
+                $userdata = get_userdata(get_current_user_id());
2481 2481
                 $user     = $userdata->user_login;
2482 2482
             } else {
2483
-                $user = __( 'gateway', 'invoicing' );
2483
+                $user = __('gateway', 'invoicing');
2484 2484
             }
2485 2485
             
2486 2486
             $subscription_id = $this->get_subscription_id();
2487
-            if ( !$subscription_id ) {
2487
+            if (!$subscription_id) {
2488 2488
                 $subscription_id = $this->ID;
2489 2489
             }
2490 2490
 
2491
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2492
-            $this->add_note( $note );
2491
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2492
+            $this->add_note($note);
2493 2493
 
2494
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2494
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2495 2495
             return true;
2496 2496
         }
2497 2497
 
@@ -2499,11 +2499,11 @@  discard block
 block discarded – undo
2499 2499
     }
2500 2500
 
2501 2501
     public function can_cancel() {
2502
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2502
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2503 2503
     }
2504 2504
     
2505
-    public function add_subscription( $data = array() ) {
2506
-        if ( empty( $this->ID ) ) {
2505
+    public function add_subscription($data = array()) {
2506
+        if (empty($this->ID)) {
2507 2507
             return false;
2508 2508
         }
2509 2509
 
@@ -2522,85 +2522,85 @@  discard block
 block discarded – undo
2522 2522
             'profile_id'        => '',
2523 2523
         );
2524 2524
 
2525
-        $args = wp_parse_args( $data, $defaults );
2525
+        $args = wp_parse_args($data, $defaults);
2526 2526
 
2527
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2528
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2527
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2528
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2529 2529
                 $args['status'] = 'expired';
2530 2530
             }
2531 2531
         }
2532 2532
 
2533
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2533
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2534 2534
         
2535
-        if ( !empty( $args ) ) {
2536
-            foreach ( $args as $key => $value ) {
2537
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2535
+        if (!empty($args)) {
2536
+            foreach ($args as $key => $value) {
2537
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2538 2538
             }
2539 2539
         }
2540 2540
 
2541
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2541
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2542 2542
 
2543 2543
         return true;
2544 2544
     }
2545 2545
     
2546
-    public function update_subscription( $args = array() ) {
2547
-        if ( empty( $this->ID ) ) {
2546
+    public function update_subscription($args = array()) {
2547
+        if (empty($this->ID)) {
2548 2548
             return false;
2549 2549
         }
2550 2550
 
2551
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2552
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2551
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2552
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2553 2553
                 $args['status'] = 'expired';
2554 2554
             }
2555 2555
         }
2556 2556
 
2557
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2558
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2557
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2558
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2559 2559
         }
2560 2560
 
2561
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2561
+        do_action('wpinv_subscription_pre_update', $args, $this);
2562 2562
         
2563
-        if ( !empty( $args ) ) {
2564
-            foreach ( $args as $key => $value ) {
2565
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2563
+        if (!empty($args)) {
2564
+            foreach ($args as $key => $value) {
2565
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2566 2566
             }
2567 2567
         }
2568 2568
 
2569
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2569
+        do_action('wpinv_subscription_post_update', $args, $this);
2570 2570
 
2571 2571
         return true;
2572 2572
     }
2573 2573
     
2574 2574
     public function renew_subscription() {
2575 2575
         $parent_invoice = $this->get_parent_payment();
2576
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2576
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2577 2577
         
2578
-        $current_time   = current_time( 'timestamp' );
2578
+        $current_time   = current_time('timestamp');
2579 2579
         $start          = $this->get_subscription_created();
2580
-        $start          = $start ? strtotime( $start ) : $current_time;
2580
+        $start          = $start ? strtotime($start) : $current_time;
2581 2581
         $expires        = $this->get_expiration_time();
2582 2582
         
2583
-        if ( !$expires ) {
2584
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2583
+        if (!$expires) {
2584
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2585 2585
         }
2586 2586
         
2587
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2588
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2587
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2588
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2589 2589
         $bill_times     = $parent_invoice->get_bill_times();
2590 2590
         $times_billed   = $parent_invoice->get_total_payments();
2591 2591
         
2592
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2592
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2593 2593
             $args = array(
2594 2594
                 'status'     => 'active',
2595 2595
             );
2596 2596
 
2597
-            $parent_invoice->update_subscription( $args );
2597
+            $parent_invoice->update_subscription($args);
2598 2598
         }
2599 2599
         
2600
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2600
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2601 2601
 
2602
-        $status       = 'active';
2603
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2602
+        $status = 'active';
2603
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2604 2604
             $this->complete_subscription();
2605 2605
             $status = 'completed';
2606 2606
         }
@@ -2610,10 +2610,10 @@  discard block
 block discarded – undo
2610 2610
             'status'     => $status,
2611 2611
         );
2612 2612
 
2613
-        $this->update_subscription( $args );
2613
+        $this->update_subscription($args);
2614 2614
 
2615
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2616
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2615
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2616
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2617 2617
     }
2618 2618
     
2619 2619
     public function complete_subscription() {
@@ -2621,8 +2621,8 @@  discard block
 block discarded – undo
2621 2621
             'status' => 'completed'
2622 2622
         );
2623 2623
 
2624
-        if ( $this->update_subscription( $args ) ) {
2625
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2624
+        if ($this->update_subscription($args)) {
2625
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2626 2626
         }
2627 2627
     }
2628 2628
     
@@ -2631,44 +2631,44 @@  discard block
 block discarded – undo
2631 2631
             'status' => 'expired'
2632 2632
         );
2633 2633
 
2634
-        if ( $this->update_subscription( $args ) ) {
2635
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2634
+        if ($this->update_subscription($args)) {
2635
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2636 2636
         }
2637 2637
     }
2638 2638
 
2639 2639
     public function get_cancel_url() {
2640
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2640
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2641 2641
 
2642
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2642
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2643 2643
     }
2644 2644
 
2645 2645
     public function can_update() {
2646
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2646
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2647 2647
     }
2648 2648
 
2649 2649
     public function get_update_url() {
2650
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2650
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2651 2651
 
2652
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2652
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2653 2653
     }
2654 2654
 
2655 2655
     public function is_parent() {
2656
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2656
+        $is_parent = empty($this->parent_invoice) ? true : false;
2657 2657
 
2658
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2658
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2659 2659
     }
2660 2660
     
2661 2661
     public function is_renewal() {
2662 2662
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2663 2663
 
2664
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2664
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2665 2665
     }
2666 2666
     
2667 2667
     public function get_parent_payment() {
2668 2668
         $parent_payment = NULL;
2669 2669
         
2670
-        if ( $this->is_renewal() ) {
2671
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2670
+        if ($this->is_renewal()) {
2671
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2672 2672
         }
2673 2673
         
2674 2674
         return $parent_payment;
@@ -2679,100 +2679,100 @@  discard block
 block discarded – undo
2679 2679
         
2680 2680
         $subscription_status = $this->get_subscription_status();
2681 2681
 
2682
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2682
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2683 2683
             $ret = true;
2684 2684
         }
2685 2685
 
2686
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2686
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2687 2687
     }
2688 2688
 
2689 2689
     public function is_subscription_expired() {
2690 2690
         $ret = false;
2691 2691
         $subscription_status = $this->get_subscription_status();
2692 2692
 
2693
-        if ( $subscription_status == 'expired' ) {
2693
+        if ($subscription_status == 'expired') {
2694 2694
             $ret = true;
2695
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2695
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2696 2696
             $ret        = false;
2697 2697
             $expiration = $this->get_expiration_time();
2698 2698
 
2699
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2699
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2700 2700
                 $ret = true;
2701 2701
 
2702
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2702
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2703 2703
                     $this->expire_subscription();
2704 2704
                 }
2705 2705
             }
2706 2706
         }
2707 2707
 
2708
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2708
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2709 2709
     }
2710 2710
     
2711
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2712
-        $item   = new WPInv_Item( $item_id );
2711
+    public function get_new_expiration($item_id = 0, $trial = true) {
2712
+        $item   = new WPInv_Item($item_id);
2713 2713
         $interval = $item->get_recurring_interval();
2714
-        $period = $item->get_recurring_period( true );
2714
+        $period = $item->get_recurring_period(true);
2715 2715
         
2716
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2716
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2717 2717
         
2718
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2719
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2718
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2719
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2720 2720
         }
2721 2721
 
2722
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2722
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2723 2723
     }
2724 2724
     
2725
-    public function get_subscription_data( $filed = '' ) {
2726
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2725
+    public function get_subscription_data($filed = '') {
2726
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2727 2727
         
2728 2728
         $subscription_meta = array();
2729
-        foreach ( $fields as $field ) {
2730
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2729
+        foreach ($fields as $field) {
2730
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2731 2731
         }
2732 2732
         
2733
-        $item = $this->get_recurring( true );
2733
+        $item = $this->get_recurring(true);
2734 2734
         
2735
-        if ( !empty( $item ) ) {
2736
-            if ( empty( $subscription_meta['item_id'] ) ) {
2735
+        if (!empty($item)) {
2736
+            if (empty($subscription_meta['item_id'])) {
2737 2737
                 $subscription_meta['item_id'] = $item->ID;
2738 2738
             }
2739
-            if ( empty( $subscription_meta['period'] ) ) {
2739
+            if (empty($subscription_meta['period'])) {
2740 2740
                 $subscription_meta['period'] = $item->get_recurring_period();
2741 2741
             }
2742
-            if ( empty( $subscription_meta['interval'] ) ) {
2742
+            if (empty($subscription_meta['interval'])) {
2743 2743
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2744 2744
             }
2745
-            if ( $item->has_free_trial() ) {
2746
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2745
+            if ($item->has_free_trial()) {
2746
+                if (empty($subscription_meta['trial_period'])) {
2747 2747
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2748 2748
                 }
2749
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2749
+                if (empty($subscription_meta['trial_interval'])) {
2750 2750
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2751 2751
                 }
2752 2752
             } else {
2753 2753
                 $subscription_meta['trial_period']      = '';
2754 2754
                 $subscription_meta['trial_interval']    = 0;
2755 2755
             }
2756
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2756
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2757 2757
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2758 2758
             }
2759
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2760
-                $subscription_meta['initial_amount']    = wpinv_round_amount( $this->get_total() );
2761
-                $subscription_meta['recurring_amount']  = wpinv_round_amount( $this->get_recurring_details( 'total' ) );
2759
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2760
+                $subscription_meta['initial_amount']    = wpinv_round_amount($this->get_total());
2761
+                $subscription_meta['recurring_amount']  = wpinv_round_amount($this->get_recurring_details('total'));
2762 2762
             }
2763 2763
         }
2764 2764
         
2765
-        if ( $filed === '' ) {
2766
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2765
+        if ($filed === '') {
2766
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2767 2767
         }
2768 2768
         
2769
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2769
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2770 2770
         
2771
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2771
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2772 2772
     }
2773 2773
     
2774 2774
     public function is_paid() {
2775
-        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2775
+        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) {
2776 2776
             return true;
2777 2777
         }
2778 2778
         
@@ -2782,15 +2782,15 @@  discard block
 block discarded – undo
2782 2782
     public function is_free() {
2783 2783
         $is_free = false;
2784 2784
         
2785
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2786
-            if ( $this->is_parent() && $this->is_recurring() ) {
2787
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2785
+        if (!((float)wpinv_round_amount($this->get_total()) > 0)) {
2786
+            if ($this->is_parent() && $this->is_recurring()) {
2787
+                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2788 2788
             } else {
2789 2789
                 $is_free = true;
2790 2790
             }
2791 2791
         }
2792 2792
         
2793
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2793
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2794 2794
     }
2795 2795
     
2796 2796
     public function has_vat() {
@@ -2798,40 +2798,40 @@  discard block
 block discarded – undo
2798 2798
         
2799 2799
         $requires_vat = false;
2800 2800
         
2801
-        if ( $this->country ) {
2801
+        if ($this->country) {
2802 2802
             $wpi_country        = $this->country;
2803 2803
             
2804
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2804
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2805 2805
         }
2806 2806
         
2807
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2807
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2808 2808
     }
2809 2809
     
2810 2810
     public function refresh_item_ids() {
2811 2811
         $item_ids = array();
2812 2812
         
2813
-        if ( !empty( $this->cart_details ) ) {
2814
-            foreach ( $this->cart_details as $key => $item ) {
2815
-                if ( !empty( $item['id'] ) ) {
2813
+        if (!empty($this->cart_details)) {
2814
+            foreach ($this->cart_details as $key => $item) {
2815
+                if (!empty($item['id'])) {
2816 2816
                     $item_ids[] = $item['id'];
2817 2817
                 }
2818 2818
             }
2819 2819
         }
2820 2820
         
2821
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2821
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2822 2822
         
2823
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2823
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2824 2824
     }
2825 2825
 
2826 2826
     public function get_invoice_quote_type($post_id) {
2827
-        if ( empty( $post_id ) ) {
2827
+        if (empty($post_id)) {
2828 2828
             return '';
2829 2829
         }
2830 2830
         $post_type = '';
2831 2831
         $type = get_post_type($post_id);
2832
-        if("wpi_invoice" === $type){
2832
+        if ("wpi_invoice" === $type) {
2833 2833
             $post_type = __('Invoice', 'invoicing');
2834
-        } else{
2834
+        } else {
2835 2835
             $post_type = __('Quote', 'invoicing');
2836 2836
         }
2837 2837
 
Please login to merge, or discard this patch.