Passed
Pull Request — master (#41)
by Kiran
04:19
created
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,22 +11,22 @@
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
     
16
-    if ( $wpi_version == WPINV_VERSION ) {
16
+    if ($wpi_version == WPINV_VERSION) {
17 17
         return;
18 18
     }
19 19
     
20
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
20
+    if (version_compare($wpi_version, '0.0.5', '<')) {
21 21
         wpinv_v005_upgrades();
22 22
     }
23 23
     
24
-    update_option( 'wpinv_version', WPINV_VERSION );
24
+    update_option('wpinv_version', WPINV_VERSION);
25 25
 }
26
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
26
+add_action('admin_init', 'wpinv_automatic_upgrade');
27 27
 
28 28
 function wpinv_v005_upgrades() {
29 29
     global $wpdb;
30 30
     
31
-    $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
31
+    $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-user-functions.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -1,26 +1,26 @@  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
-    wpinv_get_template_part( 'wpinv-invoice-history' );
7
+    wpinv_get_template_part('wpinv-invoice-history');
8 8
 }
9 9
 
10
-function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) {
11
-    if ( empty( $user ) ) {
10
+function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') {
11
+    if (empty($user)) {
12 12
         $user = get_current_user_id();
13 13
     }
14 14
 
15
-    if ( 0 === $user ) {
15
+    if (0 === $user) {
16 16
         return false;
17 17
     }
18 18
 
19
-    if ( $pagination ) {
20
-        if ( get_query_var( 'paged' ) )
19
+    if ($pagination) {
20
+        if (get_query_var('paged'))
21 21
             $paged = get_query_var('paged');
22
-        else if ( get_query_var( 'page' ) )
23
-            $paged = get_query_var( 'page' );
22
+        else if (get_query_var('page'))
23
+            $paged = get_query_var('page');
24 24
         else
25 25
             $paged = 1;
26 26
     }
@@ -29,21 +29,21 @@  discard block
 block discarded – undo
29 29
         'post_type'      => 'wpi_invoice',
30 30
         'posts_per_page' => 20,
31 31
         'paged'          => null,
32
-        'post_status'    => array( 'publish', 'pending' ),
32
+        'post_status'    => array('publish', 'pending'),
33 33
         'user'           => $user,
34 34
         'order'          => 'date',
35 35
     );
36 36
 
37
-    $invoices = get_posts( $args );
37
+    $invoices = get_posts($args);
38 38
 
39 39
     // No invoices
40
-    if ( ! $invoices )
40
+    if (!$invoices)
41 41
         return false;
42 42
 
43 43
     return $invoices;
44 44
 }
45 45
 
46
-function wpinv_dropdown_users( $args = '' ) {
46
+function wpinv_dropdown_users($args = '') {
47 47
     $defaults = array(
48 48
         'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
49 49
         'orderby' => 'display_name', 'order' => 'ASC',
@@ -54,18 +54,18 @@  discard block
 block discarded – undo
54 54
         'option_none_value' => -1
55 55
     );
56 56
 
57
-    $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
57
+    $defaults['selected'] = is_author() ? get_query_var('author') : 0;
58 58
 
59
-    $r = wp_parse_args( $args, $defaults );
59
+    $r = wp_parse_args($args, $defaults);
60 60
 
61
-    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
61
+    $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who'));
62 62
 
63
-    $fields = array( 'ID', 'user_login', 'user_email' );
63
+    $fields = array('ID', 'user_login', 'user_email');
64 64
 
65
-    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
66
-    if ( 'display_name_with_login' === $show ) {
65
+    $show = !empty($r['show']) ? $r['show'] : 'display_name';
66
+    if ('display_name_with_login' === $show) {
67 67
         $fields[] = 'display_name';
68
-    } else if ( 'display_name_with_email' === $show ) {
68
+    } else if ('display_name_with_email' === $show) {
69 69
         $fields[] = 'display_name';
70 70
     } else {
71 71
         $fields[] = $show;
@@ -77,99 +77,99 @@  discard block
 block discarded – undo
77 77
     $show_option_none = $r['show_option_none'];
78 78
     $option_none_value = $r['option_none_value'];
79 79
 
80
-    $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r );
80
+    $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r);
81 81
 
82
-    $users = get_users( $query_args );
82
+    $users = get_users($query_args);
83 83
 
84 84
     $output = '';
85
-    if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
86
-        $name = esc_attr( $r['name'] );
87
-        if ( $r['multi'] && ! $r['id'] ) {
85
+    if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) {
86
+        $name = esc_attr($r['name']);
87
+        if ($r['multi'] && !$r['id']) {
88 88
             $id = '';
89 89
         } else {
90
-            $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
90
+            $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'";
91 91
         }
92 92
         $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n";
93 93
 
94
-        if ( $show_option_all ) {
94
+        if ($show_option_all) {
95 95
             $output .= "\t<option value='0'>$show_option_all</option>\n";
96 96
         }
97 97
 
98
-        if ( $show_option_none ) {
99
-            $_selected = selected( $option_none_value, $r['selected'], false );
100
-            $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
98
+        if ($show_option_none) {
99
+            $_selected = selected($option_none_value, $r['selected'], false);
100
+            $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n";
101 101
         }
102 102
 
103
-        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
103
+        if ($r['include_selected'] && ($r['selected'] > 0)) {
104 104
             $found_selected = false;
105
-            $r['selected'] = (int) $r['selected'];
106
-            foreach ( (array) $users as $user ) {
107
-                $user->ID = (int) $user->ID;
108
-                if ( $user->ID === $r['selected'] ) {
105
+            $r['selected'] = (int)$r['selected'];
106
+            foreach ((array)$users as $user) {
107
+                $user->ID = (int)$user->ID;
108
+                if ($user->ID === $r['selected']) {
109 109
                     $found_selected = true;
110 110
                 }
111 111
             }
112 112
 
113
-            if ( ! $found_selected ) {
114
-                $users[] = get_userdata( $r['selected'] );
113
+            if (!$found_selected) {
114
+                $users[] = get_userdata($r['selected']);
115 115
             }
116 116
         }
117 117
 
118
-        foreach ( (array) $users as $user ) {
119
-            if ( 'display_name_with_login' === $show ) {
118
+        foreach ((array)$users as $user) {
119
+            if ('display_name_with_login' === $show) {
120 120
                 /* translators: 1: display name, 2: user_login */
121
-                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
122
-            } elseif ( 'display_name_with_email' === $show ) {
121
+                $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login);
122
+            } elseif ('display_name_with_email' === $show) {
123 123
                 /* translators: 1: display name, 2: user_email */
124
-                if ( $user->display_name == $user->user_email ) {
124
+                if ($user->display_name == $user->user_email) {
125 125
                     $display = $user->display_name;
126 126
                 } else {
127
-                    $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email );
127
+                    $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email);
128 128
                 }
129
-            } elseif ( ! empty( $user->$show ) ) {
129
+            } elseif (!empty($user->$show)) {
130 130
                 $display = $user->$show;
131 131
             } else {
132 132
                 $display = '(' . $user->user_login . ')';
133 133
             }
134 134
 
135
-            $_selected = selected( $user->ID, $r['selected'], false );
136
-            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
135
+            $_selected = selected($user->ID, $r['selected'], false);
136
+            $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
137 137
         }
138 138
 
139 139
         $output .= "</select>";
140 140
     }
141 141
 
142
-    $html = apply_filters( 'wpinv_dropdown_users', $output );
142
+    $html = apply_filters('wpinv_dropdown_users', $output);
143 143
 
144
-    if ( $r['echo'] ) {
144
+    if ($r['echo']) {
145 145
         echo $html;
146 146
     }
147 147
     return $html;
148 148
 }
149 149
 
150
-function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) {
151
-    if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) {
152
-        wpinv_login_user( $user_id );
150
+function wpinv_guest_redirect($redirect_to, $user_id = 0) {
151
+    if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) {
152
+        wpinv_login_user($user_id);
153 153
     } else {
154
-        $redirect_to = wp_login_url( $redirect_to );
154
+        $redirect_to = wp_login_url($redirect_to);
155 155
     }
156 156
     
157
-    $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id );
157
+    $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id);
158 158
     
159
-    wp_redirect( $redirect_to );
159
+    wp_redirect($redirect_to);
160 160
 }
161 161
 
162
-function wpinv_login_user( $user_id ) {
163
-    if ( is_user_logged_in() ) {
162
+function wpinv_login_user($user_id) {
163
+    if (is_user_logged_in()) {
164 164
         return true;
165 165
     }
166 166
     
167
-    $user = get_user_by( 'id', $user_id );
167
+    $user = get_user_by('id', $user_id);
168 168
     
169
-    if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) {
170
-        wp_set_current_user( $user_id, $user->user_login );
171
-        wp_set_auth_cookie( $user_id );
172
-        do_action( 'wp_login', $user->user_login );
169
+    if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) {
170
+        wp_set_current_user($user_id, $user->user_login);
171
+        wp_set_auth_cookie($user_id);
172
+        do_action('wp_login', $user->user_login);
173 173
         
174 174
         return true;
175 175
     }
Please login to merge, or discard this patch.
includes/wpinv-gd-functions.php 1 patch
Spacing   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_gd_active() {
8
-    return (bool)defined( 'GEODIRECTORY_VERSION' );
8
+    return (bool)defined('GEODIRECTORY_VERSION');
9 9
 }
10 10
 
11 11
 function wpinv_pm_active() {
12
-    return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' );
12
+    return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION');
13 13
 }
14 14
 
15
-function wpinv_is_gd_post_type( $post_type ) {
15
+function wpinv_is_gd_post_type($post_type) {
16 16
     global $gd_posttypes;
17 17
     
18
-    $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes();
18
+    $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes();
19 19
     
20
-    if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) {
20
+    if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) {
21 21
         return true;
22 22
     }
23 23
     
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
         return;
30 30
     }
31 31
     
32
-    if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
32
+    if (!(defined('DOING_AJAX') && DOING_AJAX)) {
33 33
         // Add  fields for force upgrade
34
-        if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) {
35
-            geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' );
34
+        if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) {
35
+            geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0');
36 36
             
37 37
             update_option('wpinv_gdp_column', '1');
38 38
         }
@@ -40,39 +40,39 @@  discard block
 block discarded – undo
40 40
         wpinv_merge_gd_packages_to_items();
41 41
     }
42 42
 }
43
-add_action( 'admin_init', 'wpinv_geodir_integration' );
43
+add_action('admin_init', 'wpinv_geodir_integration');
44 44
 
45
-function wpinv_get_gdp_package_type( $item_types ) {
46
-    if ( wpinv_pm_active() ) {
47
-        $item_types['package'] = __( 'Package', 'invoicing' );
45
+function wpinv_get_gdp_package_type($item_types) {
46
+    if (wpinv_pm_active()) {
47
+        $item_types['package'] = __('Package', 'invoicing');
48 48
     }
49 49
         
50 50
     return $item_types;
51 51
 }
52
-add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 );
52
+add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1);
53 53
 
54 54
 function wpinv_update_package_item($package_id) {
55 55
     return wpinv_merge_gd_package_to_item($package_id, true);
56 56
 }
57 57
 add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1);
58 58
 
59
-function wpinv_merge_gd_packages_to_items( $force = false ) {    
60
-    if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) {
59
+function wpinv_merge_gd_packages_to_items($force = false) {    
60
+    if ($merged = get_option('wpinv_merge_gd_packages') && !$force) {
61 61
         return true;
62 62
     }
63 63
 
64
-    if(!function_exists('geodir_package_list_info')){
64
+    if (!function_exists('geodir_package_list_info')) {
65 65
         return false;
66 66
     }
67 67
     
68 68
     $packages = geodir_package_list_info();
69 69
     
70
-    foreach ( $packages as $key => $package ) {
71
-        wpinv_merge_gd_package_to_item( $package->pid, $force, $package );
70
+    foreach ($packages as $key => $package) {
71
+        wpinv_merge_gd_package_to_item($package->pid, $force, $package);
72 72
     }
73 73
     
74
-    if ( !$merged ) {
75
-        update_option( 'wpinv_merge_gd_packages', 1 );
74
+    if (!$merged) {
75
+        update_option('wpinv_merge_gd_packages', 1);
76 76
     }
77 77
     
78 78
     return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
     $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package;
103 103
 
104
-    if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) {
104
+    if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) {
105 105
         return false;
106 106
     }
107 107
         
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
     $meta['post_type']          = $package->post_type;
112 112
     $meta['cpt_singular_name']  = get_post_type_singular_label($package->post_type);
113 113
     $meta['cpt_name']           = get_post_type_plural_label($package->post_type);
114
-    $meta['price']              = wpinv_format_amount( $package->amount, NULL, true );
114
+    $meta['price']              = wpinv_format_amount($package->amount, NULL, true);
115 115
     $meta['vat_rule']           = 'digital';
116 116
     $meta['vat_class']          = '_standard';
117 117
     
118
-    if ( !empty( $package->sub_active ) ) {
119
-        $sub_num_trial_days = absint( $package->sub_num_trial_days );
118
+    if (!empty($package->sub_active)) {
119
+        $sub_num_trial_days = absint($package->sub_num_trial_days);
120 120
         
121 121
         $meta['is_recurring']       = 1;
122 122
         $meta['recurring_period']   = $package->sub_units;
123
-        $meta['recurring_interval'] = absint( $package->sub_units_num );
124
-        $meta['recurring_limit']    = absint( $package->sub_units_num_times );
123
+        $meta['recurring_interval'] = absint($package->sub_units_num);
124
+        $meta['recurring_limit']    = absint($package->sub_units_num_times);
125 125
         $meta['free_trial']         = $sub_num_trial_days > 0 ? 1 : 0;
126 126
         $meta['trial_period']       = $package->sub_num_trial_units;
127 127
         $meta['trial_interval']     = $sub_num_trial_days;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $meta['trial_interval']     = '';
136 136
     }
137 137
     
138
-    $data  = array( 
138
+    $data = array( 
139 139
         'post_title'    => $package->title,
140 140
         'post_excerpt'  => $package->title_desc,
141 141
         'post_status'   => $package->status == 1 ? 'publish' : 'pending',
@@ -152,48 +152,48 @@  discard block
 block discarded – undo
152 152
     return $item;
153 153
 }
154 154
 
155
-function wpinv_gdp_to_wpi_gateway( $payment_method ) {
156
-    switch( $payment_method ) {
155
+function wpinv_gdp_to_wpi_gateway($payment_method) {
156
+    switch ($payment_method) {
157 157
         case 'prebanktransfer':
158 158
             $gateway = 'bank_transfer';
159 159
         break;
160 160
         default:
161
-            $gateway = empty( $payment_method ) ? 'manual' : $payment_method;
161
+            $gateway = empty($payment_method) ? 'manual' : $payment_method;
162 162
         break;
163 163
     }
164 164
     
165
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method );
165
+    return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method);
166 166
 }
167 167
 
168
-function wpinv_gdp_to_wpi_gateway_title( $payment_method ) {
169
-    $gateway = wpinv_gdp_to_wpi_gateway( $payment_method );
168
+function wpinv_gdp_to_wpi_gateway_title($payment_method) {
169
+    $gateway = wpinv_gdp_to_wpi_gateway($payment_method);
170 170
     
171
-    $gateway_title = wpinv_get_gateway_checkout_label( $gateway );
171
+    $gateway_title = wpinv_get_gateway_checkout_label($gateway);
172 172
     
173
-    if ( $gateway == $gateway_title ) {
174
-        $gateway_title = geodir_payment_method_title( $gateway );
173
+    if ($gateway == $gateway_title) {
174
+        $gateway_title = geodir_payment_method_title($gateway);
175 175
     }
176 176
     
177
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method );
177
+    return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method);
178 178
 }
179 179
 
180 180
 function wpinv_print_checkout_errors() {
181 181
     global $wpi_session;
182 182
     wpinv_print_errors();
183 183
 }
184
-add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 );
184
+add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10);
185 185
 
186
-function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) {
186
+function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) {
187 187
     global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge;
188 188
     
189
-    $invoice_info = geodir_get_invoice( $invoice_id );
189
+    $invoice_info = geodir_get_invoice($invoice_id);
190 190
     
191
-    $wpi_invoice_id  = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0;
191
+    $wpi_invoice_id  = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0;
192 192
     
193 193
     if (!empty($invoice_info)) {
194
-        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL;
194
+        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL;
195 195
         
196
-        if ( !empty( $wpi_invoice ) ) { // update invoice
196
+        if (!empty($wpi_invoice)) { // update invoice
197 197
             $save = false;
198 198
             if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) {
199 199
                 $save = true;
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
             
204 204
             if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) {
205 205
                 $save = true;
206
-                $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
207
-                $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
208
-                $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway );
209
-                $wpi_invoice->set('gateway', $gateway );
210
-                $wpi_invoice->set('gateway_title', $gateway_title );
206
+                $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
207
+                $gateway = wpinv_gdp_to_wpi_gateway($gateway);
208
+                $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway);
209
+                $wpi_invoice->set('gateway', $gateway);
210
+                $wpi_invoice->set('gateway_title', $gateway_title);
211 211
             }
212 212
             
213
-            if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) {
213
+            if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) {
214 214
                 $save = true;
215
-                $wpi_invoice->set( 'status', $status );
215
+                $wpi_invoice->set('status', $status);
216 216
             }
217 217
             
218 218
             if ($save) {
@@ -223,37 +223,37 @@  discard block
 block discarded – undo
223 223
             
224 224
             return $wpi_invoice;
225 225
         } else { // create invoice
226
-            $user_info = get_userdata( $invoice_info->user_id );
226
+            $user_info = get_userdata($invoice_info->user_id);
227 227
             
228
-            if ( !empty( $pre_status ) ) {
228
+            if (!empty($pre_status)) {
229 229
                 $invoice_info->status = $pre_status;
230 230
             }
231
-            $status = wpinv_gdp_to_wpi_status( $invoice_info->status );
231
+            $status = wpinv_gdp_to_wpi_status($invoice_info->status);
232 232
             
233 233
             $wpi_zero_tax = false;
234 234
             
235
-            if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
235
+            if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) {
236 236
                 $wpi_zero_tax = true;
237 237
             }
238 238
             
239 239
             $invoice_data                   = array();
240 240
             $invoice_data['invoice_id']     = $wpi_invoice_id;
241 241
             $invoice_data['status']         = $status;
242
-            if ( $update ) {
242
+            if ($update) {
243 243
                 //$invoice_data['private_note']   = __( 'Invoice was updated.', 'invoicing' );
244 244
             } else {
245
-                $invoice_data['private_note']   = wp_sprintf( __( 'Invoice was created with status %s.', 'invoicing' ), wpinv_status_nicename( $status ) );
245
+                $invoice_data['private_note'] = wp_sprintf(__('Invoice was created with status %s.', 'invoicing'), wpinv_status_nicename($status));
246 246
             }
247 247
             $invoice_data['user_id']        = $invoice_info->user_id;
248 248
             $invoice_data['created_via']    = 'API';
249 249
             
250
-            if ( !empty( $invoice_info->date ) ) {
251
-                $invoice_data['created_date']   = $invoice_info->date;
250
+            if (!empty($invoice_info->date)) {
251
+                $invoice_data['created_date'] = $invoice_info->date;
252 252
             }
253 253
             
254
-            $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
255
-            $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod );
256
-            $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod );
254
+            $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
255
+            $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod);
256
+            $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod);
257 257
             
258 258
             $invoice_data['payment_details'] = array( 
259 259
                 'gateway'           => $paymentmethod, 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
                 'paid'              => $status === 'publish' ? true : false
263 263
             );
264 264
             
265
-            $user_address = wpinv_get_user_address( $invoice_info->user_id, false );
265
+            $user_address = wpinv_get_user_address($invoice_info->user_id, false);
266 266
             
267 267
             $invoice_data['user_info'] = array( 
268 268
                 'user_id'       => $invoice_info->user_id, 
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
             
286 286
             $post_item = wpinv_get_gd_package_item($invoice_info->package_id);
287 287
             
288
-            if ( !empty( $post_item ) ) {
289
-                $cart_details  = array();
288
+            if (!empty($post_item)) {
289
+                $cart_details = array();
290 290
                 $cart_details[] = array(
291 291
                     'id'                => $post_item->ID,
292 292
                     'name'              => $post_item->get_name(),
@@ -299,19 +299,19 @@  discard block
 block discarded – undo
299 299
                                         ),
300 300
                 );
301 301
                 
302
-                $invoice_data['cart_details']  = $cart_details;
302
+                $invoice_data['cart_details'] = $cart_details;
303 303
             }
304 304
 
305
-            $data = array( 'invoice' => $invoice_data );
305
+            $data = array('invoice' => $invoice_data);
306 306
 
307 307
             $wpinv_api = new WPInv_API();
308
-            $data = $wpinv_api->insert_invoice( $data );
308
+            $data = $wpinv_api->insert_invoice($data);
309 309
             
310
-            if ( is_wp_error( $data ) ) {
311
-                wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() );
310
+            if (is_wp_error($data)) {
311
+                wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message());
312 312
             } else {
313
-                if ( !empty( $data ) ) {
314
-                    update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id );
313
+                if (!empty($data)) {
314
+                    update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id);
315 315
 
316 316
                     global $wpi_userID, $wpinv_ip_address_country;
317 317
                     
@@ -319,21 +319,21 @@  discard block
 block discarded – undo
319 319
                     
320 320
                     $data_session                   = array();
321 321
                     $data_session['invoice_id']     = $data->ID;
322
-                    $data_session['cart_discounts'] = $data->get_discounts( true );
322
+                    $data_session['cart_discounts'] = $data->get_discounts(true);
323 323
                     
324
-                    wpinv_set_checkout_session( $data_session );
324
+                    wpinv_set_checkout_session($data_session);
325 325
                     
326 326
                     $wpi_userID         = (int)$data->get_user_id();
327 327
                     $_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
328 328
                         
329
-                    $data->country      = sanitize_text_field( $_POST['country'] );
330
-                    $data->set( 'country', sanitize_text_field( $_POST['country'] ) );
329
+                    $data->country      = sanitize_text_field($_POST['country']);
330
+                    $data->set('country', sanitize_text_field($_POST['country']));
331 331
                     
332 332
                     $wpinv_ip_address_country = $data->country;
333 333
                     
334 334
                     $data = $data->recalculate_totals(true);
335 335
                     
336
-                    wpinv_set_checkout_session( $checkout_session );
336
+                    wpinv_set_checkout_session($checkout_session);
337 337
                     
338 338
                     $update_data = array();
339 339
                     $update_data['tax_amount'] = $data->get_tax();
@@ -341,14 +341,14 @@  discard block
 block discarded – undo
341 341
                     $update_data['invoice_id'] = $data->ID;
342 342
                     
343 343
                     global $wpdb;
344
-                    $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) );
344
+                    $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id));
345 345
                     
346 346
                     return $data;
347 347
                 } else {
348
-                    if ( $update ) {
349
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) );
348
+                    if ($update) {
349
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing'));
350 350
                     } else {
351
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) );
351
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing'));
352 352
                     }
353 353
                 }
354 354
             }
@@ -359,59 +359,59 @@  discard block
 block discarded – undo
359 359
 }
360 360
 add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3);
361 361
 
362
-function wpinv_cpt_update( $invoice_id ) {
363
-    return wpinv_cpt_save( $invoice_id, true );
362
+function wpinv_cpt_update($invoice_id) {
363
+    return wpinv_cpt_save($invoice_id, true);
364 364
 }
365 365
 add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1);
366 366
 
367
-function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) {
368
-    $invoice_info = geodir_get_invoice( $invoice_id );
369
-    if ( empty( $invoice_info ) ) {
367
+function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) {
368
+    $invoice_info = geodir_get_invoice($invoice_id);
369
+    if (empty($invoice_info)) {
370 370
         return false;
371 371
     }
372 372
 
373
-    $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
374
-    if ( !empty( $invoice ) ) {
373
+    $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
374
+    if (!empty($invoice)) {
375 375
         $new_status = wpinv_gdp_to_wpi_status($new_status);
376
-        $invoice    = wpinv_update_payment_status( $invoice->ID, $new_status );
376
+        $invoice    = wpinv_update_payment_status($invoice->ID, $new_status);
377 377
     } else {
378
-        $invoice = wpinv_cpt_save( $invoice_id );
378
+        $invoice = wpinv_cpt_save($invoice_id);
379 379
     }
380 380
     
381 381
     return $invoice;
382 382
 }
383
-add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
383
+add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
384 384
 
385
-function wpinv_transaction_details_note( $invoice_id, $html ) {
386
-    $invoice_info = geodir_get_invoice( $invoice_id );
387
-    if ( empty( $invoice_info ) ) {
385
+function wpinv_transaction_details_note($invoice_id, $html) {
386
+    $invoice_info = geodir_get_invoice($invoice_id);
387
+    if (empty($invoice_info)) {
388 388
         return false;
389 389
     }
390 390
 
391
-    $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL;
391
+    $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL;
392 392
     
393
-    if ( !$wpi_invoice_id ) {
394
-        $invoice = wpinv_cpt_save( $invoice_id, false, $old_status );
393
+    if (!$wpi_invoice_id) {
394
+        $invoice = wpinv_cpt_save($invoice_id, false, $old_status);
395 395
         
396
-        if ( !empty( $invoice ) ) {
396
+        if (!empty($invoice)) {
397 397
             $wpi_invoice_id = $invoice->ID;
398 398
         }
399 399
     }
400 400
 
401
-    $invoice = wpinv_get_invoice( $wpi_invoice_id );
401
+    $invoice = wpinv_get_invoice($wpi_invoice_id);
402 402
     
403
-    if ( empty( $invoice ) ) {
403
+    if (empty($invoice)) {
404 404
         return false;
405 405
     }
406 406
     
407
-    return $invoice->add_note( $html, true );
407
+    return $invoice->add_note($html, true);
408 408
 }
409
-add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 );
409
+add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2);
410 410
 
411
-function wpinv_gdp_to_wpi_status( $status ) {
411
+function wpinv_gdp_to_wpi_status($status) {
412 412
     $inv_status = $status ? $status : 'pending';
413 413
     
414
-    switch ( $status ) {
414
+    switch ($status) {
415 415
         case 'confirmed':
416 416
             $inv_status = 'publish';
417 417
         break;
@@ -420,10 +420,10 @@  discard block
 block discarded – undo
420 420
     return $inv_status;
421 421
 }
422 422
 
423
-function wpinv_wpi_to_gdp_status( $status ) {
423
+function wpinv_wpi_to_gdp_status($status) {
424 424
     $inv_status = $status ? $status : 'pending';
425 425
     
426
-    switch ( $status ) {
426
+    switch ($status) {
427 427
         case 'publish':
428 428
         case 'wpi-processing':
429 429
         case 'wpi-renewal':
@@ -434,98 +434,98 @@  discard block
 block discarded – undo
434 434
     return $inv_status;
435 435
 }
436 436
 
437
-function wpinv_wpi_to_gdp_id( $invoice_id ) {
437
+function wpinv_wpi_to_gdp_id($invoice_id) {
438 438
     global $wpdb;
439 439
     
440
-    return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) );
440
+    return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id)));
441 441
 }
442 442
 
443
-function wpinv_gdp_to_wpi_id( $invoice_id ) {
444
-    $invoice = geodir_get_invoice( $invoice_id );    
445
-    return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false);
443
+function wpinv_gdp_to_wpi_id($invoice_id) {
444
+    $invoice = geodir_get_invoice($invoice_id);    
445
+    return (empty($invoice->invoice_id) ? $invoice->invoice_id : false);
446 446
 }
447 447
 
448
-function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) {
448
+function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) {
449 449
     global $wpdb;
450 450
     
451
-    if ( !empty( $wpi_nosave ) ) {
451
+    if (!empty($wpi_nosave)) {
452 452
         return;
453 453
     }
454 454
     
455
-    $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID );
455
+    $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID);
456 456
     
457
-    if ( $gdp_invoice_id > 0 ) {
457
+    if ($gdp_invoice_id > 0) {
458 458
         $update_data = array();
459 459
         $update_data['tax_amount']      = $invoice->tax;
460 460
         $update_data['paied_amount']    = $invoice->total;
461 461
         $update_data['discount']        = $invoice->discount;
462 462
         $update_data['coupon_code']     = $invoice->discount_code;
463 463
         
464
-        $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) );
464
+        $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id));
465 465
     }
466 466
     
467 467
     return;
468 468
 }
469 469
 //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 );
470 470
 
471
-function wpinv_gdp_to_wpi_invoice( $invoice_id ) {
472
-    $invoice = geodir_get_invoice( $invoice_id );
473
-    if ( empty( $invoice->invoice_id ) ) {
471
+function wpinv_gdp_to_wpi_invoice($invoice_id) {
472
+    $invoice = geodir_get_invoice($invoice_id);
473
+    if (empty($invoice->invoice_id)) {
474 474
         return false;
475 475
     }
476 476
     
477
-    return wpinv_get_invoice( $invoice->invoice_id );
477
+    return wpinv_get_invoice($invoice->invoice_id);
478 478
 }
479 479
 
480
-function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) {
481
-    $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id );
482
-    if ( empty( $invoice ) ) {
480
+function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) {
481
+    $invoice = wpinv_gdp_to_wpi_invoice($invoice_id);
482
+    if (empty($invoice)) {
483 483
         return $status;
484 484
     }
485 485
 
486
-    if ( $status === 1 || $status === 0 ) {
487
-        if ( $status === 1 ) {
488
-            $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() );
486
+    if ($status === 1 || $status === 0) {
487
+        if ($status === 1) {
488
+            $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal());
489 489
         } else {
490 490
             $discount = '';
491 491
             $coupon_code = '';
492 492
         }
493 493
         
494
-        $invoice->set( 'discount', $discount );
495
-        $invoice->set( 'discount_code', $coupon_code );
494
+        $invoice->set('discount', $discount);
495
+        $invoice->set('discount_code', $coupon_code);
496 496
         $invoice->save();
497 497
         $invoice->recalculate_total();
498 498
     }
499 499
     
500 500
     return $status;
501 501
 }
502
-add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 );
502
+add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3);
503 503
 
504
-function wpinv_insert_invoice( $invoice_data = array() ) {
505
-    if ( empty( $invoice_data ) ) {
504
+function wpinv_insert_invoice($invoice_data = array()) {
505
+    if (empty($invoice_data)) {
506 506
         return false;
507 507
     }
508 508
 
509 509
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
510 510
     $default_args = array(
511
-        'status'        => !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending',
512
-        'user_note'     => !empty( $invoice_data['note'] ) ? $invoice_data['note'] : null,
513
-        'invoice_id'    => !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0,
514
-        'user_id'       => !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id(),
511
+        'status'        => !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending',
512
+        'user_note'     => !empty($invoice_data['note']) ? $invoice_data['note'] : null,
513
+        'invoice_id'    => !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0,
514
+        'user_id'       => !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id(),
515 515
     );
516 516
 
517
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data );
518
-    if ( is_wp_error( $invoice ) ) {
517
+    $invoice = wpinv_create_invoice($default_args, $invoice_data);
518
+    if (is_wp_error($invoice)) {
519 519
         return $invoice;
520 520
     }
521 521
 
522
-    $gateway = !empty( $invoice_data['gateway'] ) ? $invoice_data['gateway'] : '';
523
-    $gateway = empty( $gateway ) && isset( $_POST['gateway'] ) ? $_POST['gateway'] : $gateway;
522
+    $gateway = !empty($invoice_data['gateway']) ? $invoice_data['gateway'] : '';
523
+    $gateway = empty($gateway) && isset($_POST['gateway']) ? $_POST['gateway'] : $gateway;
524 524
     
525
-    if ( !empty( $gateway ) ) {
526
-        $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
525
+    if (!empty($gateway)) {
526
+        $gateway = wpinv_gdp_to_wpi_gateway($gateway);
527 527
         $invoice_data['payment_details']['gateway'] = $gateway;
528
-        $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title( $gateway );
528
+        $invoice_data['payment_details']['gateway_title'] = wpinv_gdp_to_wpi_gateway_title($gateway);
529 529
     }
530 530
     
531 531
     $user_info = array(
@@ -546,67 +546,67 @@  discard block
 block discarded – undo
546 546
         'discount'       => array(),
547 547
     );
548 548
     
549
-    $user_info    = wp_parse_args( $invoice_data['user_info'], $user_info );
549
+    $user_info = wp_parse_args($invoice_data['user_info'], $user_info);
550 550
     
551 551
     $payment_details = array();
552
-    if ( !empty( $invoice_data['payment_details'] ) ) {
552
+    if (!empty($invoice_data['payment_details'])) {
553 553
         $payment_details = array(
554 554
             'gateway'           => 'manual',
555
-            'gateway_title'     => __( 'Manual Payment', 'invoicing' ),
555
+            'gateway_title'     => __('Manual Payment', 'invoicing'),
556 556
             'currency'          => geodir_get_currency_type(),
557 557
             'paid'              => false,
558 558
             'transaction_id'    => '',
559 559
         );
560
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $payment_details );
560
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $payment_details);
561 561
     }
562
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) );
563
-    if ( !empty( $payment_details ) ) {
564
-        $invoice->set( 'currency', $payment_details['currency'] );
565
-        $invoice->set( 'gateway', $payment_details['gateway'] );
566
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
567
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
562
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending'));
563
+    if (!empty($payment_details)) {
564
+        $invoice->set('currency', $payment_details['currency']);
565
+        $invoice->set('gateway', $payment_details['gateway']);
566
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
567
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
568 568
     }
569 569
 
570
-    $invoice->set( 'user_info', $user_info );
570
+    $invoice->set('user_info', $user_info);
571 571
     ///$invoice->set( 'user_id', $user_info['user_id'] );
572 572
     ///$invoice->set( 'email', $user_info['email'] );
573
-    $invoice->set( 'first_name', $user_info['first_name'] );
574
-    $invoice->set( 'last_name', $user_info['last_name'] );
575
-    $invoice->set( 'address', $user_info['address'] );
576
-    $invoice->set( 'company', $user_info['company'] );
577
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
578
-    $invoice->set( 'phone', $user_info['phone'] );
579
-    $invoice->set( 'city', $user_info['city'] );
580
-    $invoice->set( 'country', $user_info['country'] );
581
-    $invoice->set( 'state', $user_info['state'] );
582
-    $invoice->set( 'zip', $user_info['zip'] );
583
-    $invoice->set( 'discounts', ( !empty( $user_info['discount'] ) ? $user_info['discount'] : array() ) );
584
-    $invoice->set( 'ip', wpinv_get_ip() );
585
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
586
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
573
+    $invoice->set('first_name', $user_info['first_name']);
574
+    $invoice->set('last_name', $user_info['last_name']);
575
+    $invoice->set('address', $user_info['address']);
576
+    $invoice->set('company', $user_info['company']);
577
+    $invoice->set('vat_number', $user_info['vat_number']);
578
+    $invoice->set('phone', $user_info['phone']);
579
+    $invoice->set('city', $user_info['city']);
580
+    $invoice->set('country', $user_info['country']);
581
+    $invoice->set('state', $user_info['state']);
582
+    $invoice->set('zip', $user_info['zip']);
583
+    $invoice->set('discounts', (!empty($user_info['discount']) ? $user_info['discount'] : array()));
584
+    $invoice->set('ip', wpinv_get_ip());
585
+    if (!empty($invoice_data['invoice_key'])) {
586
+        $invoice->set('key', $invoice_data['invoice_key']);
587 587
     }
588
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
589
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
588
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
589
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
590 590
     
591 591
     // Add note
592
-    if ( !empty( $invoice_data['user_note'] ) ) {
593
-        $invoice->add_note( $invoice_data['user_note'], true );
592
+    if (!empty($invoice_data['user_note'])) {
593
+        $invoice->add_note($invoice_data['user_note'], true);
594 594
     }
595 595
     
596
-    if ( !empty( $invoice_data['private_note'] ) ) {
597
-        $invoice->add_note( $invoice_data['private_note'] );
596
+    if (!empty($invoice_data['private_note'])) {
597
+        $invoice->add_note($invoice_data['private_note']);
598 598
     }
599 599
     
600
-    if ( is_array( $invoice_data['cart_details'] ) && !empty( $invoice_data['cart_details'] ) ) {
601
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
602
-            $item_id    = !empty( $item['id'] ) ? $item['id'] : 0;
603
-            $quantity   = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
604
-            $name       = !empty( $item['name'] ) ? $item['name'] : '';
605
-            $item_price = isset( $item['item_price'] ) ? $item['item_price'] : '';
600
+    if (is_array($invoice_data['cart_details']) && !empty($invoice_data['cart_details'])) {
601
+        foreach ($invoice_data['cart_details'] as $key => $item) {
602
+            $item_id    = !empty($item['id']) ? $item['id'] : 0;
603
+            $quantity   = !empty($item['quantity']) ? $item['quantity'] : 1;
604
+            $name       = !empty($item['name']) ? $item['name'] : '';
605
+            $item_price = isset($item['item_price']) ? $item['item_price'] : '';
606 606
             
607
-            $post_item  = new WPInv_Item( $item_id );
608
-            if ( !empty( $post_item ) ) {
609
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
607
+            $post_item  = new WPInv_Item($item_id);
608
+            if (!empty($post_item)) {
609
+                $name       = !empty($name) ? $name : $post_item->get_name();
610 610
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
611 611
             } else {
612 612
                 continue;
@@ -616,33 +616,33 @@  discard block
 block discarded – undo
616 616
                 'name'          => $name,
617 617
                 'quantity'      => $quantity,
618 618
                 'item_price'    => $item_price,
619
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
620
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
621
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
622
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
619
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
620
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
621
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
622
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
623 623
             );
624 624
 
625
-            $invoice->add_item( $item_id, $args );
625
+            $invoice->add_item($item_id, $args);
626 626
         }
627 627
     }
628 628
 
629
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
629
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
630 630
 
631
-    if ( isset( $invoice_data['post_date'] ) ) {
632
-        $invoice->set( 'date', $invoice_data['post_date'] );
631
+    if (isset($invoice_data['post_date'])) {
632
+        $invoice->set('date', $invoice_data['post_date']);
633 633
     }
634 634
 
635
-    $number = wpinv_format_invoice_number( $invoice->ID );
636
-    $invoice->set( 'number', $number );
637
-    update_option( 'wpinv_last_invoice_number', $number );
635
+    $number = wpinv_format_invoice_number($invoice->ID);
636
+    $invoice->set('number', $number);
637
+    update_option('wpinv_last_invoice_number', $number);
638 638
     
639 639
     $invoice->save();
640 640
     
641
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
641
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
642 642
 
643
-    if ( ! empty( $invoice->ID ) ) {
643
+    if (!empty($invoice->ID)) {
644 644
         // payment method (and payment_complete() if `paid` == true)
645
-        if ( !empty( $payment_details['paid'] ) ) {
645
+        if (!empty($payment_details['paid'])) {
646 646
             //$invoice->payment_complete( !empty( $payment_details['transaction_id'] ) ? $payment_details['transaction_id'] : $invoice->ID );
647 647
         }
648 648
             
@@ -659,158 +659,158 @@  discard block
 block discarded – undo
659 659
     }
660 660
     ?>
661 661
     <tr>
662
-        <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td>
663
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td>
664
-        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
662
+        <td><?php _e('Merge Price Packages', 'invoicing'); ?></td>
663
+        <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td>
664
+        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
665 665
     </tr>
666 666
     <tr>
667
-        <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td>
668
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td>
669
-        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
667
+        <td><?php _e('Merge Invoices', 'invoicing'); ?></td>
668
+        <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td>
669
+        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
670 670
     </tr>
671 671
 	<tr>
672
-        <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td>
673
-        <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td>
674
-        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
672
+        <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td>
673
+        <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td>
674
+        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
675 675
     </tr>
676 676
     <tr>
677
-        <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td>
678
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td>
679
-        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
677
+        <td><?php _e('Merge Coupons', 'invoicing'); ?></td>
678
+        <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td>
679
+        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
680 680
     </tr>
681 681
     <?php
682 682
 }
683
-add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 );
683
+add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10);
684 684
 
685 685
 function wpinv_tool_merge_packages() {
686 686
     $packages = geodir_package_list_info();
687 687
     
688 688
     $count = 0;
689 689
     
690
-    if ( !empty( $packages ) ) {
690
+    if (!empty($packages)) {
691 691
         $success = true;
692 692
         
693
-        foreach ( $packages as $key => $package ) {
693
+        foreach ($packages as $key => $package) {
694 694
             $item = wpinv_get_item_by('package_id', $package->pid);
695
-            if ( !empty( $item ) ) {
695
+            if (!empty($item)) {
696 696
                 continue;
697 697
             }
698 698
             
699
-            $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package );
699
+            $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package);
700 700
             
701
-            if ( !empty( $merged ) ) {
702
-                wpinv_error_log( 'Package merge S : ' . $package->pid );
701
+            if (!empty($merged)) {
702
+                wpinv_error_log('Package merge S : ' . $package->pid);
703 703
                 $count++;
704 704
             } else {
705
-                wpinv_error_log( 'Package merge F : ' . $package->pid );
705
+                wpinv_error_log('Package merge F : ' . $package->pid);
706 706
             }
707 707
         }
708 708
         
709
-        if ( $count > 0 ) {
710
-            $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count );
709
+        if ($count > 0) {
710
+            $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count);
711 711
         } else {
712
-            $message = __( 'No price packages merged.', 'invoicing' );
712
+            $message = __('No price packages merged.', 'invoicing');
713 713
         }
714 714
     } else {
715 715
         $success = false;
716
-        $message = __( 'No price packages found to merge!', 'invoicing' );
716
+        $message = __('No price packages found to merge!', 'invoicing');
717 717
     }
718 718
     
719 719
     $response = array();
720 720
     $response['success'] = $success;
721 721
     $response['data']['message'] = $message;
722
-    wp_send_json( $response );
722
+    wp_send_json($response);
723 723
 }
724
-add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' );
724
+add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages');
725 725
 
726 726
 function wpinv_tool_merge_invoices() {
727 727
     global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates;
728 728
     
729 729
     $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC";
730
-    $items = $wpdb->get_results( $sql );
730
+    $items = $wpdb->get_results($sql);
731 731
     
732 732
     $count = 0;
733 733
     
734
-    if ( !empty( $items ) ) {
734
+    if (!empty($items)) {
735 735
         $success = true;
736 736
         $wpi_gdp_inv_merge = true;
737 737
         
738
-        foreach ( $items as $item ) {
738
+        foreach ($items as $item) {
739 739
             $wpi_tax_rates = NULL;
740 740
             
741
-            $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" );
741
+            $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'");
742 742
             
743
-            $merged = wpinv_cpt_save( $item->id );
743
+            $merged = wpinv_cpt_save($item->id);
744 744
             
745
-            if ( !empty( $merged ) && !empty( $merged->ID ) ) {
745
+            if (!empty($merged) && !empty($merged->ID)) {
746 746
                 $count++;
747 747
                 
748 748
                 //$wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = '" . $merged->ID . "' WHERE id = '" . $item->id . "'" );
749 749
                 
750
-                $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' );
751
-                $post_date_gmt = get_gmt_from_date( $post_date );
752
-                $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
753
-                $post_modified_gmt = get_gmt_from_date( $post_modified );
750
+                $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql');
751
+                $post_date_gmt = get_gmt_from_date($post_date);
752
+                $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
753
+                $post_modified_gmt = get_gmt_from_date($post_modified);
754 754
                 
755
-                $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) );
755
+                $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID));
756 756
                 
757
-                if ( $merged->is_paid() ) {
758
-                    update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified );
757
+                if ($merged->is_paid()) {
758
+                    update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified);
759 759
                 }
760 760
                 
761
-                clean_post_cache( $merged->ID );
761
+                clean_post_cache($merged->ID);
762 762
                 
763
-                wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID );
763
+                wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID);
764 764
             } else {
765
-                wpinv_error_log( 'Invoice merge F : ' . $item->id );
765
+                wpinv_error_log('Invoice merge F : ' . $item->id);
766 766
             }
767 767
         }
768 768
         
769 769
         $wpi_gdp_inv_merge = false;
770 770
         
771
-        if ( $count > 0 ) {
772
-            $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count );
771
+        if ($count > 0) {
772
+            $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count);
773 773
         } else {
774
-            $message = __( 'No invoices merged.', 'invoicing' );
774
+            $message = __('No invoices merged.', 'invoicing');
775 775
         }
776 776
     } else {
777 777
         $success = false;
778
-        $message = __( 'No invoices found to merge!', 'invoicing' );
778
+        $message = __('No invoices found to merge!', 'invoicing');
779 779
     }
780 780
     
781 781
     $response = array();
782 782
     $response['success'] = $success;
783 783
     $response['data']['message'] = $message;
784
-    wp_send_json( $response );
784
+    wp_send_json($response);
785 785
 }
786
-add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' );
786
+add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices');
787 787
 
788 788
 function wpinv_tool_merge_coupons() {
789 789
     global $wpdb;
790 790
     
791 791
     $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC";
792
-    $items = $wpdb->get_results( $sql );
792
+    $items = $wpdb->get_results($sql);
793 793
     $count = 0;
794 794
     
795
-    if ( !empty( $items ) ) {
795
+    if (!empty($items)) {
796 796
         $success = true;
797 797
         
798
-        foreach ( $items as $item ) {
799
-            if ( wpinv_get_discount_by_code( $item->coupon_code ) ) {
798
+        foreach ($items as $item) {
799
+            if (wpinv_get_discount_by_code($item->coupon_code)) {
800 800
                 continue;
801 801
             }
802 802
             
803 803
             $args = array(
804 804
                 'post_type'   => 'wpi_discount',
805 805
                 'post_title'  => $item->coupon_code,
806
-                'post_status' => !empty( $item->status ) ? 'publish' : 'pending'
806
+                'post_status' => !empty($item->status) ? 'publish' : 'pending'
807 807
             );
808 808
 
809
-            $merged = wp_insert_post( $args );
809
+            $merged = wp_insert_post($args);
810 810
             
811 811
             $item_id = $item->cid;
812 812
             
813
-            if ( $merged ) {
813
+            if ($merged) {
814 814
                 $meta = array(
815 815
                     'code'              => $item->coupon_code,
816 816
                     'type'              => $item->discount_type != 'per' ? 'flat' : 'percent',
@@ -818,65 +818,65 @@  discard block
 block discarded – undo
818 818
                     'max_uses'          => (int)$item->usage_limit,
819 819
                     'uses'              => (int)$item->usage_count,
820 820
                 );
821
-                wpinv_store_discount( $merged, $meta, get_post( $merged ) );
821
+                wpinv_store_discount($merged, $meta, get_post($merged));
822 822
                 
823 823
                 $count++;
824 824
                 
825
-                wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged );
825
+                wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged);
826 826
             } else {
827
-                wpinv_error_log( 'Coupon merge F : ' . $item_id );
827
+                wpinv_error_log('Coupon merge F : ' . $item_id);
828 828
             }
829 829
         }
830 830
         
831
-        if ( $count > 0 ) {
832
-            $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count );
831
+        if ($count > 0) {
832
+            $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count);
833 833
         } else {
834
-            $message = __( 'No coupons merged.', 'invoicing' );
834
+            $message = __('No coupons merged.', 'invoicing');
835 835
         }
836 836
     } else {
837 837
         $success = false;
838
-        $message = __( 'No coupons found to merge!', 'invoicing' );
838
+        $message = __('No coupons found to merge!', 'invoicing');
839 839
     }
840 840
     
841 841
     $response = array();
842 842
     $response['success'] = $success;
843 843
     $response['data']['message'] = $message;
844
-    wp_send_json( $response );
844
+    wp_send_json($response);
845 845
 }
846
-add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' );
846
+add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons');
847 847
 
848
-function wpinv_gdp_to_wpi_currency( $value, $option = '' ) {
848
+function wpinv_gdp_to_wpi_currency($value, $option = '') {
849 849
     return wpinv_get_currency();
850 850
 }
851
-add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 );
851
+add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2);
852 852
 
853
-function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) {
853
+function wpinv_gdp_to_wpi_currency_sign($value, $option = '') {
854 854
     return wpinv_currency_symbol();
855 855
 }
856
-add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 );
856
+add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2);
857 857
 
858
-function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) {
859
-    if ( !$display ) {
860
-        $price = wpinv_format_amount( $amount, NULL, true );
858
+function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) {
859
+    if (!$display) {
860
+        $price = wpinv_format_amount($amount, NULL, true);
861 861
     } else {
862
-        $price = wpinv_price( wpinv_format_amount( $amount ) );
862
+        $price = wpinv_price(wpinv_format_amount($amount));
863 863
     }
864 864
     
865 865
     return $price;
866 866
 }
867
-add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 );
867
+add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5);
868 868
 
869
-function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) {
869
+function wpinv_gdp_to_inv_checkout_redirect($redirect_url) {
870 870
     $invoice_id         = geodir_payment_cart_id();
871
-    $invoice_info       = geodir_get_invoice( $invoice_id );
872
-    $wpi_invoice        = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
871
+    $invoice_info       = geodir_get_invoice($invoice_id);
872
+    $wpi_invoice        = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
873 873
     
874
-    if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) {
875
-        $wpi_invoice_id = wpinv_cpt_save( $invoice_id );
876
-        $wpi_invoice    = wpinv_get_invoice( $wpi_invoice_id );
874
+    if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) {
875
+        $wpi_invoice_id = wpinv_cpt_save($invoice_id);
876
+        $wpi_invoice    = wpinv_get_invoice($wpi_invoice_id);
877 877
     }
878 878
     
879
-    if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) {
879
+    if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) {
880 880
         
881 881
         // Clear cart
882 882
         geodir_payment_clear_cart();
@@ -886,121 +886,121 @@  discard block
 block discarded – undo
886 886
     
887 887
     return $redirect_url;
888 888
 }
889
-add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 );
889
+add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1);
890 890
 
891
-function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) {    
892
-    if ( get_current_user_id() ) {        
893
-        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>';
891
+function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) {    
892
+    if (get_current_user_id()) {        
893
+        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>';
894 894
     }
895 895
 
896 896
     return $dashboard_links;
897 897
 }
898
-add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
899
-remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
898
+add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link');
899
+remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link');
900 900
 
901
-function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
901
+function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) {
902 902
     if (!defined('GEODIRPAYMENT_VERSION')) {
903 903
         return false;
904 904
     }
905 905
     
906
-    $invoice    = wpinv_get_invoice( $invoice_id );
907
-    if ( empty( $invoice ) ) {
906
+    $invoice = wpinv_get_invoice($invoice_id);
907
+    if (empty($invoice)) {
908 908
         return false;
909 909
     }
910 910
     
911
-    remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
911
+    remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
912 912
     
913
-    $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id );
914
-    $new_status = wpinv_wpi_to_gdp_status( $new_status );
913
+    $invoice_id = wpinv_wpi_to_gdp_id($invoice_id);
914
+    $new_status = wpinv_wpi_to_gdp_status($new_status);
915 915
     
916
-    geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() );
916
+    geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring());
917 917
 }
918
-add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 );
918
+add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3);
919 919
 
920
-function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) {
921
-    $item = wpinv_get_item_by( 'package_id', $gd_package_id );
920
+function wpinv_gdp_to_wpi_delete_package($gd_package_id) {
921
+    $item = wpinv_get_item_by('package_id', $gd_package_id);
922 922
     
923
-    if ( !empty( $item ) ) {
924
-        wpinv_remove_item( $item, true );
923
+    if (!empty($item)) {
924
+        wpinv_remove_item($item, true);
925 925
     }
926 926
 }
927
-add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ;
927
+add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1);
928 928
 
929
-function wpinv_can_delete_package_item( $return, $post_id ) {
930
-    if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_package_id', true ) ) {
931
-        $gd_package = geodir_get_package_info_by_id( $package_id, '' );
929
+function wpinv_can_delete_package_item($return, $post_id) {
930
+    if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_package_id', true)) {
931
+        $gd_package = geodir_get_package_info_by_id($package_id, '');
932 932
         
933
-        if ( !empty( $gd_package ) ) {
933
+        if (!empty($gd_package)) {
934 934
             $return = false;
935 935
         }
936 936
     }
937 937
 
938 938
     return $return;
939 939
 }
940
-add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 );
940
+add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2);
941 941
 
942
-function wpinv_package_item_classes( $classes, $class, $post_id ) {
942
+function wpinv_package_item_classes($classes, $class, $post_id) {
943 943
     global $typenow;
944 944
 
945
-    if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) {
946
-        if ( wpinv_item_in_use( $post_id ) ) {
945
+    if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) {
946
+        if (wpinv_item_in_use($post_id)) {
947 947
             $classes[] = 'wpi-inuse-pkg';
948
-        } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_package_id', true ), '' ) ) ) {
948
+        } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_package_id', true), ''))) {
949 949
             $classes[] = 'wpi-delete-pkg';
950 950
         }
951 951
     }
952 952
 
953 953
     return $classes;
954 954
 }
955
-add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 );
955
+add_filter('post_class', 'wpinv_package_item_classes', 10, 3);
956 956
 
957
-function wpinv_gdp_package_type_info( $post ) {
958
-    if ( wpinv_pm_active() ) {
959
-        ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p>
957
+function wpinv_gdp_package_type_info($post) {
958
+    if (wpinv_pm_active()) {
959
+        ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p>
960 960
         <?php
961 961
     }
962 962
 }
963
-add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ;
963
+add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1);
964 964
 
965
-function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) {
965
+function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) {
966 966
     global $wpi_zero_tax;
967 967
 
968
-    if ( $wpi_zero_tax ) {
968
+    if ($wpi_zero_tax) {
969 969
         $is_taxable = false;
970 970
     }
971 971
 
972 972
     return $is_taxable;
973 973
 }
974
-add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ;
974
+add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4);
975 975
 
976 976
 function wpinv_tool_merge_fix_taxes() {
977 977
     global $wpdb;
978 978
     
979 979
 	$sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'";
980
-	$items = $wpdb->get_results( $sql );
980
+	$items = $wpdb->get_results($sql);
981 981
 	
982
-	if ( !empty( $items ) ) {
983
-		foreach ( $items as $item ) {
984
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
985
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
982
+	if (!empty($items)) {
983
+		foreach ($items as $item) {
984
+			if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') {
985
+				update_post_meta($item->ID, '_wpinv_vat_class', '_standard');
986 986
 			}
987 987
 		}
988 988
 	}
989 989
 		
990 990
     $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC";
991
-    $items = $wpdb->get_results( $sql );
991
+    $items = $wpdb->get_results($sql);
992 992
 	
993
-	if ( !empty( $items ) ) {
993
+	if (!empty($items)) {
994 994
 		$success = false;
995
-        $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
995
+        $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing');
996 996
 		
997 997
 		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
998 998
 		
999
-		foreach ( $items as $item ) {
999
+		foreach ($items as $item) {
1000 1000
 			$wpi_tax_rates = NULL;               
1001 1001
 			$data = wpinv_get_invoice($item->ID);
1002 1002
 
1003
-			if ( empty( $data ) ) {
1003
+			if (empty($data)) {
1004 1004
 				continue;
1005 1005
 			}
1006 1006
 			
@@ -1008,51 +1008,51 @@  discard block
 block discarded – undo
1008 1008
 			
1009 1009
 			$data_session                   = array();
1010 1010
 			$data_session['invoice_id']     = $data->ID;
1011
-			$data_session['cart_discounts'] = $data->get_discounts( true );
1011
+			$data_session['cart_discounts'] = $data->get_discounts(true);
1012 1012
 			
1013
-			wpinv_set_checkout_session( $data_session );
1013
+			wpinv_set_checkout_session($data_session);
1014 1014
 			
1015 1015
 			$wpi_userID         = (int)$data->get_user_id();
1016 1016
 			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
1017 1017
 				
1018
-			$data->country      = sanitize_text_field( $_POST['country'] );
1019
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
1018
+			$data->country      = sanitize_text_field($_POST['country']);
1019
+			$data->set('country', sanitize_text_field($_POST['country']));
1020 1020
 			
1021 1021
 			$wpinv_ip_address_country = $data->country;
1022 1022
 			
1023 1023
 			$data->recalculate_totals(true);
1024 1024
 			
1025
-			wpinv_set_checkout_session( $checkout_session );
1025
+			wpinv_set_checkout_session($checkout_session);
1026 1026
 			
1027 1027
 			$update_data = array();
1028 1028
 			$update_data['tax_amount'] = $data->get_tax();
1029 1029
 			$update_data['paied_amount'] = $data->get_total();
1030 1030
 			$update_data['invoice_id'] = $data->ID;
1031 1031
 			
1032
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
1032
+			$wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id));
1033 1033
 		}
1034 1034
 	} else {
1035 1035
         $success = false;
1036
-        $message = __( 'No invoices found to fix taxes!', 'invoicing' );
1036
+        $message = __('No invoices found to fix taxes!', 'invoicing');
1037 1037
     }
1038 1038
 	
1039 1039
 	$response = array();
1040 1040
     $response['success'] = $success;
1041 1041
     $response['data']['message'] = $message;
1042
-    wp_send_json( $response );
1042
+    wp_send_json($response);
1043 1043
 }
1044
-add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' );
1045
-remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 );
1044
+add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes');
1045
+remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2);
1046 1046
 
1047
-function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) {
1048
-    if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) {
1049
-        if ( $invoice->is_renewal() ) {
1047
+function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) {
1048
+    if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) {
1049
+        if ($invoice->is_renewal()) {
1050 1050
             $invoice = $invoice->get_parent_payment();
1051 1051
         }
1052 1052
         
1053
-        if ( !empty( $invoice ) ) {
1054
-            wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() );
1053
+        if (!empty($invoice)) {
1054
+            wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status());
1055 1055
         }
1056 1056
     }
1057 1057
 }
1058
-add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 );
1059 1058
\ No newline at end of file
1059
+add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2);
1060 1060
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-post-types.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -7,36 +7,36 @@  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
-add_action( 'init', 'wpinv_register_post_types', 1 );
14
+add_action('init', 'wpinv_register_post_types', 1);
15 15
 function wpinv_register_post_types() {    
16 16
     $labels = array(
17
-        'name'               => _x( 'Invoices', 'post type general name', 'invoicing' ),
18
-        'singular_name'      => _x( 'Invoice', 'post type singular name', 'invoicing' ),
19
-        'menu_name'          => _x( 'Invoices', 'admin menu', 'invoicing' ),
20
-        'name_admin_bar'     => _x( 'Invoice', 'add new on admin bar', 'invoicing' ),
21
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
22
-        'add_new_item'       => __( 'Add New Invoice', 'invoicing' ),
23
-        'new_item'           => __( 'New Invoice', 'invoicing' ),
24
-        'edit_item'          => __( 'Edit Invoice', 'invoicing' ),
25
-        'view_item'          => __( 'View Invoice', 'invoicing' ),
26
-        'all_items'          => __( 'Invoices', 'invoicing' ),
27
-        'search_items'       => __( 'Search Invoices', 'invoicing' ),
28
-        'parent_item_colon'  => __( 'Parent Invoices:', 'invoicing' ),
29
-        'not_found'          => __( 'No invoices found.', 'invoicing' ),
30
-        'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' )
17
+        'name'               => _x('Invoices', 'post type general name', 'invoicing'),
18
+        'singular_name'      => _x('Invoice', 'post type singular name', 'invoicing'),
19
+        'menu_name'          => _x('Invoices', 'admin menu', 'invoicing'),
20
+        'name_admin_bar'     => _x('Invoice', 'add new on admin bar', 'invoicing'),
21
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
22
+        'add_new_item'       => __('Add New Invoice', 'invoicing'),
23
+        'new_item'           => __('New Invoice', 'invoicing'),
24
+        'edit_item'          => __('Edit Invoice', 'invoicing'),
25
+        'view_item'          => __('View Invoice', 'invoicing'),
26
+        'all_items'          => __('Invoices', 'invoicing'),
27
+        'search_items'       => __('Search Invoices', 'invoicing'),
28
+        'parent_item_colon'  => __('Parent Invoices:', 'invoicing'),
29
+        'not_found'          => __('No invoices found.', 'invoicing'),
30
+        'not_found_in_trash' => __('No invoices found in trash.', 'invoicing')
31 31
     );
32
-    $labels = apply_filters( 'wpinv_labels', $labels );
32
+    $labels = apply_filters('wpinv_labels', $labels);
33 33
     
34 34
     $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico';
35
-    $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon );
35
+    $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon);
36 36
 
37 37
     $args = array(
38 38
         'labels'             => $labels,
39
-        'description'        => __( 'This is where invoices are stored.', 'invoicing' ),
39
+        'description'        => __('This is where invoices are stored.', 'invoicing'),
40 40
         'public'             => true,
41 41
         'can_export'         => true,
42 42
         '_builtin'           => false,
@@ -50,68 +50,68 @@  discard block
 block discarded – undo
50 50
         'has_archive'        => false,
51 51
         'hierarchical'       => false,
52 52
         'menu_position'      => null,
53
-        'supports'           => array( 'title', 'author' ),
53
+        'supports'           => array('title', 'author'),
54 54
         'menu_icon'          => $menu_icon,
55 55
     );
56 56
             
57
-    $args = apply_filters( 'wpinv_register_post_type_invoice', $args );
57
+    $args = apply_filters('wpinv_register_post_type_invoice', $args);
58 58
     
59
-    register_post_type( 'wpi_invoice', $args );
59
+    register_post_type('wpi_invoice', $args);
60 60
     
61 61
     $items_labels = array(
62
-        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
63
-        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
64
-        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
65
-        'add_new'            => _x( 'Add New', 'wpi_item', 'invoicing' ),
66
-        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
67
-        'new_item'           => __( 'New Item', 'invoicing' ),
68
-        'edit_item'          => __( 'Edit Item', 'invoicing' ),
69
-        'view_item'          => __( 'View Item', 'invoicing' ),
70
-        'all_items'          => __( 'Items', 'invoicing' ),
71
-        'search_items'       => __( 'Search Items', 'invoicing' ),
62
+        'name'               => _x('Items', 'post type general name', 'invoicing'),
63
+        'singular_name'      => _x('Item', 'post type singular name', 'invoicing'),
64
+        'menu_name'          => _x('Items', 'admin menu', 'invoicing'),
65
+        'add_new'            => _x('Add New', 'wpi_item', 'invoicing'),
66
+        'add_new_item'       => __('Add New Item', 'invoicing'),
67
+        'new_item'           => __('New Item', 'invoicing'),
68
+        'edit_item'          => __('Edit Item', 'invoicing'),
69
+        'view_item'          => __('View Item', 'invoicing'),
70
+        'all_items'          => __('Items', 'invoicing'),
71
+        'search_items'       => __('Search Items', 'invoicing'),
72 72
         'parent_item_colon'  => '',
73
-        'not_found'          => __( 'No items found.', 'invoicing' ),
74
-        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
73
+        'not_found'          => __('No items found.', 'invoicing'),
74
+        'not_found_in_trash' => __('No items found in trash.', 'invoicing')
75 75
     );
76
-    $items_labels = apply_filters( 'wpinv_items_labels', $items_labels );
76
+    $items_labels = apply_filters('wpinv_items_labels', $items_labels);
77 77
     
78 78
     $invoice_item_args = array(
79 79
         'labels'                => $items_labels,
80 80
         'public'                => false,
81 81
         'show_ui'               => true,
82 82
         'show_in_menu'          => 'wpinv',
83
-        'supports'              => array( 'title', 'excerpt' ),
83
+        'supports'              => array('title', 'excerpt'),
84 84
         'register_meta_box_cb'  => 'wpinv_register_item_meta_boxes',
85 85
         'rewrite'               => false,
86 86
         'query_var'             => false,
87 87
         'map_meta_cap'          => true,
88 88
         'can_export'            => true,
89 89
     );
90
-    $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args );
90
+    $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args);
91 91
 
92
-    register_post_type( 'wpi_item', $invoice_item_args );
92
+    register_post_type('wpi_item', $invoice_item_args);
93 93
     
94 94
     $labels = array(
95
-        'name'               => _x( 'Discounts', 'post type general name', 'invoicing' ),
96
-        'singular_name'      => _x( 'Discount', 'post type singular name', 'invoicing' ),
97
-        'menu_name'          => _x( 'Discounts', 'admin menu', 'invoicing' ),
98
-        'name_admin_bar'     => _x( 'Discount', 'add new on admin bar', 'invoicing' ),
99
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
100
-        'add_new_item'       => __( 'Add New Discount', 'invoicing' ),
101
-        'new_item'           => __( 'New Discount', 'invoicing' ),
102
-        'edit_item'          => __( 'Edit Discount', 'invoicing' ),
103
-        'view_item'          => __( 'View Discount', 'invoicing' ),
104
-        'all_items'          => __( 'Discounts', 'invoicing' ),
105
-        'search_items'       => __( 'Search Discounts', 'invoicing' ),
106
-        'parent_item_colon'  => __( 'Parent Discounts:', 'invoicing' ),
107
-        'not_found'          => __( 'No discounts found.', 'invoicing' ),
108
-        'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' )
95
+        'name'               => _x('Discounts', 'post type general name', 'invoicing'),
96
+        'singular_name'      => _x('Discount', 'post type singular name', 'invoicing'),
97
+        'menu_name'          => _x('Discounts', 'admin menu', 'invoicing'),
98
+        'name_admin_bar'     => _x('Discount', 'add new on admin bar', 'invoicing'),
99
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
100
+        'add_new_item'       => __('Add New Discount', 'invoicing'),
101
+        'new_item'           => __('New Discount', 'invoicing'),
102
+        'edit_item'          => __('Edit Discount', 'invoicing'),
103
+        'view_item'          => __('View Discount', 'invoicing'),
104
+        'all_items'          => __('Discounts', 'invoicing'),
105
+        'search_items'       => __('Search Discounts', 'invoicing'),
106
+        'parent_item_colon'  => __('Parent Discounts:', 'invoicing'),
107
+        'not_found'          => __('No discounts found.', 'invoicing'),
108
+        'not_found_in_trash' => __('No discounts found in trash.', 'invoicing')
109 109
     );
110
-    $labels = apply_filters( 'wpinv_discounts_labels', $labels );
110
+    $labels = apply_filters('wpinv_discounts_labels', $labels);
111 111
     
112 112
     $args = array(
113 113
         'labels'             => $labels,
114
-        'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
114
+        'description'        => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'),
115 115
         'public'             => false,
116 116
         'can_export'         => true,
117 117
         '_builtin'           => false,
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         'map_meta_cap'       => true,
126 126
         'has_archive'        => false,
127 127
         'hierarchical'       => false,
128
-        'supports'           => array( 'title', 'excerpt' ),
128
+        'supports'           => array('title', 'excerpt'),
129 129
         'register_meta_box_cb'  => 'wpinv_register_discount_meta_boxes',
130 130
         'show_in_nav_menus'  => false,
131 131
         'show_in_admin_bar'  => true,
@@ -133,99 +133,99 @@  discard block
 block discarded – undo
133 133
         'menu_position'      => null,
134 134
     );
135 135
             
136
-    $args = apply_filters( 'wpinv_register_post_type_discount', $args );
136
+    $args = apply_filters('wpinv_register_post_type_discount', $args);
137 137
     
138
-    register_post_type( 'wpi_discount', $args );
138
+    register_post_type('wpi_discount', $args);
139 139
 }
140 140
 
141 141
 function wpinv_get_default_labels() {
142 142
     $defaults = array(
143
-       'singular' => __( 'Invoice', 'invoicing' ),
144
-       'plural'   => __( 'Invoices', 'invoicing' )
143
+       'singular' => __('Invoice', 'invoicing'),
144
+       'plural'   => __('Invoices', 'invoicing')
145 145
     );
146 146
     
147
-    return apply_filters( 'wpinv_default_invoices_name', $defaults );
147
+    return apply_filters('wpinv_default_invoices_name', $defaults);
148 148
 }
149 149
 
150
-function wpinv_get_label_singular( $lowercase = false ) {
150
+function wpinv_get_label_singular($lowercase = false) {
151 151
     $defaults = wpinv_get_default_labels();
152 152
     
153
-    return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
153
+    return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular'];
154 154
 }
155 155
 
156
-function wpinv_get_label_plural( $lowercase = false ) {
156
+function wpinv_get_label_plural($lowercase = false) {
157 157
     $defaults = wpinv_get_default_labels();
158 158
     
159
-    return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
159
+    return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural'];
160 160
 }
161 161
 
162
-function wpinv_change_default_title( $title ) {
163
-     if ( !is_admin() ) {
162
+function wpinv_change_default_title($title) {
163
+     if (!is_admin()) {
164 164
         $label = wpinv_get_label_singular();
165
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
165
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
166 166
         return $title;
167 167
      }
168 168
 
169 169
      $screen = get_current_screen();
170 170
 
171
-     if ( 'wpi_invoice' == $screen->post_type ) {
171
+     if ('wpi_invoice' == $screen->post_type) {
172 172
         $label = wpinv_get_label_singular();
173
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
173
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
174 174
      }
175 175
 
176 176
      return $title;
177 177
 }
178
-add_filter( 'enter_title_here', 'wpinv_change_default_title' );
178
+add_filter('enter_title_here', 'wpinv_change_default_title');
179 179
 
180 180
 function wpinv_register_post_status() {
181
-    register_post_status( 'wpi-processing', array(
182
-        'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
181
+    register_post_status('wpi-processing', array(
182
+        'label'                     => _x('Processing', 'Invoice status', 'invoicing'),
183 183
         'public'                    => true,
184 184
         'exclude_from_search'       => true,
185 185
         'show_in_admin_all_list'    => true,
186 186
         'show_in_admin_status_list' => true,
187
-        'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
188
-    ) );
189
-    register_post_status( 'wpi-onhold', array(
190
-        'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
187
+        'label_count'               => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing')
188
+    ));
189
+    register_post_status('wpi-onhold', array(
190
+        'label'                     => _x('On Hold', 'Invoice status', 'invoicing'),
191 191
         'public'                    => true,
192 192
         'exclude_from_search'       => true,
193 193
         'show_in_admin_all_list'    => true,
194 194
         'show_in_admin_status_list' => true,
195
-        'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
196
-    ) );
197
-    register_post_status( 'wpi-cancelled', array(
198
-        'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
195
+        'label_count'               => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing')
196
+    ));
197
+    register_post_status('wpi-cancelled', array(
198
+        'label'                     => _x('Cancelled', 'Invoice status', 'invoicing'),
199 199
         'public'                    => true,
200 200
         'exclude_from_search'       => true,
201 201
         'show_in_admin_all_list'    => true,
202 202
         'show_in_admin_status_list' => true,
203
-        'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
204
-    ) );
205
-    register_post_status( 'wpi-refunded', array(
206
-        'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
203
+        'label_count'               => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing')
204
+    ));
205
+    register_post_status('wpi-refunded', array(
206
+        'label'                     => _x('Refunded', 'Invoice status', 'invoicing'),
207 207
         'public'                    => true,
208 208
         'exclude_from_search'       => true,
209 209
         'show_in_admin_all_list'    => true,
210 210
         'show_in_admin_status_list' => true,
211
-        'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
212
-    ) );
213
-    register_post_status( 'wpi-failed', array(
214
-        'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
211
+        'label_count'               => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing')
212
+    ));
213
+    register_post_status('wpi-failed', array(
214
+        'label'                     => _x('Failed', 'Invoice status', 'invoicing'),
215 215
         'public'                    => true,
216 216
         'exclude_from_search'       => true,
217 217
         'show_in_admin_all_list'    => true,
218 218
         'show_in_admin_status_list' => true,
219
-        'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
220
-    ) );
221
-    register_post_status( 'wpi-renewal', array(
222
-        'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
219
+        'label_count'               => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing')
220
+    ));
221
+    register_post_status('wpi-renewal', array(
222
+        'label'                     => _x('Renewal', 'Invoice status', 'invoicing'),
223 223
         'public'                    => true,
224 224
         'exclude_from_search'       => true,
225 225
         'show_in_admin_all_list'    => true,
226 226
         'show_in_admin_status_list' => true,
227
-        'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
228
-    ) );
227
+        'label_count'               => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing')
228
+    ));
229 229
 }
230
-add_action( 'init', 'wpinv_register_post_status', 10 );
230
+add_action('init', 'wpinv_register_post_status', 10);
231 231
 
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -7,112 +7,112 @@  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 ) {
44
+function wpinv_sanitize_amount($amount) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_seperator();
47 47
     $decimal_sep   = wpinv_decimal_seperator();
48 48
 
49 49
     // Sanitize the amount
50
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
51
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
52
-            $amount = str_replace( $thousands_sep, '', $amount );
53
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
54
-            $amount = str_replace( '.', '', $amount );
50
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
51
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
52
+            $amount = str_replace($thousands_sep, '', $amount);
53
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
54
+            $amount = str_replace('.', '', $amount);
55 55
         }
56 56
 
57
-        $amount = str_replace( $decimal_sep, '.', $amount );
58
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
59
-        $amount = str_replace( $thousands_sep, '', $amount );
57
+        $amount = str_replace($decimal_sep, '.', $amount);
58
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
59
+        $amount = str_replace($thousands_sep, '', $amount);
60 60
     }
61 61
 
62
-    if( $amount < 0 ) {
62
+    if ($amount < 0) {
63 63
         $is_negative = true;
64 64
     }
65 65
 
66
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
66
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
67 67
 
68
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', 2, $amount );
69
-    $amount   = number_format( (double) $amount, $decimals, '.', '' );
68
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', 2, $amount);
69
+    $amount   = number_format((double)$amount, $decimals, '.', '');
70 70
 
71
-    if( $is_negative ) {
71
+    if ($is_negative) {
72 72
         $amount *= -1;
73 73
     }
74 74
 
75
-    return apply_filters( 'wpinv_sanitize_amount', $amount );
75
+    return apply_filters('wpinv_sanitize_amount', $amount);
76 76
 }
77 77
 
78
-function wpinv_get_invoice_statuses( $trashed = false ) {
78
+function wpinv_get_invoice_statuses($trashed = false) {
79 79
     $invoice_statuses = array(
80
-        'pending'       => __( 'Pending Payment', 'invoicing' ),
81
-        'publish'       => __( 'Paid', 'invoicing' ),
82
-        'wpi-processing'    => __( 'Processing', 'invoicing' ),
83
-        'wpi-onhold'        => __( 'On Hold', 'invoicing' ),
84
-        'wpi-refunded'      => __( 'Refunded', 'invoicing' ),
85
-        'wpi-cancelled'     => __( 'Cancelled', 'invoicing' ),
86
-        'wpi-failed'        => __( 'Failed', 'invoicing' ),
87
-        'wpi-renewal'       => __( 'Renewal Payment', 'invoicing' )
80
+        'pending'       => __('Pending Payment', 'invoicing'),
81
+        'publish'       => __('Paid', 'invoicing'),
82
+        'wpi-processing'    => __('Processing', 'invoicing'),
83
+        'wpi-onhold'        => __('On Hold', 'invoicing'),
84
+        'wpi-refunded'      => __('Refunded', 'invoicing'),
85
+        'wpi-cancelled'     => __('Cancelled', 'invoicing'),
86
+        'wpi-failed'        => __('Failed', 'invoicing'),
87
+        'wpi-renewal'       => __('Renewal Payment', 'invoicing')
88 88
     );
89 89
     
90
-    if ( $trashed ) {
91
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
90
+    if ($trashed) {
91
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
92 92
     }
93 93
 
94
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
94
+    return apply_filters('wpinv_statuses', $invoice_statuses);
95 95
 }
96 96
 
97
-function wpinv_status_nicename( $status ) {
97
+function wpinv_status_nicename($status) {
98 98
     $statuses = wpinv_get_invoice_statuses();
99
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
99
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
100 100
 
101 101
     return $status;
102 102
 }
103 103
 
104 104
 function wpinv_get_currency() {
105
-    $currency = wpinv_get_option( 'currency', 'USD' );
105
+    $currency = wpinv_get_option('currency', 'USD');
106 106
     
107
-    return apply_filters( 'wpinv_currency', $currency );
107
+    return apply_filters('wpinv_currency', $currency);
108 108
 }
109 109
 
110
-function wpinv_currency_symbol( $currency = '' ) {
111
-    if ( empty( $currency ) ) {
110
+function wpinv_currency_symbol($currency = '') {
111
+    if (empty($currency)) {
112 112
         $currency = wpinv_get_currency();
113 113
     }
114 114
     
115
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
115
+    $symbols = apply_filters('wpinv_currency_symbols', array(
116 116
         'AED' => 'د.إ',
117 117
         'ARS' => '&#36;',
118 118
         'AUD' => '&#36;',
@@ -164,78 +164,78 @@  discard block
 block discarded – undo
164 164
         'USD' => '&#36;',
165 165
         'VND' => '&#8363;',
166 166
         'ZAR' => '&#82;',
167
-    ) );
167
+    ));
168 168
 
169
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
169
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
170 170
 
171
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
171
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
172 172
 }
173 173
 
174 174
 function wpinv_currency_position() {
175
-    $position = wpinv_get_option( 'currency_position', 'left' );
175
+    $position = wpinv_get_option('currency_position', 'left');
176 176
     
177
-    return apply_filters( 'wpinv_currency_position', $position );
177
+    return apply_filters('wpinv_currency_position', $position);
178 178
 }
179 179
 
180 180
 function wpinv_thousands_seperator() {
181
-    $thousand_sep = wpinv_get_option( 'thousands_seperator', ',' );
181
+    $thousand_sep = wpinv_get_option('thousands_seperator', ',');
182 182
     
183
-    return apply_filters( 'wpinv_thousands_seperator', $thousand_sep );
183
+    return apply_filters('wpinv_thousands_seperator', $thousand_sep);
184 184
 }
185 185
 
186 186
 function wpinv_decimal_seperator() {
187
-    $decimal_sep = wpinv_get_option( 'decimal_seperator', '.' );
187
+    $decimal_sep = wpinv_get_option('decimal_seperator', '.');
188 188
     
189
-    return apply_filters( 'wpinv_decimal_seperator', $decimal_sep );
189
+    return apply_filters('wpinv_decimal_seperator', $decimal_sep);
190 190
 }
191 191
 
192 192
 function wpinv_decimals() {
193
-    $decimals = wpinv_get_option( 'decimals', 2 );
193
+    $decimals = wpinv_get_option('decimals', 2);
194 194
     
195
-    return apply_filters( 'wpinv_decimals', $decimals );
195
+    return apply_filters('wpinv_decimals', $decimals);
196 196
 }
197 197
 
198 198
 function wpinv_get_currencies() {
199 199
     $currencies = array(
200
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
201
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
202
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
203
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
204
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
205
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
206
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
207
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
208
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
209
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
210
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
211
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
212
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
213
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
214
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
215
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
216
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
217
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
218
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
219
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
220
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
221
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
222
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
223
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
224
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
225
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
226
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
227
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
228
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
229
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
200
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
201
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
202
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
203
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
204
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
205
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
206
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
207
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
208
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
209
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
210
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
211
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
212
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
213
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
214
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
215
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
216
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
217
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
218
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
219
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
220
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
221
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
222
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
223
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
224
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
225
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
226
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
227
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
228
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
229
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
230 230
     );
231 231
     
232
-    asort( $currencies );
232
+    asort($currencies);
233 233
 
234
-    return apply_filters( 'wpinv_currencies', $currencies );
234
+    return apply_filters('wpinv_currencies', $currencies);
235 235
 }
236 236
 
237
-function wpinv_price( $amount = '', $currency = '' ) {
238
-    if( empty( $currency ) ) {
237
+function wpinv_price($amount = '', $currency = '') {
238
+    if (empty($currency)) {
239 239
         $currency = wpinv_get_currency();
240 240
     }
241 241
 
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 
244 244
     $negative = $amount < 0;
245 245
 
246
-    if ( $negative ) {
247
-        $amount = substr( $amount, 1 );
246
+    if ($negative) {
247
+        $amount = substr($amount, 1);
248 248
     }
249 249
 
250
-    $symbol = wpinv_currency_symbol( $currency );
250
+    $symbol = wpinv_currency_symbol($currency);
251 251
 
252
-    if ( $position == 'left' || $position == 'left_space' ) {
253
-        switch ( $currency ) {
252
+    if ($position == 'left' || $position == 'left_space') {
253
+        switch ($currency) {
254 254
             case "GBP" :
255 255
             case "BRL" :
256 256
             case "EUR" :
@@ -262,15 +262,15 @@  discard block
 block discarded – undo
262 262
             case "NZD" :
263 263
             case "SGD" :
264 264
             case "JPY" :
265
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
265
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
266 266
                 break;
267 267
             default :
268 268
                 //$price = $currency . ' ' . $amount;
269
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
269
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
270 270
                 break;
271 271
         }
272 272
     } else {
273
-        switch ( $currency ) {
273
+        switch ($currency) {
274 274
             case "GBP" :
275 275
             case "BRL" :
276 276
             case "EUR" :
@@ -281,82 +281,82 @@  discard block
 block discarded – undo
281 281
             case "MXN" :
282 282
             case "SGD" :
283 283
             case "JPY" :
284
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
284
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
285 285
                 break;
286 286
             default :
287 287
                 //$price = $amount . ' ' . $currency;
288
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
288
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
289 289
                 break;
290 290
         }
291 291
     }
292 292
     
293
-    if ( $negative ) {
293
+    if ($negative) {
294 294
         $price = '-' . $price;
295 295
     }
296 296
     
297
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
297
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
298 298
 
299 299
     return $price;
300 300
 }
301 301
 
302
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
302
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
303 303
     $thousands_sep = wpinv_thousands_seperator();
304 304
     $decimal_sep   = wpinv_decimal_seperator();
305 305
 
306
-    if ( $decimals === NULL ) {
306
+    if ($decimals === NULL) {
307 307
         $decimals = wpinv_decimals();
308 308
     }
309 309
 
310
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
311
-        $whole = substr( $amount, 0, $sep_found );
312
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
310
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
311
+        $whole = substr($amount, 0, $sep_found);
312
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
313 313
         $amount = $whole . '.' . $part;
314 314
     }
315 315
 
316
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
317
-        $amount = str_replace( ',', '', $amount );
316
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
317
+        $amount = str_replace(',', '', $amount);
318 318
     }
319 319
 
320
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
321
-        $amount = str_replace( ' ', '', $amount );
320
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
321
+        $amount = str_replace(' ', '', $amount);
322 322
     }
323 323
 
324
-    if ( empty( $amount ) ) {
324
+    if (empty($amount)) {
325 325
         $amount = 0;
326 326
     }
327 327
     
328
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
329
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
328
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
329
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
330 330
     
331
-    if ( $calculate ) {
332
-        if ( $thousands_sep === "," ) {
333
-            $formatted = str_replace( ",", "", $formatted );
331
+    if ($calculate) {
332
+        if ($thousands_sep === ",") {
333
+            $formatted = str_replace(",", "", $formatted);
334 334
         }
335 335
         
336
-        if ( $decimal_sep === "," ) {
337
-            $formatted = str_replace( ",", ".", $formatted );
336
+        if ($decimal_sep === ",") {
337
+            $formatted = str_replace(",", ".", $formatted);
338 338
         }
339 339
     }
340 340
 
341
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
341
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
342 342
 }
343 343
 
344
-function wpinv_sanitize_key( $key ) {
344
+function wpinv_sanitize_key($key) {
345 345
     $raw_key = $key;
346
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
346
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
347 347
 
348
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
348
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
349 349
 }
350 350
 
351
-function wpinv_get_file_extension( $str ) {
352
-    $parts = explode( '.', $str );
353
-    return end( $parts );
351
+function wpinv_get_file_extension($str) {
352
+    $parts = explode('.', $str);
353
+    return end($parts);
354 354
 }
355 355
 
356
-function wpinv_string_is_image_url( $str ) {
357
-    $ext = wpinv_get_file_extension( $str );
356
+function wpinv_string_is_image_url($str) {
357
+    $ext = wpinv_get_file_extension($str);
358 358
 
359
-    switch ( strtolower( $ext ) ) {
359
+    switch (strtolower($ext)) {
360 360
         case 'jpeg';
361 361
         case 'jpg';
362 362
             $return = true;
@@ -372,32 +372,32 @@  discard block
 block discarded – undo
372 372
             break;
373 373
     }
374 374
 
375
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
375
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
376 376
 }
377 377
 
378
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
379
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
378
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
379
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
380 380
     
381
-    if ( true === $should_log ) {
381
+    if (true === $should_log) {
382 382
         $label = '';
383
-        if ( $file && $file !== '' ) {
384
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
383
+        if ($file && $file !== '') {
384
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
385 385
         }
386 386
         
387
-        if ( $title && $title !== '' ) {
387
+        if ($title && $title !== '') {
388 388
             $label = $label !== '' ? $label . ' ' : '';
389 389
             $label .= $title . ' ';
390 390
         }
391 391
         
392
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
392
+        $label = $label !== '' ? trim($label) . ' : ' : '';
393 393
         
394
-        if ( is_array( $log ) || is_object( $log ) ) {
395
-            error_log( $label . print_r( $log, true ) );
394
+        if (is_array($log) || is_object($log)) {
395
+            error_log($label . print_r($log, true));
396 396
         } else {
397
-            error_log( $label . $log );
397
+            error_log($label . $log);
398 398
         }
399 399
         
400
-        if ( $exit ) {
400
+        if ($exit) {
401 401
             exit;
402 402
         }
403 403
     }
@@ -405,65 +405,65 @@  discard block
 block discarded – undo
405 405
 
406 406
 function wpinv_is_ajax_disabled() {
407 407
     $retval = false;
408
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
408
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
409 409
 }
410 410
 
411
-function wpinv_get_current_page_url( $nocache = false ) {
411
+function wpinv_get_current_page_url($nocache = false) {
412 412
     global $wp;
413 413
 
414
-    if ( get_option( 'permalink_structure' ) ) {
415
-        $base = trailingslashit( home_url( $wp->request ) );
414
+    if (get_option('permalink_structure')) {
415
+        $base = trailingslashit(home_url($wp->request));
416 416
     } else {
417
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
418
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
417
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
418
+        $base = remove_query_arg(array('post_type', 'name'), $base);
419 419
     }
420 420
 
421 421
     $scheme = is_ssl() ? 'https' : 'http';
422
-    $uri    = set_url_scheme( $base, $scheme );
422
+    $uri    = set_url_scheme($base, $scheme);
423 423
 
424
-    if ( is_front_page() ) {
425
-        $uri = home_url( '/' );
426
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
424
+    if (is_front_page()) {
425
+        $uri = home_url('/');
426
+    } elseif (wpinv_is_checkout(array(), false)) {
427 427
         $uri = wpinv_get_checkout_uri();
428 428
     }
429 429
 
430
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
430
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
431 431
 
432
-    if ( $nocache ) {
433
-        $uri = wpinv_add_cache_busting( $uri );
432
+    if ($nocache) {
433
+        $uri = wpinv_add_cache_busting($uri);
434 434
     }
435 435
 
436 436
     return $uri;
437 437
 }
438 438
 
439 439
 function wpinv_get_php_arg_separator_output() {
440
-	return ini_get( 'arg_separator.output' );
440
+	return ini_get('arg_separator.output');
441 441
 }
442 442
 
443
-function wpinv_rgb_from_hex( $color ) {
444
-    $color = str_replace( '#', '', $color );
443
+function wpinv_rgb_from_hex($color) {
444
+    $color = str_replace('#', '', $color);
445 445
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
446
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
446
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
447 447
 
448 448
     $rgb      = array();
449
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
450
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
451
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
449
+    $rgb['R'] = hexdec($color{0} . $color{1} );
450
+    $rgb['G'] = hexdec($color{2} . $color{3} );
451
+    $rgb['B'] = hexdec($color{4} . $color{5} );
452 452
 
453 453
     return $rgb;
454 454
 }
455 455
 
456
-function wpinv_hex_darker( $color, $factor = 30 ) {
457
-    $base  = wpinv_rgb_from_hex( $color );
456
+function wpinv_hex_darker($color, $factor = 30) {
457
+    $base  = wpinv_rgb_from_hex($color);
458 458
     $color = '#';
459 459
 
460
-    foreach ( $base as $k => $v ) {
460
+    foreach ($base as $k => $v) {
461 461
         $amount      = $v / 100;
462
-        $amount      = round( $amount * $factor );
462
+        $amount      = round($amount * $factor);
463 463
         $new_decimal = $v - $amount;
464 464
 
465
-        $new_hex_component = dechex( $new_decimal );
466
-        if ( strlen( $new_hex_component ) < 2 ) {
465
+        $new_hex_component = dechex($new_decimal);
466
+        if (strlen($new_hex_component) < 2) {
467 467
             $new_hex_component = "0" . $new_hex_component;
468 468
         }
469 469
         $color .= $new_hex_component;
@@ -472,18 +472,18 @@  discard block
 block discarded – undo
472 472
     return $color;
473 473
 }
474 474
 
475
-function wpinv_hex_lighter( $color, $factor = 30 ) {
476
-    $base  = wpinv_rgb_from_hex( $color );
475
+function wpinv_hex_lighter($color, $factor = 30) {
476
+    $base  = wpinv_rgb_from_hex($color);
477 477
     $color = '#';
478 478
 
479
-    foreach ( $base as $k => $v ) {
479
+    foreach ($base as $k => $v) {
480 480
         $amount      = 255 - $v;
481 481
         $amount      = $amount / 100;
482
-        $amount      = round( $amount * $factor );
482
+        $amount      = round($amount * $factor);
483 483
         $new_decimal = $v + $amount;
484 484
 
485
-        $new_hex_component = dechex( $new_decimal );
486
-        if ( strlen( $new_hex_component ) < 2 ) {
485
+        $new_hex_component = dechex($new_decimal);
486
+        if (strlen($new_hex_component) < 2) {
487 487
             $new_hex_component = "0" . $new_hex_component;
488 488
         }
489 489
         $color .= $new_hex_component;
@@ -492,22 +492,22 @@  discard block
 block discarded – undo
492 492
     return $color;
493 493
 }
494 494
 
495
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
496
-    $hex = str_replace( '#', '', $color );
495
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
496
+    $hex = str_replace('#', '', $color);
497 497
 
498
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
499
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
500
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
498
+    $c_r = hexdec(substr($hex, 0, 2));
499
+    $c_g = hexdec(substr($hex, 2, 2));
500
+    $c_b = hexdec(substr($hex, 4, 2));
501 501
 
502
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
502
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
503 503
 
504 504
     return $brightness > 155 ? $dark : $light;
505 505
 }
506 506
 
507
-function wpinv_format_hex( $hex ) {
508
-    $hex = trim( str_replace( '#', '', $hex ) );
507
+function wpinv_format_hex($hex) {
508
+    $hex = trim(str_replace('#', '', $hex));
509 509
 
510
-    if ( strlen( $hex ) == 3 ) {
510
+    if (strlen($hex) == 3) {
511 511
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
512 512
     }
513 513
 
@@ -527,12 +527,12 @@  discard block
 block discarded – undo
527 527
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
528 528
  * @return string
529 529
  */
530
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
531
-    if ( function_exists( 'mb_strimwidth' ) ) {
532
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
530
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
531
+    if (function_exists('mb_strimwidth')) {
532
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
533 533
     }
534 534
     
535
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
535
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
536 536
 }
537 537
 
538 538
 /**
@@ -544,28 +544,28 @@  discard block
 block discarded – undo
544 544
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
545 545
  * @return int Returns the number of characters in string.
546 546
  */
547
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
548
-    if ( function_exists( 'mb_strlen' ) ) {
549
-        return mb_strlen( $str, $encoding );
547
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
548
+    if (function_exists('mb_strlen')) {
549
+        return mb_strlen($str, $encoding);
550 550
     }
551 551
         
552
-    return strlen( $str );
552
+    return strlen($str);
553 553
 }
554 554
 
555
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
556
-    if ( function_exists( 'mb_strtolower' ) ) {
557
-        return mb_strtolower( $str, $encoding );
555
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
556
+    if (function_exists('mb_strtolower')) {
557
+        return mb_strtolower($str, $encoding);
558 558
     }
559 559
     
560
-    return strtolower( $str );
560
+    return strtolower($str);
561 561
 }
562 562
 
563
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
564
-    if ( function_exists( 'mb_strtoupper' ) ) {
565
-        return mb_strtoupper( $str, $encoding );
563
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
564
+    if (function_exists('mb_strtoupper')) {
565
+        return mb_strtoupper($str, $encoding);
566 566
     }
567 567
     
568
-    return strtoupper( $str );
568
+    return strtoupper($str);
569 569
 }
570 570
 
571 571
 /**
@@ -579,12 +579,12 @@  discard block
 block discarded – undo
579 579
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
580 580
  * @return int Returns the position of the first occurrence of search in the string.
581 581
  */
582
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
583
-    if ( function_exists( 'mb_strpos' ) ) {
584
-        return mb_strpos( $str, $find, $offset, $encoding );
582
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
583
+    if (function_exists('mb_strpos')) {
584
+        return mb_strpos($str, $find, $offset, $encoding);
585 585
     }
586 586
         
587
-    return strpos( $str, $find, $offset );
587
+    return strpos($str, $find, $offset);
588 588
 }
589 589
 
590 590
 /**
@@ -598,12 +598,12 @@  discard block
 block discarded – undo
598 598
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
599 599
  * @return int Returns the position of the last occurrence of search.
600 600
  */
601
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
602
-    if ( function_exists( 'mb_strrpos' ) ) {
603
-        return mb_strrpos( $str, $find, $offset, $encoding );
601
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
602
+    if (function_exists('mb_strrpos')) {
603
+        return mb_strrpos($str, $find, $offset, $encoding);
604 604
     }
605 605
         
606
-    return strrpos( $str, $find, $offset );
606
+    return strrpos($str, $find, $offset);
607 607
 }
608 608
 
609 609
 /**
@@ -618,16 +618,16 @@  discard block
 block discarded – undo
618 618
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
619 619
  * @return string
620 620
  */
621
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
622
-    if ( function_exists( 'mb_substr' ) ) {
623
-        if ( $length === null ) {
624
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
621
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
622
+    if (function_exists('mb_substr')) {
623
+        if ($length === null) {
624
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
625 625
         } else {
626
-            return mb_substr( $str, $start, $length, $encoding );
626
+            return mb_substr($str, $start, $length, $encoding);
627 627
         }
628 628
     }
629 629
         
630
-    return substr( $str, $start, $length );
630
+    return substr($str, $start, $length);
631 631
 }
632 632
 
633 633
 /**
@@ -639,48 +639,48 @@  discard block
 block discarded – undo
639 639
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
640 640
  * @return string The width of string.
641 641
  */
642
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
643
-    if ( function_exists( 'mb_strwidth' ) ) {
644
-        return mb_strwidth( $str, $encoding );
642
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
643
+    if (function_exists('mb_strwidth')) {
644
+        return mb_strwidth($str, $encoding);
645 645
     }
646 646
     
647
-    return wpinv_utf8_strlen( $str, $encoding );
647
+    return wpinv_utf8_strlen($str, $encoding);
648 648
 }
649 649
 
650
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
651
-    if ( function_exists( 'mb_strlen' ) ) {
652
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
650
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
651
+    if (function_exists('mb_strlen')) {
652
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
653 653
         $str_end = "";
654 654
         
655
-        if ( $lower_str_end ) {
656
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
655
+        if ($lower_str_end) {
656
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
657 657
         } else {
658
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
658
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
659 659
         }
660 660
 
661 661
         return $first_letter . $str_end;
662 662
     }
663 663
     
664
-    return ucfirst( $str );
664
+    return ucfirst($str);
665 665
 }
666 666
 
667
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
668
-    if ( function_exists( 'mb_convert_case' ) ) {
669
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
667
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
668
+    if (function_exists('mb_convert_case')) {
669
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
670 670
     }
671 671
     
672
-    return ucwords( $str );
672
+    return ucwords($str);
673 673
 }
674 674
 
675
-function wpinv_period_in_days( $period, $unit ) {
676
-    $period = absint( $period );
675
+function wpinv_period_in_days($period, $unit) {
676
+    $period = absint($period);
677 677
     
678
-    if ( $period > 0 ) {
679
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
678
+    if ($period > 0) {
679
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
680 680
             $period = $period * 7;
681
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
681
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
682 682
             $period = $period * 30;
683
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
683
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
684 684
             $period = $period * 365;
685 685
         }
686 686
     }
Please login to merge, or discard this patch.
includes/gateways/paypal.php 1 patch
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  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
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8
-function wpinv_process_paypal_payment( $purchase_data ) {
9
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
10
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
8
+function wpinv_process_paypal_payment($purchase_data) {
9
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
10
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
11 11
     }
12 12
 
13 13
     // Collect payment data
@@ -21,34 +21,34 @@  discard block
 block discarded – undo
21 21
         'user_info'     => $purchase_data['user_info'],
22 22
         'cart_details'  => $purchase_data['cart_details'],
23 23
         'gateway'       => 'paypal',
24
-        'status'        => !empty( $purchase_data['buy_now'] ) ? 'private' : 'pending'
24
+        'status'        => !empty($purchase_data['buy_now']) ? 'private' : 'pending'
25 25
     );
26 26
 
27 27
     // Record the pending payment
28
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
28
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
29 29
 
30 30
     // Check payment
31
-    if ( ! $invoice ) {
31
+    if (!$invoice) {
32 32
         // Record the error
33
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment );
33
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment);
34 34
         // Problems? send back
35
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
35
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
36 36
     } else {
37 37
         // Only send to PayPal if the pending payment is created successfully
38
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
38
+        $listener_url = wpinv_get_ipn_url('paypal');
39 39
 
40 40
         // Get the success url
41
-        $return_url = add_query_arg( array(
41
+        $return_url = add_query_arg(array(
42 42
                 'payment-confirm' => 'paypal',
43 43
                 'invoice-id' => $invoice->ID
44
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
44
+            ), get_permalink(wpinv_get_option('success_page', false)));
45 45
 
46 46
         // Get the PayPal redirect uri
47
-        $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?';
47
+        $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?';
48 48
 
49 49
         // Setup PayPal arguments
50 50
         $paypal_args = array(
51
-            'business'      => wpinv_get_option( 'paypal_email', false ),
51
+            'business'      => wpinv_get_option('paypal_email', false),
52 52
             'email'         => $invoice->get_email(),
53 53
             'first_name'    => $invoice->get_first_name(),
54 54
             'last_name'     => $invoice->get_last_name(),
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
             'shipping'      => '0',
58 58
             'no_note'       => '1',
59 59
             'currency_code' => wpinv_get_currency(),
60
-            'charset'       => get_bloginfo( 'charset' ),
60
+            'charset'       => get_bloginfo('charset'),
61 61
             'custom'        => $invoice->ID,
62 62
             'rm'            => '2',
63 63
             'return'        => $return_url,
64
-            'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ),
64
+            'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID),
65 65
             'notify_url'    => $listener_url,
66
-            'cbt'           => get_bloginfo( 'name' ),
66
+            'cbt'           => get_bloginfo('name'),
67 67
             'bn'            => 'WPInvoicing_SP',
68 68
 	        'lc'            => 'US' // this will force paypal site to english
69 69
         );
@@ -79,57 +79,57 @@  discard block
 block discarded – undo
79 79
             'upload' => '1'
80 80
         );
81 81
 
82
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
82
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
83 83
 
84 84
         // Add cart items
85 85
         $i = 1;
86
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
87
-            foreach ( $purchase_data['cart_details'] as $item ) {
86
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
87
+            foreach ($purchase_data['cart_details'] as $item) {
88 88
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
89
-                $item_amount = round( $item['subtotal'] / $item['quantity'], 2 );
89
+                $item_amount = round($item['subtotal'] / $item['quantity'], 2);
90 90
 
91
-                if ( $item_amount <= 0 ) {
91
+                if ($item_amount <= 0) {
92 92
                     $item_amount = 0;
93 93
                 }
94 94
 
95
-                $paypal_args['item_number_' . $i ]      = $item['id'];
96
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
97
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
98
-                $paypal_args['amount_' . $i ]           = $item_amount;
99
-                $paypal_args['discount_amount_' . $i ]  = $item['discount'];
95
+                $paypal_args['item_number_' . $i]      = $item['id'];
96
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
97
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
98
+                $paypal_args['amount_' . $i]           = $item_amount;
99
+                $paypal_args['discount_amount_' . $i]  = $item['discount'];
100 100
 
101 101
                 $i++;
102 102
             }
103 103
         }
104 104
 
105 105
         // Add taxes to the cart
106
-        if ( wpinv_use_taxes() ) {
107
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax() );
106
+        if (wpinv_use_taxes()) {
107
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax());
108 108
         }
109 109
 
110
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
110
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
111 111
 
112 112
         // Build query
113
-        $paypal_redirect .= http_build_query( $paypal_args );
113
+        $paypal_redirect .= http_build_query($paypal_args);
114 114
 
115 115
         // Fix for some sites that encode the entities
116
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
116
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
117 117
 
118 118
         // Get rid of cart contents
119 119
         wpinv_empty_cart();
120 120
         
121 121
         // Redirect to PayPal
122
-        wp_redirect( $paypal_redirect );
122
+        wp_redirect($paypal_redirect);
123 123
         exit;
124 124
     }
125 125
 }
126
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
126
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
127 127
 
128
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
129
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
130
-        $item   = new WPInv_Item( $item_id );
128
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
129
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
130
+        $item = new WPInv_Item($item_id);
131 131
         
132
-        if ( empty( $item ) ) {
132
+        if (empty($item)) {
133 133
             return $paypal_args;
134 134
         }
135 135
 
@@ -137,24 +137,24 @@  discard block
 block discarded – undo
137 137
         $interval           = $item->get_recurring_interval();
138 138
         $bill_times         = (int)$item->get_recurring_limit();
139 139
         
140
-        $initial_amount     = wpinv_format_amount( $invoice->get_total() );
141
-        $recurring_amount   = wpinv_format_amount( $invoice->get_recurring_details( 'total' ) );
140
+        $initial_amount     = wpinv_format_amount($invoice->get_total());
141
+        $recurring_amount   = wpinv_format_amount($invoice->get_recurring_details('total'));
142 142
         
143 143
         $paypal_args['cmd'] = '_xclick-subscriptions';
144 144
         $paypal_args['sra'] = '1';
145 145
         $paypal_args['src'] = '1';
146 146
         
147 147
         // Set item description
148
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) );
148
+        $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8'));
149 149
         
150
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
150
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
151 151
             $paypal_args['a1']  = $initial_amount;
152 152
             $paypal_args['p1']  = $item->get_trial_interval();
153 153
             $paypal_args['t1']  = $item->get_trial_period();
154 154
             
155 155
             // Set the recurring amount
156 156
             $paypal_args['a3']  = $recurring_amount;
157
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
157
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
158 158
             $paypal_args['a1']  = $initial_amount;
159 159
             $paypal_args['p1']  = $interval;
160 160
             $paypal_args['t1']  = $period;
@@ -162,63 +162,63 @@  discard block
 block discarded – undo
162 162
             // Set the recurring amount
163 163
             $paypal_args['a3']  = $recurring_amount;
164 164
             
165
-            if ( $bill_times > 1 ) {
165
+            if ($bill_times > 1) {
166 166
                 $bill_times--;
167 167
             }
168 168
         } else {
169
-            $paypal_args['a3']  = $initial_amount;
169
+            $paypal_args['a3'] = $initial_amount;
170 170
         }
171 171
         
172 172
         $paypal_args['p3']  = $interval;
173 173
         $paypal_args['t3']  = $period;
174 174
         
175
-        if ( $bill_times > 1 ) {
175
+        if ($bill_times > 1) {
176 176
             // Make sure it's not over the max of 52
177
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
177
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
178 178
         }
179 179
                 
180 180
         // Remove cart items
181 181
         $i = 1;
182
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
183
-            foreach ( $purchase_data['cart_details'] as $item ) {                
184
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
185
-                    unset( $paypal_args['item_number_' . $i] );
182
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
183
+            foreach ($purchase_data['cart_details'] as $item) {                
184
+                if (isset($paypal_args['item_number_' . $i])) {
185
+                    unset($paypal_args['item_number_' . $i]);
186 186
                 }
187
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
188
-                    unset( $paypal_args['item_name_' . $i] );
187
+                if (isset($paypal_args['item_name_' . $i])) {
188
+                    unset($paypal_args['item_name_' . $i]);
189 189
                 }
190
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
191
-                    unset( $paypal_args['quantity_' . $i] );
190
+                if (isset($paypal_args['quantity_' . $i])) {
191
+                    unset($paypal_args['quantity_' . $i]);
192 192
                 }
193
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
194
-                    unset( $paypal_args['amount_' . $i] );
193
+                if (isset($paypal_args['amount_' . $i])) {
194
+                    unset($paypal_args['amount_' . $i]);
195 195
                 }
196
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
197
-                    unset( $paypal_args['discount_amount_' . $i] );
196
+                if (isset($paypal_args['discount_amount_' . $i])) {
197
+                    unset($paypal_args['discount_amount_' . $i]);
198 198
                 }
199 199
 
200 200
                 $i++;
201 201
             }
202 202
         }
203 203
         
204
-        if ( isset( $paypal_args['tax_cart'] ) ) {
205
-            unset( $paypal_args['tax_cart'] );
204
+        if (isset($paypal_args['tax_cart'])) {
205
+            unset($paypal_args['tax_cart']);
206 206
         }
207 207
                 
208
-        if ( isset( $paypal_args['upload'] ) ) {
209
-            unset( $paypal_args['upload'] );
208
+        if (isset($paypal_args['upload'])) {
209
+            unset($paypal_args['upload']);
210 210
         }
211 211
         
212
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
212
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
213 213
     }
214 214
     
215 215
     return $paypal_args;
216 216
 }
217
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
217
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
218 218
 
219 219
 function wpinv_process_paypal_ipn() {
220 220
 	// Check the request method is POST
221
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
221
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
222 222
 		return;
223 223
 	}
224 224
 
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 	$post_data = '';
227 227
 
228 228
 	// Fallback just in case post_max_size is lower than needed
229
-	if ( ini_get( 'allow_url_fopen' ) ) {
230
-		$post_data = file_get_contents( 'php://input' );
229
+	if (ini_get('allow_url_fopen')) {
230
+		$post_data = file_get_contents('php://input');
231 231
 	} else {
232 232
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
233
-		ini_set( 'post_max_size', '12M' );
233
+		ini_set('post_max_size', '12M');
234 234
 	}
235 235
 	// Start the encoded data collection with notification command
236 236
 	$encoded_data = 'cmd=_notify-validate';
@@ -239,43 +239,43 @@  discard block
 block discarded – undo
239 239
 	$arg_separator = wpinv_get_php_arg_separator_output();
240 240
 
241 241
 	// Verify there is a post_data
242
-	if ( $post_data || strlen( $post_data ) > 0 ) {
242
+	if ($post_data || strlen($post_data) > 0) {
243 243
 		// Append the data
244
-		$encoded_data .= $arg_separator.$post_data;
244
+		$encoded_data .= $arg_separator . $post_data;
245 245
 	} else {
246 246
 		// Check if POST is empty
247
-		if ( empty( $_POST ) ) {
247
+		if (empty($_POST)) {
248 248
 			// Nothing to do
249 249
 			return;
250 250
 		} else {
251 251
 			// Loop through each POST
252
-			foreach ( $_POST as $key => $value ) {
252
+			foreach ($_POST as $key => $value) {
253 253
 				// Encode the value and append the data
254
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
254
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
255 255
 			}
256 256
 		}
257 257
 	}
258 258
 
259 259
 	// Convert collected post data to an array
260
-	parse_str( $encoded_data, $encoded_data_array );
260
+	parse_str($encoded_data, $encoded_data_array);
261 261
 
262
-	foreach ( $encoded_data_array as $key => $value ) {
263
-		if ( false !== strpos( $key, 'amp;' ) ) {
264
-			$new_key = str_replace( '&amp;', '&', $key );
265
-			$new_key = str_replace( 'amp;', '&' , $new_key );
262
+	foreach ($encoded_data_array as $key => $value) {
263
+		if (false !== strpos($key, 'amp;')) {
264
+			$new_key = str_replace('&amp;', '&', $key);
265
+			$new_key = str_replace('amp;', '&', $new_key);
266 266
 
267
-			unset( $encoded_data_array[ $key ] );
268
-			$encoded_data_array[ $new_key ] = $value;
267
+			unset($encoded_data_array[$key]);
268
+			$encoded_data_array[$new_key] = $value;
269 269
 		}
270 270
 	}
271 271
 
272 272
 	// Get the PayPal redirect uri
273
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
273
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
274 274
 
275
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
275
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
276 276
 		// Validate the IPN
277 277
 
278
-		$remote_post_vars      = array(
278
+		$remote_post_vars = array(
279 279
 			'method'           => 'POST',
280 280
 			'timeout'          => 45,
281 281
 			'redirection'      => 5,
@@ -293,21 +293,21 @@  discard block
 block discarded – undo
293 293
 		);
294 294
 
295 295
 		// Get response
296
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
296
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
297 297
 
298
-		if ( is_wp_error( $api_response ) ) {
299
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
298
+		if (is_wp_error($api_response)) {
299
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
300 300
 			return; // Something went wrong
301 301
 		}
302 302
 
303
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
304
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
303
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
304
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
305 305
 			return; // Response not okay
306 306
 		}
307 307
 	}
308 308
 
309 309
 	// Check if $post_data_array has been populated
310
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
310
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
311 311
 		return;
312 312
 
313 313
 	$defaults = array(
@@ -315,215 +315,215 @@  discard block
 block discarded – undo
315 315
 		'payment_status' => ''
316 316
 	);
317 317
 
318
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
318
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
319 319
 
320
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
320
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
321 321
     
322
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
322
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
323 323
 
324
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
324
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
325 325
 		// Allow PayPal IPN types to be processed separately
326
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
326
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
327 327
 	} else {
328 328
 		// Fallback to web accept just in case the txn_type isn't present
329
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
329
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
330 330
 	}
331 331
 	exit;
332 332
 }
333
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
333
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
334 334
 
335
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
336
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
335
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
336
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
337 337
 		return;
338 338
 	}
339 339
 
340
-	if( empty( $invoice_id ) ) {
340
+	if (empty($invoice_id)) {
341 341
 		return;
342 342
 	}
343 343
 
344 344
 	// Collect payment details
345
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
345
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
346 346
 	$paypal_amount  = $data['mc_gross'];
347
-	$payment_status = strtolower( $data['payment_status'] );
348
-	$currency_code  = strtolower( $data['mc_currency'] );
349
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
350
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
347
+	$payment_status = strtolower($data['payment_status']);
348
+	$currency_code  = strtolower($data['mc_currency']);
349
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
350
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
351 351
 
352
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
352
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
353 353
 		return; // this isn't a PayPal standard IPN
354 354
 	}
355 355
 
356 356
 	// Verify payment recipient
357
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
358
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
359
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
360
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
357
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
358
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
359
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
360
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'));
361 361
 		return;
362 362
 	}
363 363
 
364 364
 	// Verify payment currency
365
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
366
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
367
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
368
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
365
+	if ($currency_code != strtolower($payment_meta['currency'])) {
366
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
367
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
368
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'));
369 369
 		return;
370 370
 	}
371 371
 
372
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
372
+	if (!wpinv_get_payment_user_email($invoice_id)) {
373 373
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
374 374
 		// No email associated with purchase, so store from PayPal
375
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
375
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
376 376
 
377 377
 		// Setup and store the customer's details
378 378
 		$user_info = array(
379 379
 			'user_id'    => '-1',
380
-			'email'      => sanitize_text_field( $data['payer_email'] ),
381
-			'first_name' => sanitize_text_field( $data['first_name'] ),
382
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
380
+			'email'      => sanitize_text_field($data['payer_email']),
381
+			'first_name' => sanitize_text_field($data['first_name']),
382
+			'last_name'  => sanitize_text_field($data['last_name']),
383 383
 			'discount'   => '',
384 384
 		);
385
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
386
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
387
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
388
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
389
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
385
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
386
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
387
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
388
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
389
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
390 390
 
391 391
 		$payment_meta['user_info'] = $user_info;
392
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
392
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
393 393
 	}
394 394
 
395
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
395
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
396 396
 		// Process a refund
397
-		wpinv_process_paypal_refund( $data, $invoice_id );
397
+		wpinv_process_paypal_refund($data, $invoice_id);
398 398
 	} else {
399
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
399
+		if (get_post_status($invoice_id) == 'publish') {
400 400
 			return; // Only paid payments once
401 401
 		}
402 402
 
403 403
 		// Retrieve the total purchase amount (before PayPal)
404
-		$payment_amount = wpinv_payment_total( $invoice_id );
404
+		$payment_amount = wpinv_payment_total($invoice_id);
405 405
 
406
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
406
+		if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) {
407 407
 			// The prices don't match
408
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
409
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
410
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
408
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
409
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
410
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'));
411 411
 			return;
412 412
 		}
413
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
413
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
414 414
 			// Purchase keys don't match
415
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
416
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
417
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
415
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
416
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
417
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'));
418 418
 			return;
419 419
 		}
420 420
 
421
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
422
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
423
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
424
-			wpinv_update_payment_status( $invoice_id, 'publish' );
425
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
421
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
422
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']));
423
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
424
+			wpinv_update_payment_status($invoice_id, 'publish');
425
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
426 426
 			// Look for possible pending reasons, such as an echeck
427 427
 			$note = '';
428 428
 
429
-			switch( strtolower( $data['pending_reason'] ) ) {
429
+			switch (strtolower($data['pending_reason'])) {
430 430
 				case 'echeck' :
431
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
431
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
432 432
 					break;
433 433
 				
434 434
                 case 'address' :
435
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
435
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
436 436
 					break;
437 437
 				
438 438
                 case 'intl' :
439
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
439
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
440 440
 					break;
441 441
 				
442 442
                 case 'multi-currency' :
443
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
443
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
444 444
 					break;
445 445
 				
446 446
                 case 'paymentreview' :
447 447
                 case 'regulatory_review' :
448
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
448
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
449 449
 					break;
450 450
 				
451 451
                 case 'unilateral' :
452
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
452
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
453 453
 					break;
454 454
 				
455 455
                 case 'upgrade' :
456
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
456
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
457 457
 					break;
458 458
 				
459 459
                 case 'verify' :
460
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
460
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
461 461
 					break;
462 462
 
463 463
 				case 'other' :
464
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
464
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
465 465
 					break;
466 466
 			}
467 467
 
468
-			if ( ! empty( $note ) ) {
469
-				wpinv_insert_payment_note( $invoice_id, $note );
468
+			if (!empty($note)) {
469
+				wpinv_insert_payment_note($invoice_id, $note);
470 470
 			}
471 471
 		} else {
472
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
472
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status));
473 473
 		}
474 474
 	}
475 475
 }
476
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
476
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
477 477
 
478 478
 // Process PayPal subscription sign ups
479
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
479
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
480 480
 
481 481
 // Process PayPal subscription payments
482
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
482
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
483 483
 
484 484
 // Process PayPal subscription cancellations
485
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
485
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
486 486
 
487 487
 // Process PayPal subscription end of term notices
488
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
488
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
489 489
 
490 490
 // Process PayPal payment failed
491
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
491
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
492 492
 
493 493
 
494 494
 /**
495 495
  * Process the subscription started IPN.
496 496
  */
497
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
498
-    $parent_invoice_id = absint( $ipn_data['custom'] );
499
-    if( empty( $parent_invoice_id ) ) {
497
+function wpinv_process_paypal_subscr_signup($ipn_data) {
498
+    $parent_invoice_id = absint($ipn_data['custom']);
499
+    if (empty($parent_invoice_id)) {
500 500
         return;
501 501
     }
502 502
 
503
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
504
-    if ( empty( $invoice ) ) {
503
+    $invoice = wpinv_get_invoice($parent_invoice_id);
504
+    if (empty($invoice)) {
505 505
         return;
506 506
     }
507 507
 
508
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
509
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) );
510
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] );
508
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
509
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']));
510
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']);
511 511
     }
512 512
     
513
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
513
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
514 514
     sleep(1);
515
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) );
515
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']));
516 516
     
517
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
518
-    if ( false === $subscription ) {
517
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
518
+    if (false === $subscription) {
519 519
         return;
520 520
     }
521 521
 
522
-    $cart_details   = $invoice->cart_details;
522
+    $cart_details = $invoice->cart_details;
523 523
 
524
-    if ( !empty( $cart_details ) ) {
525
-        foreach ( $cart_details as $cart_item ) {
526
-            $item = new WPInv_Item( $cart_item['id'] );
524
+    if (!empty($cart_details)) {
525
+        foreach ($cart_details as $cart_item) {
526
+            $item = new WPInv_Item($cart_item['id']);
527 527
             
528 528
             $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active';
529 529
             
@@ -532,15 +532,15 @@  discard block
 block discarded – undo
532 532
                 'status'            => $status,
533 533
                 'period'            => $item->get_recurring_period(),
534 534
                 'initial_amount'    => $invoice->get_total(),
535
-                'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
535
+                'recurring_amount'  => $invoice->get_recurring_details('total'),
536 536
                 'interval'          => $item->get_recurring_interval(),
537 537
                 'bill_times'        => $item->get_recurring_limit(),
538
-                'expiration'        => $invoice->get_new_expiration( $cart_item['id'] ),
538
+                'expiration'        => $invoice->get_new_expiration($cart_item['id']),
539 539
                 'profile_id'        => $ipn_data['subscr_id'],
540
-                'created'           => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) )
540
+                'created'           => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date']))
541 541
             );
542 542
             
543
-            if ( $item->has_free_trial() ) {
543
+            if ($item->has_free_trial()) {
544 544
                 $args['trial_period']      = $item->get_trial_period();
545 545
                 $args['trial_interval']    = $item->get_trial_interval();
546 546
             } else {
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             }
550 550
             
551 551
 
552
-            $subscription->update_subscription( $args );
552
+            $subscription->update_subscription($args);
553 553
         }
554 554
     }
555 555
 }
@@ -557,39 +557,39 @@  discard block
 block discarded – undo
557 557
 /**
558 558
  * Process the subscription payment received IPN.
559 559
  */
560
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
561
-    $parent_invoice_id = absint( $ipn_data['custom'] );
560
+function wpinv_process_paypal_subscr_payment($ipn_data) {
561
+    $parent_invoice_id = absint($ipn_data['custom']);
562 562
     
563
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
564
-    if ( false === $subscription ) {
563
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
564
+    if (false === $subscription) {
565 565
         return;
566 566
     }
567 567
     
568
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
569
-    $signup_date    = strtotime( $subscription->get_subscription_created() );
570
-    $today          = date_i18n( 'Y-m-d', $signup_date ) == date_i18n( 'Y-m-d', strtotime( $ipn_data['payment_date'] ) );
568
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
569
+    $signup_date    = strtotime($subscription->get_subscription_created());
570
+    $today          = date_i18n('Y-m-d', $signup_date) == date_i18n('Y-m-d', strtotime($ipn_data['payment_date']));
571 571
 
572 572
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
573
-    if ( $today && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
574
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
573
+    if ($today && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
574
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
575 575
         sleep(1);
576 576
         
577 577
         // This is the very first payment
578
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
579
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
578
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
579
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
580 580
         return;
581 581
     }
582 582
     
583
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
583
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
584 584
         return; // Payment already recorded
585 585
     }
586 586
 
587
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
587
+    $currency_code = strtolower($ipn_data['mc_currency']);
588 588
 
589 589
     // verify details
590
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
590
+    if ($currency_code != strtolower(wpinv_get_currency())) {
591 591
         // the currency code is invalid
592
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
592
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
593 593
         return;
594 594
     }
595 595
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
         'transaction_id' => $ipn_data['txn_id']
599 599
     );
600 600
     
601
-    $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args );
601
+    $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args);
602 602
     
603
-    if ( !empty( $invoice ) ) {
603
+    if (!empty($invoice)) {
604 604
         sleep(1);
605
-        wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
605
+        wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
606 606
 
607 607
         $invoice->renew_subscription();
608 608
     }
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 /**
612 612
  * Process the subscription canceled IPN.
613 613
  */
614
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
615
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
614
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
615
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
616 616
 
617
-    if( false === $subscription ) {
617
+    if (false === $subscription) {
618 618
         return;
619 619
     }
620 620
 
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
 /**
625 625
  * Process the subscription expired IPN.
626 626
  */
627
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
628
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
627
+function wpinv_process_paypal_subscr_eot($ipn_data) {
628
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
629 629
 
630
-    if( false === $subscription ) {
630
+    if (false === $subscription) {
631 631
         return;
632 632
     }
633 633
 
@@ -637,45 +637,45 @@  discard block
 block discarded – undo
637 637
 /**
638 638
  * Process the subscription payment failed IPN.
639 639
  */
640
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
641
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
640
+function wpinv_process_paypal_subscr_failed($ipn_data) {
641
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
642 642
 
643
-    if( false === $subscription ) {
643
+    if (false === $subscription) {
644 644
         return;
645 645
     }
646 646
 
647 647
     $subscription->failing_subscription();
648 648
 
649
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
649
+    do_action('wpinv_recurring_payment_failed', $subscription);
650 650
 }
651 651
 
652 652
 /**
653 653
  * Retrieve the subscription this IPN notice is for.
654 654
  */
655
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
656
-    $parent_invoice_id = absint( $ipn_data['custom'] );
655
+function wpinv_get_paypal_subscription($ipn_data = array()) {
656
+    $parent_invoice_id = absint($ipn_data['custom']);
657 657
 
658
-    if( empty( $parent_invoice_id ) ) {
658
+    if (empty($parent_invoice_id)) {
659 659
         return false;
660 660
     }
661 661
 
662
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
663
-    if ( empty( $invoice ) ) {
662
+    $invoice = wpinv_get_invoice($parent_invoice_id);
663
+    if (empty($invoice)) {
664 664
         return false;
665 665
     }
666 666
 
667
-    $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true );
667
+    $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true);
668 668
 
669
-    if ( empty( $subscription ) ) {
670
-        $subs         = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) );
671
-        $subscription = reset( $subs );
669
+    if (empty($subscription)) {
670
+        $subs         = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1));
671
+        $subscription = reset($subs);
672 672
 
673
-        if ( $subscription && $subscription->ID > 0 ) {
673
+        if ($subscription && $subscription->ID > 0) {
674 674
             // Update the profile ID so it is set for future renewals
675
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
675
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
676 676
         } else {
677 677
             $subscription = $invoice;
678
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
678
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
679 679
             // No subscription found with a matching payment ID, bail
680 680
             //return false;
681 681
         }
@@ -685,39 +685,39 @@  discard block
 block discarded – undo
685 685
 
686 686
 }
687 687
 
688
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
688
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
689 689
 	// Collect payment details
690 690
 
691
-	if( empty( $invoice_id ) ) {
691
+	if (empty($invoice_id)) {
692 692
 		return;
693 693
 	}
694 694
 
695
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
695
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
696 696
 		return; // Only refund payments once
697 697
 	}
698 698
 
699
-	$payment_amount = wpinv_payment_total( $invoice_id );
699
+	$payment_amount = wpinv_payment_total($invoice_id);
700 700
 	$refund_amount  = $data['mc_gross'] * -1;
701 701
 
702
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
703
-		wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
702
+	if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) {
703
+		wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id']));
704 704
 		return; // This is a partial refund
705 705
 	}
706 706
 
707
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
708
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
709
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
707
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']));
708
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']));
709
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
710 710
 }
711 711
 
712
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
713
-    if ( is_ssl() || ! $ssl_check ) {
712
+function wpinv_get_paypal_redirect($ssl_check = false) {
713
+    if (is_ssl() || !$ssl_check) {
714 714
         $protocol = 'https://';
715 715
     } else {
716 716
         $protocol = 'http://';
717 717
     }
718 718
 
719 719
     // Check the current payment mode
720
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
720
+    if (wpinv_is_test_mode('paypal')) {
721 721
         // Test mode
722 722
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
723 723
     } else {
@@ -725,67 +725,67 @@  discard block
 block discarded – undo
725 725
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
726 726
     }
727 727
 
728
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
728
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
729 729
 }
730 730
 
731
-function wpinv_paypal_success_page_content( $content ) {
731
+function wpinv_paypal_success_page_content($content) {
732 732
     global $wpi_invoice;
733 733
     
734 734
     $session = wpinv_get_checkout_session();
735 735
 
736
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
736
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
737 737
         return $content;
738 738
     }
739 739
 
740
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
740
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
741 741
 
742
-    if ( empty(  $invoice_id ) ) {
742
+    if (empty($invoice_id)) {
743 743
         return $content;
744 744
     }
745 745
 
746
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
746
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
747 747
     
748
-    if ( !empty( $wpi_invoice ) && 'pending' == $wpi_invoice->status ) {
748
+    if (!empty($wpi_invoice) && 'pending' == $wpi_invoice->status) {
749 749
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
750 750
         ob_start();
751
-        wpinv_get_template_part( 'wpinv-payment-processing' );
751
+        wpinv_get_template_part('wpinv-payment-processing');
752 752
         $content = ob_get_clean();
753 753
     }
754 754
 
755 755
     return $content;
756 756
 }
757
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
757
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
758 758
 
759
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
759
+function wpinv_paypal_get_transaction_id($invoice_id) {
760 760
     $transaction_id = '';
761
-    $notes = wpinv_get_invoice_notes( $invoice_id );
761
+    $notes = wpinv_get_invoice_notes($invoice_id);
762 762
 
763
-    foreach ( $notes as $note ) {
764
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
763
+    foreach ($notes as $note) {
764
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
765 765
             $transaction_id = $match[1];
766 766
             continue;
767 767
         }
768 768
     }
769 769
 
770
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
770
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
771 771
 }
772
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
772
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
773 773
 
774
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
775
-    if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal.
774
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
775
+    if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal.
776 776
         $transaction_url = $invoice->get_view_url();
777 777
     } else {
778
-        $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : '';
778
+        $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : '';
779 779
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id;
780 780
     }
781 781
 
782
-    $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
782
+    $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
783 783
 
784
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice );
784
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice);
785 785
 }
786
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
786
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
787 787
 
788 788
 function wpinv_gateway_paypal_button_label($label) {
789
-    return __( 'Proceed to PayPal', 'invoicing' );
789
+    return __('Proceed to PayPal', 'invoicing');
790 790
 }
791
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
792 791
\ No newline at end of file
792
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
793 793
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/worldpay.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  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
-add_action( 'wpinv_worldpay_cc_form', '__return_false' );
5
+add_action('wpinv_worldpay_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_worldpay_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_worldpay_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
     
12 12
     // Collect payment data
@@ -24,120 +24,120 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
29
+    if (!empty($invoice)) {
30 30
         $quantities_enabled = wpinv_item_quantities_enabled();
31 31
         
32
-        $instId     = wpinv_get_option( 'worldpay_instId', false );
32
+        $instId     = wpinv_get_option('worldpay_instId', false);
33 33
         $cartId     = $invoice->get_number();
34
-        $testMode   = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0;
34
+        $testMode   = wpinv_is_test_mode('worldpay') ? 100 : 0;
35 35
         $name       = $invoice->get_user_full_name();
36
-        $address    = wp_strip_all_tags( $invoice->get_address(), true );
36
+        $address    = wp_strip_all_tags($invoice->get_address(), true);
37 37
         $postcode   = $invoice->zip;
38 38
         $tel        = $invoice->phone;
39 39
         $email      = $invoice->get_email();
40 40
         $country    = $invoice->country;
41
-        $amount     = wpinv_sanitize_amount( $invoice->get_total() );
41
+        $amount     = wpinv_sanitize_amount($invoice->get_total());
42 42
         $currency   = wpinv_get_currency();
43 43
         
44 44
         $items      = array();
45
-        foreach ( $invoice->get_cart_details() as $item ) {
45
+        foreach ($invoice->get_cart_details() as $item) {
46 46
             $item_desc  = $item['name'];
47
-            $quantity   = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
-            $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
47
+            $quantity   = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
+            $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
49 49
             
50 50
             $items[] = $item_desc;
51 51
         }
52 52
         
53
-        $desc = implode( ', ', $items );
54
-        if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) {
55
-            $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
53
+        $desc = implode(', ', $items);
54
+        if (wpinv_use_taxes() && $invoice->get_tax() > 0) {
55
+            $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
56 56
         }
57 57
         
58 58
         $extra_params                   = array();
59 59
         $extra_params['MC_description'] = $desc;
60
-        $extra_params['MC_callback']    = wpinv_get_ipn_url( 'worldpay' );
60
+        $extra_params['MC_callback']    = wpinv_get_ipn_url('worldpay');
61 61
         $extra_params['MC_key']         = $invoice->get_key();
62 62
         $extra_params['MC_invoice_id']  = $invoice->ID;
63 63
         $extra_params['address1']       = $address;
64 64
         $extra_params['town']           = $invoice->city;
65 65
         $extra_params['region']         = $invoice->state;
66
-        $extra_params['amountString']   = $invoice->get_total( true );
67
-        $extra_params['countryString']  = wpinv_country_name( $invoice->country );
66
+        $extra_params['amountString']   = $invoice->get_total(true);
67
+        $extra_params['countryString']  = wpinv_country_name($invoice->country);
68 68
         $extra_params['compName']       = $invoice->company;
69 69
         
70
-        $extra_params   = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice );
70
+        $extra_params   = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice);
71 71
         
72
-        $redirect_text  = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' );
73
-        $redirect_text  = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice );
72
+        $redirect_text  = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing');
73
+        $redirect_text  = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice);
74 74
         
75 75
         // Empty the shopping cart
76 76
         wpinv_empty_cart();
77 77
         ?>
78 78
 <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555">
79
-<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?>
80
-<h3><?php echo $redirect_text ;?></h3>
79
+<?php do_action('wpinv_worldpay_form_before', $invoice); ?>
80
+<h3><?php echo $redirect_text; ?></h3>
81 81
 <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST">
82
-    <input type="hidden" value="<?php echo $amount;?>" name="amount">
83
-    <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId">
84
-    <input type="hidden" value="<?php echo $currency;?>" name="currency">
85
-    <input type="hidden" value="<?php echo $instId;?>" name="instId">
86
-    <input type="hidden" value="<?php echo $testMode;?>" name="testMode">
87
-    <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name">
88
-    <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address">
89
-    <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode">
90
-    <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel">
91
-    <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email">
92
-    <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country">
93
-    <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc">
94
-    <?php foreach ( $extra_params as $param => $value ) { ?>
95
-        <?php if ( !empty( $value !== false ) ) { ?>
96
-    <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>">
82
+    <input type="hidden" value="<?php echo $amount; ?>" name="amount">
83
+    <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId">
84
+    <input type="hidden" value="<?php echo $currency; ?>" name="currency">
85
+    <input type="hidden" value="<?php echo $instId; ?>" name="instId">
86
+    <input type="hidden" value="<?php echo $testMode; ?>" name="testMode">
87
+    <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name">
88
+    <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address">
89
+    <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode">
90
+    <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel">
91
+    <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email">
92
+    <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country">
93
+    <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc">
94
+    <?php foreach ($extra_params as $param => $value) { ?>
95
+        <?php if (!empty($value !== false)) { ?>
96
+    <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>">
97 97
         <?php } ?>
98 98
     <?php } ?>
99
-    <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?>
100
-    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>">
99
+    <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?>
100
+    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>">
101 101
 </form>
102 102
 <script type="text/javascript">document.wpi_worldpay_form.submit();</script>
103
-<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?>
103
+<?php do_action('wpinv_worldpay_form_after', $invoice); ?>
104 104
 </div>
105 105
         <?php
106 106
     } else {
107
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
107
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
108 108
         // If errors are present, send the user back to the purchase page so they can be corrected
109
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
109
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
110 110
     }
111 111
 }
112
-add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' );
112
+add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment');
113 113
 
114 114
 function wpinv_get_worldpay_redirect() {
115
-    $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
115
+    $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
116 116
     
117
-    return apply_filters( 'wpinv_worldpay_redirect', $redirect );
117
+    return apply_filters('wpinv_worldpay_redirect', $redirect);
118 118
 }
119 119
 
120 120
 function wpinv_process_worldpay_ipn() {
121
-    $request = wpinv_get_post_data( 'post' );
121
+    $request = wpinv_get_post_data('post');
122 122
     
123
-    if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) {
123
+    if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) {
124 124
         $invoice_id = $request['MC_invoice_id'];
125 125
         
126
-        if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) {
127
-            if ( $request['transStatus'] == 'Y' ) {                
128
-                wpinv_update_payment_status( $invoice_id, 'publish' );
129
-                wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] );
130
-                wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) );
126
+        if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) {
127
+            if ($request['transStatus'] == 'Y') {                
128
+                wpinv_update_payment_status($invoice_id, 'publish');
129
+                wpinv_set_payment_transaction_id($invoice_id, $request['transId']);
130
+                wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId']));
131 131
                 return;
132
-            } else if ( $request['transStatus'] == 'C' ) {
133
-                wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
134
-                wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) );
132
+            } else if ($request['transStatus'] == 'C') {
133
+                wpinv_update_payment_status($invoice_id, 'wpi-failed');
134
+                wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing'));
135 135
                 
136
-                wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id );
136
+                wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id);
137 137
                 return;
138 138
             }
139 139
         }
140 140
     }
141 141
     return;
142 142
 }
143
-add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' );
144 143
\ No newline at end of file
144
+add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn');
145 145
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Spacing   +492 added lines, -492 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,74 +28,74 @@  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 );
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 77
 
78 78
 function wpinv_send_transactional_email() {
79 79
     $args       = func_get_args();
80 80
     $function   = current_filter() . '_notification';
81
-    do_action_ref_array( $function, $args );
81
+    do_action_ref_array($function, $args);
82 82
 }
83 83
     
84
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
84
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
85 85
     global $wpinv_email_search, $wpinv_email_replace;
86 86
     
87 87
     $email_type = 'new_invoice';
88
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
88
+    if (!wpinv_email_is_enabled($email_type)) {
89 89
         return false;
90 90
     }
91 91
     
92
-    $invoice = wpinv_get_invoice( $invoice_id );
93
-    if ( empty( $invoice ) ) {
92
+    $invoice = wpinv_get_invoice($invoice_id);
93
+    if (empty($invoice)) {
94 94
         return false;
95 95
     }
96 96
     
97
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
98
-    if ( !is_email( $recipient ) ) {
97
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
98
+    if (!is_email($recipient)) {
99 99
         return false;
100 100
     }
101 101
         
@@ -112,37 +112,37 @@  discard block
 block discarded – undo
112 112
     $wpinv_email_search     = $search;
113 113
     $wpinv_email_replace    = $replace;
114 114
     
115
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
116
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
117
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
118
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
115
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
116
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
117
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
118
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
119 119
     
120
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
120
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
121 121
             'invoice'       => $invoice,
122 122
             'email_type'    => $email_type,
123 123
             'email_heading' => $email_heading,
124 124
             'sent_to_admin' => true,
125 125
             'plain_text'    => false,
126
-        ) );
126
+        ));
127 127
     
128
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
128
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
129 129
 }
130 130
 
131
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
131
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
132 132
     global $wpinv_email_search, $wpinv_email_replace;
133 133
     
134 134
     $email_type = 'cancelled_invoice';
135
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
135
+    if (!wpinv_email_is_enabled($email_type)) {
136 136
         return false;
137 137
     }
138 138
     
139
-    $invoice = wpinv_get_invoice( $invoice_id );
140
-    if ( empty( $invoice ) ) {
139
+    $invoice = wpinv_get_invoice($invoice_id);
140
+    if (empty($invoice)) {
141 141
         return false;
142 142
     }
143 143
     
144
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
145
-    if ( !is_email( $recipient ) ) {
144
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
145
+    if (!is_email($recipient)) {
146 146
         return false;
147 147
     }
148 148
         
@@ -159,37 +159,37 @@  discard block
 block discarded – undo
159 159
     $wpinv_email_search     = $search;
160 160
     $wpinv_email_replace    = $replace;
161 161
     
162
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
163
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
164
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
165
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
162
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
163
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
164
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
165
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
166 166
     
167
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
167
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
168 168
             'invoice'       => $invoice,
169 169
             'email_type'    => $email_type,
170 170
             'email_heading' => $email_heading,
171 171
             'sent_to_admin' => true,
172 172
             'plain_text'    => false,
173
-        ) );
173
+        ));
174 174
     
175
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
175
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
176 176
 }
177 177
 
178
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
178
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
179 179
     global $wpinv_email_search, $wpinv_email_replace;
180 180
     
181 181
     $email_type = 'failed_invoice';
182
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
182
+    if (!wpinv_email_is_enabled($email_type)) {
183 183
         return false;
184 184
     }
185 185
     
186
-    $invoice = wpinv_get_invoice( $invoice_id );
187
-    if ( empty( $invoice ) ) {
186
+    $invoice = wpinv_get_invoice($invoice_id);
187
+    if (empty($invoice)) {
188 188
         return false;
189 189
     }
190 190
     
191
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
192
-    if ( !is_email( $recipient ) ) {
191
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
192
+    if (!is_email($recipient)) {
193 193
         return false;
194 194
     }
195 195
         
@@ -206,37 +206,37 @@  discard block
 block discarded – undo
206 206
     $wpinv_email_search     = $search;
207 207
     $wpinv_email_replace    = $replace;
208 208
     
209
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
210
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
211
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
212
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
209
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
210
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
211
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
212
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
213 213
     
214
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
214
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
215 215
             'invoice'       => $invoice,
216 216
             'email_type'    => $email_type,
217 217
             'email_heading' => $email_heading,
218 218
             'sent_to_admin' => true,
219 219
             'plain_text'    => false,
220
-        ) );
220
+        ));
221 221
     
222
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
222
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
223 223
 }
224 224
 
225
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
225
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
226 226
     global $wpinv_email_search, $wpinv_email_replace;
227 227
     
228 228
     $email_type = 'onhold_invoice';
229
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
229
+    if (!wpinv_email_is_enabled($email_type)) {
230 230
         return false;
231 231
     }
232 232
     
233
-    $invoice = wpinv_get_invoice( $invoice_id );
234
-    if ( empty( $invoice ) ) {
233
+    $invoice = wpinv_get_invoice($invoice_id);
234
+    if (empty($invoice)) {
235 235
         return false;
236 236
     }
237 237
     
238
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
239
-    if ( !is_email( $recipient ) ) {
238
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
239
+    if (!is_email($recipient)) {
240 240
         return false;
241 241
     }
242 242
         
@@ -253,45 +253,45 @@  discard block
 block discarded – undo
253 253
     $wpinv_email_search     = $search;
254 254
     $wpinv_email_replace    = $replace;
255 255
     
256
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
257
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
258
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
259
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
256
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
257
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
258
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
259
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
260 260
     
261
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
261
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
262 262
             'invoice'       => $invoice,
263 263
             'email_type'    => $email_type,
264 264
             'email_heading' => $email_heading,
265 265
             'sent_to_admin' => false,
266 266
             'plain_text'    => false,
267
-        ) );
267
+        ));
268 268
     
269
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
269
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
270 270
     
271
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
272
-        $recipient  = wpinv_get_admin_email();
273
-        $subject    .= ' - ADMIN BCC COPY';
274
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
271
+    if (wpinv_mail_admin_bcc_active($email_type)) {
272
+        $recipient = wpinv_get_admin_email();
273
+        $subject .= ' - ADMIN BCC COPY';
274
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
275 275
     }
276 276
     
277 277
     return $sent;
278 278
 }
279 279
 
280
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
280
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
281 281
     global $wpinv_email_search, $wpinv_email_replace;
282 282
     
283 283
     $email_type = 'processing_invoice';
284
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
284
+    if (!wpinv_email_is_enabled($email_type)) {
285 285
         return false;
286 286
     }
287 287
     
288
-    $invoice = wpinv_get_invoice( $invoice_id );
289
-    if ( empty( $invoice ) ) {
288
+    $invoice = wpinv_get_invoice($invoice_id);
289
+    if (empty($invoice)) {
290 290
         return false;
291 291
     }
292 292
     
293
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
294
-    if ( !is_email( $recipient ) ) {
293
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
294
+    if (!is_email($recipient)) {
295 295
         return false;
296 296
     }
297 297
         
@@ -308,45 +308,45 @@  discard block
 block discarded – undo
308 308
     $wpinv_email_search     = $search;
309 309
     $wpinv_email_replace    = $replace;
310 310
     
311
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
312
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
313
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
314
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
311
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
312
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
313
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
314
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
315 315
     
316
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
316
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
317 317
             'invoice'       => $invoice,
318 318
             'email_type'    => $email_type,
319 319
             'email_heading' => $email_heading,
320 320
             'sent_to_admin' => false,
321 321
             'plain_text'    => false,
322
-        ) );
322
+        ));
323 323
     
324
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
324
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
325 325
     
326
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
327
-        $recipient  = wpinv_get_admin_email();
328
-        $subject    .= ' - ADMIN BCC COPY';
329
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
326
+    if (wpinv_mail_admin_bcc_active($email_type)) {
327
+        $recipient = wpinv_get_admin_email();
328
+        $subject .= ' - ADMIN BCC COPY';
329
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
330 330
     }
331 331
     
332 332
     return $sent;
333 333
 }
334 334
 
335
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
335
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
336 336
     global $wpinv_email_search, $wpinv_email_replace;
337 337
     
338 338
     $email_type = 'completed_invoice';
339
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
339
+    if (!wpinv_email_is_enabled($email_type)) {
340 340
         return false;
341 341
     }
342 342
     
343
-    $invoice = wpinv_get_invoice( $invoice_id );
344
-    if ( empty( $invoice ) ) {
343
+    $invoice = wpinv_get_invoice($invoice_id);
344
+    if (empty($invoice)) {
345 345
         return false;
346 346
     }
347 347
     
348
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
349
-    if ( !is_email( $recipient ) ) {
348
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
349
+    if (!is_email($recipient)) {
350 350
         return false;
351 351
     }
352 352
         
@@ -363,45 +363,45 @@  discard block
 block discarded – undo
363 363
     $wpinv_email_search     = $search;
364 364
     $wpinv_email_replace    = $replace;
365 365
     
366
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
367
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
368
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
369
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
366
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
367
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
368
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
369
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
370 370
     
371
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
371
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
372 372
             'invoice'       => $invoice,
373 373
             'email_type'    => $email_type,
374 374
             'email_heading' => $email_heading,
375 375
             'sent_to_admin' => false,
376 376
             'plain_text'    => false,
377
-        ) );
377
+        ));
378 378
     
379
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
379
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
380 380
     
381
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
382
-        $recipient  = wpinv_get_admin_email();
383
-        $subject    .= ' - ADMIN BCC COPY';
384
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
381
+    if (wpinv_mail_admin_bcc_active($email_type)) {
382
+        $recipient = wpinv_get_admin_email();
383
+        $subject .= ' - ADMIN BCC COPY';
384
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
385 385
     }
386 386
     
387 387
     return $sent;
388 388
 }
389 389
 
390
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
390
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
391 391
     global $wpinv_email_search, $wpinv_email_replace;
392 392
     
393 393
     $email_type = 'refunded_invoice';
394
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
394
+    if (!wpinv_email_is_enabled($email_type)) {
395 395
         return false;
396 396
     }
397 397
     
398
-    $invoice = wpinv_get_invoice( $invoice_id );
399
-    if ( empty( $invoice ) ) {
398
+    $invoice = wpinv_get_invoice($invoice_id);
399
+    if (empty($invoice)) {
400 400
         return false;
401 401
     }
402 402
     
403
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
404
-    if ( !is_email( $recipient ) ) {
403
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
404
+    if (!is_email($recipient)) {
405 405
         return false;
406 406
     }
407 407
         
@@ -418,46 +418,46 @@  discard block
 block discarded – undo
418 418
     $wpinv_email_search     = $search;
419 419
     $wpinv_email_replace    = $replace;
420 420
     
421
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
422
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
423
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
424
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
421
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
422
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
423
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
424
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
425 425
     
426
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
426
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
427 427
             'invoice'           => $invoice,
428 428
             'email_type'        => $email_type,
429 429
             'email_heading'     => $email_heading,
430 430
             'sent_to_admin'     => false,
431 431
             'plain_text'        => false,
432 432
             'partial_refund'    => false
433
-        ) );
433
+        ));
434 434
     
435
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
435
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
436 436
     
437
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
438
-        $recipient  = wpinv_get_admin_email();
439
-        $subject    .= ' - ADMIN BCC COPY';
440
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
437
+    if (wpinv_mail_admin_bcc_active($email_type)) {
438
+        $recipient = wpinv_get_admin_email();
439
+        $subject .= ' - ADMIN BCC COPY';
440
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
441 441
     }
442 442
     
443 443
     return $sent;
444 444
 }
445 445
 
446
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
446
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
447 447
     global $wpinv_email_search, $wpinv_email_replace;
448 448
     
449 449
     $email_type = 'refunded_invoice';
450
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
450
+    if (!wpinv_email_is_enabled($email_type)) {
451 451
         return false;
452 452
     }
453 453
     
454
-    $invoice = wpinv_get_invoice( $invoice_id );
455
-    if ( empty( $invoice ) ) {
454
+    $invoice = wpinv_get_invoice($invoice_id);
455
+    if (empty($invoice)) {
456 456
         return false;
457 457
     }
458 458
     
459
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
460
-    if ( !is_email( $recipient ) ) {
459
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
460
+    if (!is_email($recipient)) {
461 461
         return false;
462 462
     }
463 463
         
@@ -474,49 +474,49 @@  discard block
 block discarded – undo
474 474
     $wpinv_email_search     = $search;
475 475
     $wpinv_email_replace    = $replace;
476 476
     
477
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
478
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
479
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
480
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
477
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
478
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
479
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
480
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
481 481
     
482
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
482
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
483 483
             'invoice'           => $invoice,
484 484
             'email_type'        => $email_type,
485 485
             'email_heading'     => $email_heading,
486 486
             'sent_to_admin'     => false,
487 487
             'plain_text'        => false,
488 488
             'partial_refund'    => true
489
-        ) );
489
+        ));
490 490
     
491
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
491
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
492 492
     
493
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
494
-        $recipient  = wpinv_get_admin_email();
495
-        $subject    .= ' - ADMIN BCC COPY';
496
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
493
+    if (wpinv_mail_admin_bcc_active($email_type)) {
494
+        $recipient = wpinv_get_admin_email();
495
+        $subject .= ' - ADMIN BCC COPY';
496
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
497 497
     }
498 498
     
499 499
     return $sent;
500 500
 }
501 501
 
502
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
502
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
503 503
 }
504 504
 
505
-function wpinv_user_invoice_notification( $invoice_id ) {
505
+function wpinv_user_invoice_notification($invoice_id) {
506 506
     global $wpinv_email_search, $wpinv_email_replace;
507 507
     
508 508
     $email_type = 'user_invoice';
509
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
509
+    if (!wpinv_email_is_enabled($email_type)) {
510 510
         return false;
511 511
     }
512 512
     
513
-    $invoice = wpinv_get_invoice( $invoice_id );
514
-    if ( empty( $invoice ) ) {
513
+    $invoice = wpinv_get_invoice($invoice_id);
514
+    if (empty($invoice)) {
515 515
         return false;
516 516
     }
517 517
     
518
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
519
-    if ( !is_email( $recipient ) ) {
518
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
519
+    if (!is_email($recipient)) {
520 520
         return false;
521 521
     }
522 522
         
@@ -533,52 +533,52 @@  discard block
 block discarded – undo
533 533
     $wpinv_email_search     = $search;
534 534
     $wpinv_email_replace    = $replace;
535 535
     
536
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
537
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
538
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
539
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
536
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
537
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
538
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
539
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
540 540
     
541
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
541
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
542 542
             'invoice'       => $invoice,
543 543
             'email_type'    => $email_type,
544 544
             'email_heading' => $email_heading,
545 545
             'sent_to_admin' => false,
546 546
             'plain_text'    => false,
547
-        ) );
547
+        ));
548 548
     
549
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
549
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
550 550
     
551
-    if ( $sent ) {
552
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
551
+    if ($sent) {
552
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
553 553
     } else {
554
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
554
+        $note = __('Fail to send invoice to the user!', 'invoicing');
555 555
     }
556
-    $invoice->add_note( $note ); // Add private note.
556
+    $invoice->add_note($note); // Add private note.
557 557
     
558
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
559
-        $recipient  = wpinv_get_admin_email();
560
-        $subject    .= ' - ADMIN BCC COPY';
561
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
558
+    if (wpinv_mail_admin_bcc_active($email_type)) {
559
+        $recipient = wpinv_get_admin_email();
560
+        $subject .= ' - ADMIN BCC COPY';
561
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
562 562
     }
563 563
     
564 564
     return $sent;
565 565
 }
566 566
 
567
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
567
+function wpinv_user_note_notification($invoice_id, $args = array()) {
568 568
     global $wpinv_email_search, $wpinv_email_replace;
569 569
     
570 570
     $email_type = 'user_note';
571
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
571
+    if (!wpinv_email_is_enabled($email_type)) {
572 572
         return false;
573 573
     }
574 574
     
575
-    $invoice = wpinv_get_invoice( $invoice_id );
576
-    if ( empty( $invoice ) ) {
575
+    $invoice = wpinv_get_invoice($invoice_id);
576
+    if (empty($invoice)) {
577 577
         return false;
578 578
     }
579 579
     
580
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
581
-    if ( !is_email( $recipient ) ) {
580
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
581
+    if (!is_email($recipient)) {
582 582
         return false;
583 583
     }
584 584
     
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
         'user_note' => ''
587 587
     );
588 588
 
589
-    $args = wp_parse_args( $args, $defaults );
589
+    $args = wp_parse_args($args, $defaults);
590 590
         
591 591
     $search                     = array();
592 592
     $search['invoice_number']   = '{invoice_number}';
@@ -603,46 +603,46 @@  discard block
 block discarded – undo
603 603
     $wpinv_email_search     = $search;
604 604
     $wpinv_email_replace    = $replace;
605 605
     
606
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
607
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
608
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
609
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
606
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
607
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
608
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
609
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
610 610
     
611
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
611
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
612 612
             'invoice'       => $invoice,
613 613
             'email_type'    => $email_type,
614 614
             'email_heading' => $email_heading,
615 615
             'sent_to_admin' => false,
616 616
             'plain_text'    => false,
617 617
             'customer_note' => $args['user_note']
618
-        ) );
618
+        ));
619 619
         
620
-    $content        = wpinv_email_format_text( $content );
620
+    $content = wpinv_email_format_text($content);
621 621
     
622
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
622
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
623 623
         
624 624
     return $sent;
625 625
 }
626 626
 
627 627
 function wpinv_mail_get_from_address() {
628
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
629
-    return sanitize_email( $from_address );
628
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
629
+    return sanitize_email($from_address);
630 630
 }
631 631
 
632 632
 function wpinv_mail_get_from_name() {
633
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
634
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
633
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
634
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
635 635
 }
636 636
 
637
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
638
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
639
-    return ( $active ? true : false );
637
+function wpinv_mail_admin_bcc_active($mail_type = '') {
638
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
639
+    return ($active ? true : false);
640 640
 }
641 641
     
642
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
643
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
642
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
643
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
644 644
     
645
-    switch ( $email_type ) {
645
+    switch ($email_type) {
646 646
         case 'html' :
647 647
             $content_type = 'text/html';
648 648
             break;
@@ -657,35 +657,35 @@  discard block
 block discarded – undo
657 657
     return $content_type;
658 658
 }
659 659
     
660
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
661
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
662
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
663
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
660
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments) {
661
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
662
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
663
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
664 664
 
665
-    $message = wpinv_email_style_body( $message );
666
-    $message = apply_filters( 'wpinv_mail_content', $message );
665
+    $message = wpinv_email_style_body($message);
666
+    $message = apply_filters('wpinv_mail_content', $message);
667 667
     
668
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
668
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
669 669
     
670
-    if ( !$sent ) {
671
-        $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 );
672
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
670
+    if (!$sent) {
671
+        $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);
672
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
673 673
     }
674 674
 
675
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
676
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
677
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
675
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
676
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
677
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
678 678
 
679 679
     return $sent;
680 680
 }
681 681
     
682 682
 function wpinv_get_emails() {
683 683
     $overdue_days_options       = array();
684
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
685
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
684
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
685
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
686 686
     
687
-    for ( $i = 2; $i <= 10; $i++ ) {
688
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
687
+    for ($i = 2; $i <= 10; $i++) {
688
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
689 689
     }
690 690
 
691 691
 	// Default, built-in gateways
@@ -693,130 +693,130 @@  discard block
 block discarded – undo
693 693
             'new_invoice' => array(
694 694
             'email_new_invoice_header' => array(
695 695
                 'id'   => 'email_new_invoice_header',
696
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
697
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
696
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
697
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
698 698
                 'type' => 'header',
699 699
             ),
700 700
             'email_new_invoice_active' => array(
701 701
                 'id'   => 'email_new_invoice_active',
702
-                'name' => __( 'Enable/Disable', 'invoicing' ),
703
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
702
+                'name' => __('Enable/Disable', 'invoicing'),
703
+                'desc' => __('Enable this email notification', 'invoicing'),
704 704
                 'type' => 'checkbox',
705 705
                 'std'  => 1
706 706
             ),
707 707
             'email_new_invoice_subject' => array(
708 708
                 'id'   => 'email_new_invoice_subject',
709
-                'name' => __( 'Subject', 'invoicing' ),
710
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
709
+                'name' => __('Subject', 'invoicing'),
710
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
711 711
                 'type' => 'text',
712
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
712
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
713 713
                 'size' => 'large'
714 714
             ),
715 715
             'email_new_invoice_heading' => array(
716 716
                 'id'   => 'email_new_invoice_heading',
717
-                'name' => __( 'Email Heading', 'invoicing' ),
718
-                'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
717
+                'name' => __('Email Heading', 'invoicing'),
718
+                'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
719 719
                 'type' => 'text',
720
-                'std'  => __( 'New payment invoice', 'invoicing' ),
720
+                'std'  => __('New payment invoice', 'invoicing'),
721 721
                 'size' => 'large'
722 722
             ),
723 723
         ),
724 724
         'cancelled_invoice' => array(
725 725
             'email_cancelled_invoice_header' => array(
726 726
                 'id'   => 'email_cancelled_invoice_header',
727
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
728
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
727
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
728
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
729 729
                 'type' => 'header',
730 730
             ),
731 731
             'email_cancelled_invoice_active' => array(
732 732
                 'id'   => 'email_cancelled_invoice_active',
733
-                'name' => __( 'Enable/Disable', 'invoicing' ),
734
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
733
+                'name' => __('Enable/Disable', 'invoicing'),
734
+                'desc' => __('Enable this email notification', 'invoicing'),
735 735
                 'type' => 'checkbox',
736 736
                 'std'  => 1
737 737
             ),
738 738
             'email_cancelled_invoice_subject' => array(
739 739
                 'id'   => 'email_cancelled_invoice_subject',
740
-                'name' => __( 'Subject', 'invoicing' ),
741
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
740
+                'name' => __('Subject', 'invoicing'),
741
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
742 742
                 'type' => 'text',
743
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
743
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
744 744
                 'size' => 'large'
745 745
             ),
746 746
             'email_cancelled_invoice_heading' => array(
747 747
                 'id'   => 'email_cancelled_invoice_heading',
748
-                'name' => __( 'Email Heading', 'invoicing' ),
749
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
748
+                'name' => __('Email Heading', 'invoicing'),
749
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
750 750
                 'type' => 'text',
751
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
751
+                'std'  => __('Cancelled invoice', 'invoicing'),
752 752
                 'size' => 'large'
753 753
             ),
754 754
         ),
755 755
         'failed_invoice' => array(
756 756
             'email_failed_invoice_header' => array(
757 757
                 'id'   => 'email_failed_invoice_header',
758
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
759
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
758
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
759
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
760 760
                 'type' => 'header',
761 761
             ),
762 762
             'email_failed_invoice_active' => array(
763 763
                 'id'   => 'email_failed_invoice_active',
764
-                'name' => __( 'Enable/Disable', 'invoicing' ),
765
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
764
+                'name' => __('Enable/Disable', 'invoicing'),
765
+                'desc' => __('Enable this email notification', 'invoicing'),
766 766
                 'type' => 'checkbox',
767 767
                 'std'  => 1
768 768
             ),
769 769
             'email_failed_invoice_subject' => array(
770 770
                 'id'   => 'email_failed_invoice_subject',
771
-                'name' => __( 'Subject', 'invoicing' ),
772
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
771
+                'name' => __('Subject', 'invoicing'),
772
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
773 773
                 'type' => 'text',
774
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
774
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
775 775
                 'size' => 'large'
776 776
             ),
777 777
             'email_failed_invoice_heading' => array(
778 778
                 'id'   => 'email_failed_invoice_heading',
779
-                'name' => __( 'Email Heading', 'invoicing' ),
780
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
779
+                'name' => __('Email Heading', 'invoicing'),
780
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
781 781
                 'type' => 'text',
782
-                'std'  => __( 'Failed invoice', 'invoicing' ),
782
+                'std'  => __('Failed invoice', 'invoicing'),
783 783
                 'size' => 'large'
784 784
             )
785 785
         ),
786 786
         'onhold_invoice' => array(
787 787
             'email_onhold_invoice_header' => array(
788 788
                 'id'   => 'email_onhold_invoice_header',
789
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
790
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
789
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
790
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
791 791
                 'type' => 'header',
792 792
             ),
793 793
             'email_onhold_invoice_active' => array(
794 794
                 'id'   => 'email_onhold_invoice_active',
795
-                'name' => __( 'Enable/Disable', 'invoicing' ),
796
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
795
+                'name' => __('Enable/Disable', 'invoicing'),
796
+                'desc' => __('Enable this email notification', 'invoicing'),
797 797
                 'type' => 'checkbox',
798 798
                 'std'  => 1
799 799
             ),
800 800
             'email_onhold_invoice_subject' => array(
801 801
                 'id'   => 'email_onhold_invoice_subject',
802
-                'name' => __( 'Subject', 'invoicing' ),
803
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
802
+                'name' => __('Subject', 'invoicing'),
803
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
804 804
                 'type' => 'text',
805
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
805
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
806 806
                 'size' => 'large'
807 807
             ),
808 808
             'email_onhold_invoice_heading' => array(
809 809
                 'id'   => 'email_onhold_invoice_heading',
810
-                'name' => __( 'Email Heading', 'invoicing' ),
811
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
810
+                'name' => __('Email Heading', 'invoicing'),
811
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
812 812
                 'type' => 'text',
813
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
813
+                'std'  => __('Thank you for your invoice', 'invoicing'),
814 814
                 'size' => 'large'
815 815
             ),
816 816
             'email_onhold_invoice_admin_bcc' => array(
817 817
                 'id'   => 'email_onhold_invoice_admin_bcc',
818
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
819
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
818
+                'name' => __('Enable Admin BCC', 'invoicing'),
819
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
820 820
                 'type' => 'checkbox',
821 821
                 'std'  => 1
822 822
             ),
@@ -824,37 +824,37 @@  discard block
 block discarded – undo
824 824
         'processing_invoice' => array(
825 825
             'email_processing_invoice_header' => array(
826 826
                 'id'   => 'email_processing_invoice_header',
827
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
828
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
827
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
828
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
829 829
                 'type' => 'header',
830 830
             ),
831 831
             'email_processing_invoice_active' => array(
832 832
                 'id'   => 'email_processing_invoice_active',
833
-                'name' => __( 'Enable/Disable', 'invoicing' ),
834
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
833
+                'name' => __('Enable/Disable', 'invoicing'),
834
+                'desc' => __('Enable this email notification', 'invoicing'),
835 835
                 'type' => 'checkbox',
836 836
                 'std'  => 1
837 837
             ),
838 838
             'email_processing_invoice_subject' => array(
839 839
                 'id'   => 'email_processing_invoice_subject',
840
-                'name' => __( 'Subject', 'invoicing' ),
841
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
840
+                'name' => __('Subject', 'invoicing'),
841
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
842 842
                 'type' => 'text',
843
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
843
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
844 844
                 'size' => 'large'
845 845
             ),
846 846
             'email_processing_invoice_heading' => array(
847 847
                 'id'   => 'email_processing_invoice_heading',
848
-                'name' => __( 'Email Heading', 'invoicing' ),
849
-                'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
848
+                'name' => __('Email Heading', 'invoicing'),
849
+                'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
850 850
                 'type' => 'text',
851
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
851
+                'std'  => __('Thank you for your invoice', 'invoicing'),
852 852
                 'size' => 'large'
853 853
             ),
854 854
             'email_processing_invoice_admin_bcc' => array(
855 855
                 'id'   => 'email_processing_invoice_admin_bcc',
856
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
857
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
856
+                'name' => __('Enable Admin BCC', 'invoicing'),
857
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
858 858
                 'type' => 'checkbox',
859 859
                 'std'  => 1
860 860
             ),
@@ -862,37 +862,37 @@  discard block
 block discarded – undo
862 862
         'completed_invoice' => array(
863 863
             'email_completed_invoice_header' => array(
864 864
                 'id'   => 'email_completed_invoice_header',
865
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
866
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
865
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
866
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
867 867
                 'type' => 'header',
868 868
             ),
869 869
             'email_completed_invoice_active' => array(
870 870
                 'id'   => 'email_completed_invoice_active',
871
-                'name' => __( 'Enable/Disable', 'invoicing' ),
872
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
871
+                'name' => __('Enable/Disable', 'invoicing'),
872
+                'desc' => __('Enable this email notification', 'invoicing'),
873 873
                 'type' => 'checkbox',
874 874
                 'std'  => 1
875 875
             ),
876 876
             'email_completed_invoice_subject' => array(
877 877
                 'id'   => 'email_completed_invoice_subject',
878
-                'name' => __( 'Subject', 'invoicing' ),
879
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
878
+                'name' => __('Subject', 'invoicing'),
879
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
880 880
                 'type' => 'text',
881
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
881
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
882 882
                 'size' => 'large'
883 883
             ),
884 884
             'email_completed_invoice_heading' => array(
885 885
                 'id'   => 'email_completed_invoice_heading',
886
-                'name' => __( 'Email Heading', 'invoicing' ),
887
-                'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
886
+                'name' => __('Email Heading', 'invoicing'),
887
+                'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
888 888
                 'type' => 'text',
889
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
889
+                'std'  => __('Your invoice has been paid', 'invoicing'),
890 890
                 'size' => 'large'
891 891
             ),
892 892
             'email_completed_invoice_admin_bcc' => array(
893 893
                 'id'   => 'email_completed_invoice_admin_bcc',
894
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
895
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
894
+                'name' => __('Enable Admin BCC', 'invoicing'),
895
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
896 896
                 'type' => 'checkbox',
897 897
             ),
898 898
             'std'  => 1
@@ -900,37 +900,37 @@  discard block
 block discarded – undo
900 900
         'refunded_invoice' => array(
901 901
             'email_refunded_invoice_header' => array(
902 902
                 'id'   => 'email_refunded_invoice_header',
903
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
904
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
903
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
904
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
905 905
                 'type' => 'header',
906 906
             ),
907 907
             'email_refunded_invoice_active' => array(
908 908
                 'id'   => 'email_refunded_invoice_active',
909
-                'name' => __( 'Enable/Disable', 'invoicing' ),
910
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
909
+                'name' => __('Enable/Disable', 'invoicing'),
910
+                'desc' => __('Enable this email notification', 'invoicing'),
911 911
                 'type' => 'checkbox',
912 912
                 'std'  => 1
913 913
             ),
914 914
             'email_refunded_invoice_subject' => array(
915 915
                 'id'   => 'email_refunded_invoice_subject',
916
-                'name' => __( 'Subject', 'invoicing' ),
917
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
916
+                'name' => __('Subject', 'invoicing'),
917
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
918 918
                 'type' => 'text',
919
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
919
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
920 920
                 'size' => 'large'
921 921
             ),
922 922
             'email_refunded_invoice_heading' => array(
923 923
                 'id'   => 'email_refunded_invoice_heading',
924
-                'name' => __( 'Email Heading', 'invoicing' ),
925
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
924
+                'name' => __('Email Heading', 'invoicing'),
925
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
926 926
                 'type' => 'text',
927
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
927
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
928 928
                 'size' => 'large'
929 929
             ),
930 930
             'email_refunded_invoice_admin_bcc' => array(
931 931
                 'id'   => 'email_refunded_invoice_admin_bcc',
932
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
933
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
932
+                'name' => __('Enable Admin BCC', 'invoicing'),
933
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
934 934
                 'type' => 'checkbox',
935 935
                 'std'  => 1
936 936
             ),
@@ -938,37 +938,37 @@  discard block
 block discarded – undo
938 938
         'user_invoice' => array(
939 939
             'email_user_invoice_header' => array(
940 940
                 'id'   => 'email_user_invoice_header',
941
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
942
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
941
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
942
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
943 943
                 'type' => 'header',
944 944
             ),
945 945
             'email_user_invoice_active' => array(
946 946
                 'id'   => 'email_user_invoice_active',
947
-                'name' => __( 'Enable/Disable', 'invoicing' ),
948
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
947
+                'name' => __('Enable/Disable', 'invoicing'),
948
+                'desc' => __('Enable this email notification', 'invoicing'),
949 949
                 'type' => 'checkbox',
950 950
                 'std'  => 1
951 951
             ),
952 952
             'email_user_invoice_subject' => array(
953 953
                 'id'   => 'email_user_invoice_subject',
954
-                'name' => __( 'Subject', 'invoicing' ),
955
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
954
+                'name' => __('Subject', 'invoicing'),
955
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
956 956
                 'type' => 'text',
957
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
957
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
958 958
                 'size' => 'large'
959 959
             ),
960 960
             'email_user_invoice_heading' => array(
961 961
                 'id'   => 'email_user_invoice_heading',
962
-                'name' => __( 'Email Heading', 'invoicing' ),
963
-                'desc' => __( 'Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
962
+                'name' => __('Email Heading', 'invoicing'),
963
+                'desc' => __('Enter the the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
964 964
                 'type' => 'text',
965
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
965
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
966 966
                 'size' => 'large'
967 967
             ),
968 968
             'email_user_invoice_admin_bcc' => array(
969 969
                 'id'   => 'email_user_invoice_admin_bcc',
970
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
971
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
970
+                'name' => __('Enable Admin BCC', 'invoicing'),
971
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
972 972
                 'type' => 'checkbox',
973 973
                 'std'  => 1
974 974
             ),
@@ -976,177 +976,177 @@  discard block
 block discarded – undo
976 976
         'user_note' => array(
977 977
             'email_user_note_header' => array(
978 978
                 'id'   => 'email_user_note_header',
979
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
980
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ),
979
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
980
+                'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'),
981 981
                 'type' => 'header',
982 982
             ),
983 983
             'email_user_note_active' => array(
984 984
                 'id'   => 'email_user_note_active',
985
-                'name' => __( 'Enable/Disable', 'invoicing' ),
986
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
985
+                'name' => __('Enable/Disable', 'invoicing'),
986
+                'desc' => __('Enable this email notification', 'invoicing'),
987 987
                 'type' => 'checkbox',
988 988
                 'std'  => 1
989 989
             ),
990 990
             'email_user_note_subject' => array(
991 991
                 'id'   => 'email_user_note_subject',
992
-                'name' => __( 'Subject', 'invoicing' ),
993
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
992
+                'name' => __('Subject', 'invoicing'),
993
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
994 994
                 'type' => 'text',
995
-                'std'  => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ),
995
+                'std'  => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'),
996 996
                 'size' => 'large'
997 997
             ),
998 998
             'email_user_note_heading' => array(
999 999
                 'id'   => 'email_user_note_heading',
1000
-                'name' => __( 'Email Heading', 'invoicing' ),
1001
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
1000
+                'name' => __('Email Heading', 'invoicing'),
1001
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
1002 1002
                 'type' => 'text',
1003
-                'std'  => __( 'A note has been added to your invoice', 'invoicing' ),
1003
+                'std'  => __('A note has been added to your invoice', 'invoicing'),
1004 1004
                 'size' => 'large'
1005 1005
             ),
1006 1006
         ),
1007 1007
         'overdue' => array(
1008 1008
             'email_overdue_header' => array(
1009 1009
                 'id'   => 'email_overdue_header',
1010
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1011
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1010
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1011
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1012 1012
                 'type' => 'header',
1013 1013
             ),
1014 1014
             'email_overdue_active' => array(
1015 1015
                 'id'   => 'email_overdue_active',
1016
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1017
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1016
+                'name' => __('Enable/Disable', 'invoicing'),
1017
+                'desc' => __('Enable this email notification', 'invoicing'),
1018 1018
                 'type' => 'checkbox',
1019 1019
                 'std'  => 1
1020 1020
             ),
1021 1021
             'email_due_reminder_days' => array(
1022 1022
                 'id'        => 'email_due_reminder_days',
1023
-                'name'      => __( 'When to Send', 'sliced-invoices' ),
1024
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1023
+                'name'      => __('When to Send', 'sliced-invoices'),
1024
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1025 1025
                 'default'   => '',
1026 1026
                 'type'      => 'multicheck',
1027 1027
                 'options'   => $overdue_days_options,
1028 1028
             ),
1029 1029
             'email_overdue_subject' => array(
1030 1030
                 'id'   => 'email_overdue_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}] Payment Reminder', 'invoicing' ),
1034
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1035 1035
                 'size' => 'large'
1036 1036
             ),
1037 1037
             'email_overdue_heading' => array(
1038 1038
                 'id'   => 'email_overdue_heading',
1039
-                'name' => __( 'Email Heading', 'invoicing' ),
1040
-                'desc' => __( 'Enter the the main heading contained within the email notification.', 'invoicing' ),
1039
+                'name' => __('Email Heading', 'invoicing'),
1040
+                'desc' => __('Enter the the main heading contained within the email notification.', 'invoicing'),
1041 1041
                 'type' => 'text',
1042
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1042
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1043 1043
                 'size' => 'large'
1044 1044
             ),
1045 1045
             'email_overdue_body' => array(
1046 1046
                 'id'   => 'email_overdue_body',
1047
-                'name' => __( 'Email Content', 'invoicing' ),
1048
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1047
+                'name' => __('Email Content', 'invoicing'),
1048
+                'desc' => __('The content of the email.', 'invoicing'),
1049 1049
                 'type' => 'rich_editor',
1050
-                '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' ),
1050
+                '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'),
1051 1051
                 'class' => 'large',
1052 1052
                 'size'  => 10,
1053 1053
             ),
1054 1054
         ),
1055 1055
     );
1056 1056
 
1057
-    return apply_filters( 'wpinv_get_emails', $emails );
1057
+    return apply_filters('wpinv_get_emails', $emails);
1058 1058
 }
1059 1059
 
1060
-function wpinv_settings_emails( $settings = array() ) {
1060
+function wpinv_settings_emails($settings = array()) {
1061 1061
     $emails = wpinv_get_emails();
1062 1062
     
1063
-    if ( !empty( $emails ) ) {
1064
-        foreach ( $emails as $key => $email ) {
1063
+    if (!empty($emails)) {
1064
+        foreach ($emails as $key => $email) {
1065 1065
             $settings[$key] = $email;
1066 1066
         }
1067 1067
     }
1068 1068
     
1069
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1069
+    return apply_filters('wpinv_settings_get_emails', $settings);
1070 1070
 }
1071
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1071
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1072 1072
 
1073
-function wpinv_settings_sections_emails( $settings ) {
1073
+function wpinv_settings_sections_emails($settings) {
1074 1074
     $emails = wpinv_get_emails();
1075 1075
     
1076 1076
     if (!empty($emails)) {
1077
-        foreach  ($emails as $key => $email) {
1078
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1077
+        foreach ($emails as $key => $email) {
1078
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1079 1079
         }
1080 1080
     }
1081 1081
     
1082 1082
     return $settings;    
1083 1083
 }
1084
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1084
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1085 1085
 
1086
-function wpinv_email_is_enabled( $email_type ) {
1086
+function wpinv_email_is_enabled($email_type) {
1087 1087
     $emails = wpinv_get_emails();
1088
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 1 ) ? true : false;
1088
+    $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 1) ? true : false;
1089 1089
 
1090
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1090
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1091 1091
 }
1092 1092
 
1093
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1094
-    switch ( $email_type ) {
1093
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1094
+    switch ($email_type) {
1095 1095
         case 'new_invoice':
1096 1096
         case 'cancelled_invoice':
1097 1097
         case 'failed_invoice':
1098 1098
             $recipient  = wpinv_get_admin_email();
1099 1099
         break;
1100 1100
         default:
1101
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1102
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1101
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1102
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1103 1103
         break;
1104 1104
     }
1105 1105
     
1106
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1106
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1107 1107
 }
1108 1108
 
1109
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1110
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1109
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1110
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1111 1111
     
1112
-    $subject    = wpinv_email_format_text( $subject );
1112
+    $subject    = wpinv_email_format_text($subject);
1113 1113
     
1114
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1114
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1115 1115
 }
1116 1116
 
1117
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1118
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1117
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1118
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1119 1119
     
1120
-    $email_heading = wpinv_email_format_text( $email_heading );
1120
+    $email_heading = wpinv_email_format_text($email_heading);
1121 1121
     
1122
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1122
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1123 1123
 }
1124 1124
 
1125
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1126
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1125
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1126
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1127 1127
     
1128
-    $content    = wpinv_email_format_text( $content );
1128
+    $content    = wpinv_email_format_text($content);
1129 1129
     
1130
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1130
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1131 1131
 }
1132 1132
 
1133
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1133
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1134 1134
     $from_name = wpinv_mail_get_from_address();
1135 1135
     $from_email = wpinv_mail_get_from_address();
1136 1136
     
1137
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1137
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1138 1138
     
1139
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1140
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1139
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1140
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1141 1141
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1142 1142
     
1143
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1143
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1144 1144
 }
1145 1145
 
1146
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1146
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1147 1147
     $attachments = array();
1148 1148
     
1149
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1149
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1150 1150
 }
1151 1151
 
1152 1152
 function wpinv_email_global_vars() {
@@ -1163,73 +1163,73 @@  discard block
 block discarded – undo
1163 1163
     $replace['sitename']    = $blogname;
1164 1164
     $replace['site-title']  = $blogname;
1165 1165
     
1166
-    return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) );
1166
+    return apply_filters('wpinv_email_global_vars', array($search, $replace));
1167 1167
 }
1168 1168
 
1169
-function wpinv_email_format_text( $content ) {
1169
+function wpinv_email_format_text($content) {
1170 1170
     global $wpinv_email_search, $wpinv_email_replace;
1171 1171
     
1172
-    if ( empty( $wpinv_email_search ) ) {
1172
+    if (empty($wpinv_email_search)) {
1173 1173
         $wpinv_email_search = array();
1174 1174
     }
1175 1175
     
1176
-    if ( empty( $wpinv_email_replace ) ) {
1176
+    if (empty($wpinv_email_replace)) {
1177 1177
         $wpinv_email_replace = array();
1178 1178
     }
1179 1179
     
1180
-    $wpinv_email_search     = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search );
1181
-    $wpinv_email_replace    = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace );
1180
+    $wpinv_email_search     = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search);
1181
+    $wpinv_email_replace    = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace);
1182 1182
     
1183 1183
     $global_vars    = wpinv_email_global_vars();
1184 1184
     
1185
-    $search         = array_merge( $global_vars[0], $wpinv_email_search );
1186
-    $replace        = array_merge( $global_vars[1], $wpinv_email_replace );
1185
+    $search         = array_merge($global_vars[0], $wpinv_email_search);
1186
+    $replace        = array_merge($global_vars[1], $wpinv_email_replace);
1187 1187
     
1188
-    if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) {
1188
+    if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) {
1189 1189
         return  $content;
1190 1190
     }
1191 1191
         
1192
-    return str_replace( $search, $replace, $content );
1192
+    return str_replace($search, $replace, $content);
1193 1193
 }
1194 1194
 
1195
-function wpinv_email_style_body( $content ) {
1195
+function wpinv_email_style_body($content) {
1196 1196
     // make sure we only inline CSS for html emails
1197
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1197
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1198 1198
         ob_start();
1199
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1200
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1199
+        wpinv_get_template('emails/wpinv-email-styles.php');
1200
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1201 1201
         
1202 1202
         // apply CSS styles inline for picky email clients
1203 1203
         try {
1204
-            $emogrifier = new Emogrifier( $content, $css );
1204
+            $emogrifier = new Emogrifier($content, $css);
1205 1205
             $content    = $emogrifier->emogrify();
1206
-        } catch ( Exception $e ) {
1207
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1206
+        } catch (Exception $e) {
1207
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1208 1208
         }
1209 1209
     }
1210 1210
     return $content;
1211 1211
 }
1212 1212
 
1213
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1214
-    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 ) );
1213
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1214
+    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));
1215 1215
 }
1216 1216
 
1217 1217
 /**
1218 1218
  * Get the email footer.
1219 1219
  */
1220
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1221
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1220
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1221
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1222 1222
 }
1223 1223
 
1224
-function wpinv_email_wrap_message( $message ) {
1224
+function wpinv_email_wrap_message($message) {
1225 1225
     // Buffer
1226 1226
     ob_start();
1227 1227
 
1228
-    do_action( 'wpinv_email_header' );
1228
+    do_action('wpinv_email_header');
1229 1229
 
1230
-    echo wpautop( wptexturize( $message ) );
1230
+    echo wpautop(wptexturize($message));
1231 1231
 
1232
-    do_action( 'wpinv_email_footer' );
1232
+    do_action('wpinv_email_footer');
1233 1233
 
1234 1234
     // Get contents
1235 1235
     $message = ob_get_clean();
@@ -1237,86 +1237,86 @@  discard block
 block discarded – undo
1237 1237
     return $message;
1238 1238
 }
1239 1239
 
1240
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1241
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1240
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1241
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1242 1242
 }
1243 1243
 
1244
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1245
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1244
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1245
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1246 1246
 }
1247 1247
 
1248
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1249
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1248
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1249
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1250 1250
 }
1251 1251
 
1252
-function wpinv_send_customer_invoice( $data = array() ) {
1253
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1252
+function wpinv_send_customer_invoice($data = array()) {
1253
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1254 1254
     
1255
-    if ( empty( $invoice_id ) ) {
1255
+    if (empty($invoice_id)) {
1256 1256
         return;
1257 1257
     }
1258 1258
 
1259
-    if ( !current_user_can( 'manage_options' ) ) {
1260
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1259
+    if (!current_user_can('manage_options')) {
1260
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1261 1261
     }
1262 1262
     
1263
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1263
+    $sent = wpinv_user_invoice_notification($invoice_id);
1264 1264
     
1265 1265
     $status = $sent ? 'email_sent' : 'email_fail';
1266 1266
     
1267
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1268
-    wp_redirect( $redirect );
1267
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1268
+    wp_redirect($redirect);
1269 1269
     exit;
1270 1270
 }
1271
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1271
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1272 1272
 
1273
-function wpinv_send_overdue_reminder( $data = array() ) {
1274
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1273
+function wpinv_send_overdue_reminder($data = array()) {
1274
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1275 1275
     
1276
-    if ( empty( $invoice_id ) ) {
1276
+    if (empty($invoice_id)) {
1277 1277
         return;
1278 1278
     }
1279 1279
 
1280
-    if ( !current_user_can( 'manage_options' ) ) {
1281
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1280
+    if (!current_user_can('manage_options')) {
1281
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1282 1282
     }
1283 1283
     
1284
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1284
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1285 1285
     
1286 1286
     $status = $sent ? 'email_sent' : 'email_fail';
1287 1287
     
1288
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1289
-    wp_redirect( $redirect );
1288
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1289
+    wp_redirect($redirect);
1290 1290
     exit;
1291 1291
 }
1292
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1292
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1293 1293
 
1294
-function wpinv_send_customer_note_email( $data ) {
1295
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1294
+function wpinv_send_customer_note_email($data) {
1295
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1296 1296
     
1297
-    if ( empty( $invoice_id ) ) {
1297
+    if (empty($invoice_id)) {
1298 1298
         return;
1299 1299
     }
1300 1300
     
1301
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1301
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1302 1302
 }
1303
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1303
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1304 1304
 
1305
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1306
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1307
-        $date_format = get_option( 'date_format' );
1308
-        $time_format = get_option( 'time_format' );
1305
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1306
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1307
+        $date_format = get_option('date_format');
1308
+        $time_format = get_option('time_format');
1309 1309
         ?>
1310 1310
         <div id="wpinv-email-notes">
1311
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1311
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1312 1312
             <ol class="wpinv-notes-lists">
1313 1313
         <?php
1314
-        foreach ( $invoice_notes as $note ) {
1315
-            $note_time = strtotime( $note->comment_date );
1314
+        foreach ($invoice_notes as $note) {
1315
+            $note_time = strtotime($note->comment_date);
1316 1316
             ?>
1317 1317
             <li class="comment wpinv-note">
1318
-            <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>
1319
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1318
+            <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>
1319
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1320 1320
             </li>
1321 1321
             <?php
1322 1322
         }
@@ -1325,21 +1325,21 @@  discard block
 block discarded – undo
1325 1325
         <?php
1326 1326
     }
1327 1327
 }
1328
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1328
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1329 1329
 
1330 1330
 function wpinv_email_payment_reminders() {    
1331 1331
     global $wpi_auto_reminder;
1332
-    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1332
+    if (!wpinv_get_option('email_overdue_active')) {
1333 1333
         return;
1334 1334
     }
1335 1335
     
1336
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1337
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1336
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1337
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : '';
1338 1338
         
1339
-        if ( empty( $reminder_days ) ) {
1339
+        if (empty($reminder_days)) {
1340 1340
             return;
1341 1341
         }
1342
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1342
+        $reminder_days = array_unique(array_map('absint', $reminder_days));
1343 1343
         
1344 1344
         $args = array(
1345 1345
             'post_type'     => 'wpi_invoice',
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
             'meta_query'    => array(
1350 1350
                 array(
1351 1351
                     'key'       =>  '_wpinv_due_date',
1352
-                    'value'     =>  array( '', 'none' ),
1352
+                    'value'     =>  array('', 'none'),
1353 1353
                     'compare'   =>  'NOT IN',
1354 1354
                 )
1355 1355
             ),
@@ -1358,64 +1358,64 @@  discard block
 block discarded – undo
1358 1358
             'order'         => 'ASC',
1359 1359
         );
1360 1360
         
1361
-        $invoices = get_posts( $args );
1361
+        $invoices = get_posts($args);
1362 1362
         
1363
-        if ( empty( $invoices ) ) {
1363
+        if (empty($invoices)) {
1364 1364
             return;
1365 1365
         }
1366 1366
         
1367
-        $date_to_send   = array();
1367
+        $date_to_send = array();
1368 1368
         
1369
-        foreach ( $invoices as $id ) {
1370
-            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1369
+        foreach ($invoices as $id) {
1370
+            $due_date = get_post_meta($id, '_wpinv_due_date', true);
1371 1371
             
1372
-            foreach ( $reminder_days as $key => $days ) {
1373
-                if ( $days !== '' ) {
1374
-                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1372
+            foreach ($reminder_days as $key => $days) {
1373
+                if ($days !== '') {
1374
+                    $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS));
1375 1375
                 }
1376 1376
             }
1377 1377
         }
1378 1378
 
1379
-        $today              = date_i18n( 'Y-m-d' );
1379
+        $today              = date_i18n('Y-m-d');
1380 1380
         $wpi_auto_reminder  = true;
1381 1381
 
1382
-        foreach ( $date_to_send as $id => $values ) {
1383
-            if ( in_array( $today, $values ) ) {
1384
-                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1382
+        foreach ($date_to_send as $id => $values) {
1383
+            if (in_array($today, $values)) {
1384
+                $sent = get_post_meta($id, '_wpinv_reminder_sent', true);
1385 1385
 
1386
-                if ( isset( $sent ) && !empty( $sent ) ) {
1387
-                    if ( !in_array( $today, $sent ) ) {
1388
-                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1386
+                if (isset($sent) && !empty($sent)) {
1387
+                    if (!in_array($today, $sent)) {
1388
+                        do_action('wpinv_send_payment_reminder_notification', $id);
1389 1389
                     }
1390 1390
                 } else {
1391
-                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1391
+                    do_action('wpinv_send_payment_reminder_notification', $id);
1392 1392
                 }
1393 1393
             }
1394 1394
         }
1395 1395
         
1396
-        $wpi_auto_reminder  = false;
1396
+        $wpi_auto_reminder = false;
1397 1397
     }
1398 1398
 }
1399 1399
 
1400
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1400
+function wpinv_send_payment_reminder_notification($invoice_id) {
1401 1401
     global $wpinv_email_search, $wpinv_email_replace;
1402 1402
     
1403 1403
     $email_type = 'overdue';
1404
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1404
+    if (!wpinv_email_is_enabled($email_type)) {
1405 1405
         return false;
1406 1406
     }
1407 1407
     
1408
-    $invoice    = wpinv_get_invoice( $invoice_id );
1409
-    if ( empty( $invoice ) ) {
1408
+    $invoice = wpinv_get_invoice($invoice_id);
1409
+    if (empty($invoice)) {
1410 1410
         return false;
1411 1411
     }
1412 1412
     
1413
-    if ( !$invoice->needs_payment() ) {
1413
+    if (!$invoice->needs_payment()) {
1414 1414
         return false;
1415 1415
     }
1416 1416
     
1417
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1418
-    if ( !is_email( $recipient ) ) {
1417
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1418
+    if (!is_email($recipient)) {
1419 1419
         return false;
1420 1420
     }
1421 1421
         
@@ -1431,60 +1431,60 @@  discard block
 block discarded – undo
1431 1431
     $replace                    = array();
1432 1432
     $replace['full_name']       = $invoice->get_user_full_name();
1433 1433
     $replace['invoice_number']  = $invoice->get_number();
1434
-    $replace['invoice_due_date']= $invoice->get_due_date( true );
1435
-    $replace['invoice_total']   = $invoice->get_total( true );
1436
-    $replace['invoice_link']    = $invoice->get_view_url( true );
1437
-    $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true );
1438
-    $replace['is_was']          = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' );
1434
+    $replace['invoice_due_date'] = $invoice->get_due_date(true);
1435
+    $replace['invoice_total']   = $invoice->get_total(true);
1436
+    $replace['invoice_link']    = $invoice->get_view_url(true);
1437
+    $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true);
1438
+    $replace['is_was']          = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing');
1439 1439
 
1440 1440
     $wpinv_email_search         = $search;
1441 1441
     $wpinv_email_replace        = $replace;
1442 1442
     
1443
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1444
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1445
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1446
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1443
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1444
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1445
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1446
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1447 1447
     
1448
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1448
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1449 1449
     
1450
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1450
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1451 1451
             'invoice'       => $invoice,
1452 1452
             'email_type'    => $email_type,
1453 1453
             'email_heading' => $email_heading,
1454 1454
             'sent_to_admin' => false,
1455 1455
             'plain_text'    => false,
1456 1456
             'message_body'  => $message_body
1457
-        ) );
1457
+        ));
1458 1458
         
1459
-    $content        = wpinv_email_format_text( $content );
1459
+    $content = wpinv_email_format_text($content);
1460 1460
 
1461
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1462
-    if ( $sent ) {
1463
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1461
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1462
+    if ($sent) {
1463
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1464 1464
     }
1465 1465
         
1466 1466
     return $sent;
1467 1467
 }
1468
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1468
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1469 1469
 
1470
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1470
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1471 1471
     global $wpi_auto_reminder;
1472 1472
     
1473
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1473
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1474 1474
     
1475
-    if ( empty( $sent ) ) {
1475
+    if (empty($sent)) {
1476 1476
         $sent = array();
1477 1477
     }
1478
-    $sent[] = date_i18n( 'Y-m-d' );
1478
+    $sent[] = date_i18n('Y-m-d');
1479 1479
     
1480
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1480
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1481 1481
     
1482
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1483
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1484
-        $invoice->add_note( $note, false, false, true );
1482
+    if ($wpi_auto_reminder) { // Auto reminder note.
1483
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1484
+        $invoice->add_note($note, false, false, true);
1485 1485
     } else { // Menual reminder note.
1486
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1487
-        $invoice->add_note( $note );
1486
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1487
+        $invoice->add_note($note);
1488 1488
     }
1489 1489
 }
1490
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1491 1490
\ No newline at end of file
1491
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1492 1492
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +154 added lines, -154 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,189 +83,189 @@  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' );
118
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
119
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
121
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
126
-        if ( !class_exists( 'Geodir_EUVat' ) ) {
127
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.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
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
119
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
121
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
126
+        if (!class_exists('Geodir_EUVat')) {
127
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
128 128
         }
129 129
         
130
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
131
-        if ( !empty( $gateways ) ) {
132
-            foreach ( $gateways as $gateway ) {
133
-                if ( $gateway == 'manual' ) {
130
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
131
+        if (!empty($gateways)) {
132
+            foreach ($gateways as $gateway) {
133
+                if ($gateway == 'manual') {
134 134
                     continue;
135 135
                 }
136 136
                 
137 137
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
138 138
                 
139
-                if ( file_exists( $gateway_file ) ) {
140
-                    require_once( $gateway_file );
139
+                if (file_exists($gateway_file)) {
140
+                    require_once($gateway_file);
141 141
                 }
142 142
             }
143 143
         }
144
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
145
-        
146
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
147
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
148
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
149
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
152
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
153
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
144
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
145
+        
146
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
147
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
148
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
149
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
152
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
153
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
155 155
             
156 156
         }
157 157
         
158 158
         // include css inliner
159
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
160
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
159
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
160
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
161 161
         }
162 162
         
163
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
163
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
164 164
     }
165 165
     
166 166
     public function init() {
167 167
     }
168 168
     
169 169
     public function admin_init() {
170
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
170
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
171 171
         }
172 172
         
173
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
173
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
174 174
     }
175 175
 
176 176
     public function activation_redirect() {
177 177
         // Bail if no activation redirect
178
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
178
+        if (!get_transient('_wpinv_activation_redirect')) {
179 179
             return;
180 180
         }
181 181
 
182 182
         // Delete the redirect transient
183
-        delete_transient( '_wpinv_activation_redirect' );
183
+        delete_transient('_wpinv_activation_redirect');
184 184
 
185 185
         // Bail if activating from network, or bulk
186
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
186
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
187 187
             return;
188 188
         }
189 189
 
190
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
190
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
191 191
         exit;
192 192
     }
193 193
     
194 194
     public function enqueue_scripts() {
195
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
195
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
196 196
         
197
-        wp_deregister_style( 'font-awesome' );
198
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
199
-        wp_enqueue_style( 'font-awesome' );
197
+        wp_deregister_style('font-awesome');
198
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
199
+        wp_enqueue_style('font-awesome');
200 200
         
201
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
202
-        wp_enqueue_style( 'wpinv_front_style' );
201
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
202
+        wp_enqueue_style('wpinv_front_style');
203 203
                
204 204
         // Register scripts
205
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
206
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
205
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
206
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
207 207
         
208 208
         $localize                         = array();
209
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
210
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
209
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
210
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
211 211
         $localize['currency_symbol']      = wpinv_currency_symbol();
212 212
         $localize['currency_pos']         = wpinv_currency_position();
213 213
         $localize['thousand_sep']         = wpinv_thousands_seperator();
214 214
         $localize['decimal_sep']          = wpinv_decimal_seperator();
215 215
         $localize['decimals']             = wpinv_decimals();
216 216
         
217
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
217
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
218 218
         
219
-        wp_enqueue_script( 'jquery-blockui' );
220
-        wp_enqueue_script( 'wpinv-front-script' );
221
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
219
+        wp_enqueue_script('jquery-blockui');
220
+        wp_enqueue_script('wpinv-front-script');
221
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
222 222
     }
223 223
     
224 224
     public function admin_enqueue_scripts() {
225 225
         global $post, $pagenow;
226 226
         
227 227
         $post_type  = wpinv_admin_post_type();
228
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
228
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
229 229
         
230
-        wp_deregister_style( 'font-awesome' );
231
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
232
-        wp_enqueue_style( 'font-awesome' );
230
+        wp_deregister_style('font-awesome');
231
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
232
+        wp_enqueue_style('font-awesome');
233 233
         
234
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
235
-        wp_enqueue_style( 'jquery-ui-css' );
234
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
235
+        wp_enqueue_style('jquery-ui-css');
236 236
         
237
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
238
-        wp_enqueue_style( 'jquery-chosen' );
237
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
238
+        wp_enqueue_style('jquery-chosen');
239 239
 
240
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
241
-        wp_enqueue_script( 'jquery-chosen' );
240
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
241
+        wp_enqueue_script('jquery-chosen');
242 242
         
243
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
244
-        wp_enqueue_style( 'wpinv_meta_box_style' );
243
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
244
+        wp_enqueue_style('wpinv_meta_box_style');
245 245
         
246
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
247
-        wp_enqueue_style( 'wpinv_admin_style' );
246
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
247
+        wp_enqueue_style('wpinv_admin_style');
248 248
         
249
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
250
-            wp_enqueue_script( 'jquery-ui-datepicker' );
249
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
250
+            wp_enqueue_script('jquery-ui-datepicker');
251 251
         }
252 252
 
253
-        wp_enqueue_style( 'wp-color-picker' );
254
-        wp_enqueue_script( 'wp-color-picker' );
253
+        wp_enqueue_style('wp-color-picker');
254
+        wp_enqueue_script('wp-color-picker');
255 255
         
256
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
256
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
257 257
         
258
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
259
-        wp_enqueue_script( 'wpinv-admin-script' );
258
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION);
259
+        wp_enqueue_script('wpinv-admin-script');
260 260
         
261 261
         $localize                               = array();
262
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
263
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
264
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
265
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
266
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
267
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
268
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
262
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
263
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
264
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
265
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
266
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
267
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
268
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
269 269
         $localize['tax']                        = wpinv_tax_amount();
270 270
         $localize['discount']                   = wpinv_discount_amount();
271 271
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -273,55 +273,55 @@  discard block
 block discarded – undo
273 273
         $localize['thousand_sep']               = wpinv_thousands_seperator();
274 274
         $localize['decimal_sep']                = wpinv_decimal_seperator();
275 275
         $localize['decimals']                   = wpinv_decimals();
276
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
277
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
278
-        $localize['status_pending']             = wpinv_status_nicename( 'pending' );
279
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
280
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
281
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
282
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
283
-        $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' );
284
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
285
-        $localize['hasGD']                      = wpinv_gd_active();;
276
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
277
+        $localize['status_publish']             = wpinv_status_nicename('publish');
278
+        $localize['status_pending']             = wpinv_status_nicename('pending');
279
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
280
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
281
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
282
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
283
+        $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');
284
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
285
+        $localize['hasGD']                      = wpinv_gd_active(); ;
286 286
         $localize['hasPM']                      = wpinv_pm_active();
287
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
288
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
289
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
290
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
287
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
288
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
289
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
290
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
291 291
         
292
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
292
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
293 293
     }
294 294
     
295
-    public function admin_body_class( $classes ) {
295
+    public function admin_body_class($classes) {
296 296
         global $pagenow;
297 297
         
298
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
298
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
299 299
 
300 300
         $add_class = false;
301
-        if ( $pagenow == 'admin.php' && $page ) {
302
-            $add_class = strpos( $page, 'wpinv-' );
301
+        if ($pagenow == 'admin.php' && $page) {
302
+            $add_class = strpos($page, 'wpinv-');
303 303
         }
304 304
         
305 305
         $settings_class = array();
306
-        if ( $page == 'wpinv-settings' ) {
307
-            if ( !empty( $_REQUEST['tab'] ) ) {
308
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
306
+        if ($page == 'wpinv-settings') {
307
+            if (!empty($_REQUEST['tab'])) {
308
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
309 309
             }
310 310
             
311
-            if ( !empty( $_REQUEST['section'] ) ) {
312
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
311
+            if (!empty($_REQUEST['section'])) {
312
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
313 313
             }
314 314
             
315
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
315
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
316 316
         }
317 317
         
318
-        if ( !empty( $settings_class ) ) {
319
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
318
+        if (!empty($settings_class)) {
319
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
320 320
         }
321 321
         
322 322
         $post_type = wpinv_admin_post_type();
323 323
         
324
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
324
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
325 325
             return $classes .= ' wpinv';
326 326
         } else {
327 327
             return $classes;
@@ -333,26 +333,26 @@  discard block
 block discarded – undo
333 333
     public function admin_print_scripts_edit_php() {
334 334
         $post_type = wpinv_admin_post_type();
335 335
         
336
-        if ( $post_type == 'wpi_item' ) {
337
-            wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
336
+        if ($post_type == 'wpi_item') {
337
+            wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true);
338 338
         }
339 339
     }
340 340
     
341 341
     public function wpinv_actions() {
342
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
343
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
342
+        if (isset($_REQUEST['wpi_action'])) {
343
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
344 344
         }
345 345
     }
346 346
     
347
-    public function pre_get_posts( $wp_query ) {
348
-        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() ) {
349
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
347
+    public function pre_get_posts($wp_query) {
348
+        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()) {
349
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
350 350
         }
351 351
         
352 352
         return $wp_query;
353 353
     }
354 354
     
355 355
     public function bp_invoicing_init() {
356
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
356
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
357 357
     }
358 358
 }
359 359
\ No newline at end of file
Please login to merge, or discard this patch.