Passed
Pull Request — master (#126)
by Kiran
03:53
created
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -7,256 +7,256 @@  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
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Created Date', 'invoicing' ),
21
-        'payment_date'      => __( 'Payment Date', 'invoicing' ),
22
-        'status'            => __( 'Status', 'invoicing' ),
23
-        'ID'                => __( 'ID', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Created Date', 'invoicing'),
21
+        'payment_date'      => __('Payment Date', 'invoicing'),
22
+        'status'            => __('Status', 'invoicing'),
23
+        'ID'                => __('ID', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
39
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
40 40
 
41
-function wpinv_sortable_columns( $columns ) {
41
+function wpinv_sortable_columns($columns) {
42 42
     $columns = array(
43
-        'ID'            => array( 'ID', true ),
44
-        'number'        => array( 'number', false ),
45
-        'amount'        => array( 'amount', false ),
46
-        'invoice_date'  => array( 'date', false ),
47
-        'payment_date'  => array( 'payment_date', true ),
48
-        'customer'      => array( 'customer', false ),
49
-        'status'        => array( 'status', false ),
43
+        'ID'            => array('ID', true),
44
+        'number'        => array('number', false),
45
+        'amount'        => array('amount', false),
46
+        'invoice_date'  => array('date', false),
47
+        'payment_date'  => array('payment_date', true),
48
+        'customer'      => array('customer', false),
49
+        'status'        => array('status', false),
50 50
     );
51 51
     
52
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
52
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
53 53
 }
54
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
54
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
55 55
 
56
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
56
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
58 58
     global $post, $wpi_invoice;
59 59
     
60
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
61
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
60
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
61
+        $wpi_invoice = new WPInv_Invoice($post->ID);
62 62
     }
63 63
 
64 64
     $value = NULL;
65 65
     
66
-    switch ( $column_name ) {
66
+    switch ($column_name) {
67 67
         case 'email' :
68
-            $value   = $wpi_invoice->get_email();
68
+            $value = $wpi_invoice->get_email();
69 69
             break;
70 70
         case 'customer' :
71 71
             $customer_name = $wpi_invoice->get_user_full_name();
72
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
73
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
74
-            if ( $email = $wpi_invoice->get_email() ) {
72
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
73
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
74
+            if ($email = $wpi_invoice->get_email()) {
75 75
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
76 76
             }
77 77
             break;
78 78
         case 'amount' :
79
-            echo $wpi_invoice->get_total( true );
79
+            echo $wpi_invoice->get_total(true);
80 80
             break;
81 81
         case 'invoice_date' :
82
-            $date_format = get_option( 'date_format' );
83
-            $time_format = get_option( 'time_format' );
84
-            $date_time_format = $date_format . ' '. $time_format;
82
+            $date_format = get_option('date_format');
83
+            $time_format = get_option('time_format');
84
+            $date_time_format = $date_format . ' ' . $time_format;
85 85
             
86
-            $t_time = get_the_time( $date_time_format );
86
+            $t_time = get_the_time($date_time_format);
87 87
             $m_time = $post->post_date;
88
-            $h_time = mysql2date( $date_format, $m_time );
88
+            $h_time = mysql2date($date_format, $m_time);
89 89
             
90
-            $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
90
+            $value = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
91 91
             break;
92 92
         case 'payment_date' :
93
-            if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) {
94
-                $date_format = get_option( 'date_format' );
95
-                $time_format = get_option( 'time_format' );
96
-                $date_time_format = $date_format . ' '. $time_format;
93
+            if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) {
94
+                $date_format = get_option('date_format');
95
+                $time_format = get_option('time_format');
96
+                $date_time_format = $date_format . ' ' . $time_format;
97 97
                 
98
-                $t_time = get_the_time( $date_time_format );
98
+                $t_time = get_the_time($date_time_format);
99 99
                 $m_time = $date_completed;
100
-                $h_time = mysql2date( $date_format, $m_time );
100
+                $h_time = mysql2date($date_format, $m_time);
101 101
                 
102
-                $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
102
+                $value = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
103 103
             } else {
104 104
                 $value = '-';
105 105
             }
106 106
             break;
107 107
         case 'status' :
108
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
109
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() ) && $gateway_title = $wpi_invoice->get_gateway_title() ) {
110
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
108
+            $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
109
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded()) && $gateway_title = $wpi_invoice->get_gateway_title()) {
110
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
111 111
             }
112 112
             break;
113 113
         case 'number' :
114
-            $edit_link = get_edit_post_link( $post->ID );
115
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
114
+            $edit_link = get_edit_post_link($post->ID);
115
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
116 116
             break;
117 117
         case 'wpi_actions' :
118 118
             $value = '';
119
-            if ( !empty( $post->post_name ) ) {
120
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
119
+            if (!empty($post->post_name)) {
120
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
121 121
             }
122 122
             
123
-            if ( $email = $wpi_invoice->get_email() ) {
124
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
123
+            if ($email = $wpi_invoice->get_email()) {
124
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
125 125
             }
126 126
             
127 127
             break;
128 128
         default:
129
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
129
+            $value = isset($post->$column_name) ? $post->$column_name : '';
130 130
             break;
131 131
 
132 132
     }
133
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
133
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
134 134
     
135
-    if ( $value !== NULL ) {
135
+    if ($value !== NULL) {
136 136
         echo $value;
137 137
     }
138 138
 }
139 139
 
140
-function wpinv_admin_post_id( $id = 0 ) {
140
+function wpinv_admin_post_id($id = 0) {
141 141
     global $post;
142 142
 
143
-    if ( isset( $id ) && ! empty( $id ) ) {
143
+    if (isset($id) && !empty($id)) {
144 144
         return (int)$id;
145
-    } else if ( get_the_ID() ) {
146
-        return (int) get_the_ID();
147
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
148
-        return (int) $post->ID;
149
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
150
-        return (int) $_GET['post'];
151
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
152
-        return (int) $_GET['id'];
153
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
154
-        return (int) $_POST['id'];
145
+    } else if (get_the_ID()) {
146
+        return (int)get_the_ID();
147
+    } else if (isset($post->ID) && !empty($post->ID)) {
148
+        return (int)$post->ID;
149
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
150
+        return (int)$_GET['post'];
151
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
152
+        return (int)$_GET['id'];
153
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
154
+        return (int)$_POST['id'];
155 155
     } 
156 156
 
157 157
     return null;
158 158
 }
159 159
     
160
-function wpinv_admin_post_type( $id = 0 ) {
161
-    if ( !$id ) {
160
+function wpinv_admin_post_type($id = 0) {
161
+    if (!$id) {
162 162
         $id = wpinv_admin_post_id();
163 163
     }
164 164
     
165
-    $type = get_post_type( $id );
165
+    $type = get_post_type($id);
166 166
     
167
-    if ( !$type ) {
168
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
167
+    if (!$type) {
168
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
169 169
     }
170 170
     
171
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
171
+    return apply_filters('wpinv_admin_post_type', $type, $id);
172 172
 }
173 173
 
174 174
 function wpinv_admin_messages() {
175 175
 	global $wpinv_options, $pagenow, $post;
176 176
 
177
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
178
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
177
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
178
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
179 179
 	}
180 180
 
181
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
182
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
181
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
182
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
183 183
 	}
184 184
 
185
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
186
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
185
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
186
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
187 187
 	}
188 188
 
189
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
190
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
189
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
190
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
191 191
 	}
192 192
 
193
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
194
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
193
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
194
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
195 195
 	}
196 196
 
197
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
198
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
197
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
198
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
199 199
 	}
200 200
 
201
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
202
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
201
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
202
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
203 203
     }
204 204
     
205
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
206
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
205
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
206
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
207 207
     }
208 208
 
209
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
210
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
209
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
210
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
211 211
     }
212 212
 
213
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
214
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
213
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
214
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
215 215
 	}
216 216
 
217
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
218
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
217
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
218
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
219 219
 	}
220 220
 
221
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
222
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
221
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
222
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
223 223
 	}
224 224
     
225
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
226
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
225
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
226
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
227 227
 
228
-		if ( !empty( $message ) ) {
229
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
228
+		if (!empty($message)) {
229
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
230 230
 		}
231 231
 	}
232 232
 
233
-	settings_errors( 'wpinv-notices' );
233
+	settings_errors('wpinv-notices');
234 234
 }
235
-add_action( 'admin_notices', 'wpinv_admin_messages' );
235
+add_action('admin_notices', 'wpinv_admin_messages');
236 236
 
237
-function wpinv_items_columns( $existing_columns ) {
237
+function wpinv_items_columns($existing_columns) {
238 238
     global $wpinv_euvat;
239 239
     
240 240
     $columns                = array();
241 241
     $columns['cb']          = $existing_columns['cb'];
242
-    $columns['title']       = __( 'Title', 'invoicing' );
243
-    $columns['price']       = __( 'Price', 'invoicing' );
244
-    if ( $wpinv_euvat->allow_vat_rules() ) {
245
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
242
+    $columns['title']       = __('Title', 'invoicing');
243
+    $columns['price']       = __('Price', 'invoicing');
244
+    if ($wpinv_euvat->allow_vat_rules()) {
245
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
246 246
     }
247
-    if ( $wpinv_euvat->allow_vat_classes() ) {
248
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
247
+    if ($wpinv_euvat->allow_vat_classes()) {
248
+        $columns['vat_class']   = __('VAT class', 'invoicing');
249 249
     }
250
-    $columns['type']        = __( 'Type', 'invoicing' );
251
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
252
-    $columns['date']        = __( 'Date', 'invoicing' );
253
-    $columns['id']          = __( 'ID', 'invoicing' );
250
+    $columns['type']        = __('Type', 'invoicing');
251
+    $columns['recurring']   = __('Recurring', 'invoicing');
252
+    $columns['date']        = __('Date', 'invoicing');
253
+    $columns['id']          = __('ID', 'invoicing');
254 254
 
255
-    return apply_filters( 'wpinv_items_columns', $columns );
255
+    return apply_filters('wpinv_items_columns', $columns);
256 256
 }
257
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
257
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
258 258
 
259
-function wpinv_items_sortable_columns( $columns ) {
259
+function wpinv_items_sortable_columns($columns) {
260 260
     $columns['price']       = 'price';
261 261
     $columns['vat_rule']    = 'vat_rule';
262 262
     $columns['vat_class']   = 'vat_class';
@@ -266,151 +266,151 @@  discard block
 block discarded – undo
266 266
 
267 267
     return $columns;
268 268
 }
269
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
269
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
270 270
 
271
-function wpinv_items_table_custom_column( $column ) {
271
+function wpinv_items_table_custom_column($column) {
272 272
     global $wpinv_euvat, $post, $wpi_item;
273 273
     
274
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
275
-        $wpi_item = new WPInv_Item( $post->ID );
274
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
275
+        $wpi_item = new WPInv_Item($post->ID);
276 276
     }
277 277
 
278
-    switch ( $column ) {
278
+    switch ($column) {
279 279
         case 'price' :
280
-            echo wpinv_item_price( $post->ID );
280
+            echo wpinv_item_price($post->ID);
281 281
         break;
282 282
         case 'vat_rule' :
283
-            echo $wpinv_euvat->item_rule_label( $post->ID );
283
+            echo $wpinv_euvat->item_rule_label($post->ID);
284 284
         break;
285 285
         case 'vat_class' :
286
-            echo $wpinv_euvat->item_class_label( $post->ID );
286
+            echo $wpinv_euvat->item_class_label($post->ID);
287 287
         break;
288 288
         case 'type' :
289
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
289
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
290 290
         break;
291 291
         case 'recurring' :
292
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
292
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
293 293
         break;
294 294
         case 'id' :
295 295
            echo $post->ID;
296 296
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
297
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
298
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
299
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
297
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
298
+                    if ($wpinv_euvat->allow_vat_rules()) {
299
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
300 300
                     }
301
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
302
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
301
+                    if ($wpinv_euvat->allow_vat_classes()) {
302
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
303 303
                     }
304
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
304
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
305 305
                 </div>';
306 306
         break;
307 307
     }
308 308
     
309
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
309
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
310 310
 }
311
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
311
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
312 312
 
313 313
 function wpinv_add_items_filters() {
314 314
     global $wpinv_euvat, $typenow;
315 315
 
316 316
     // Checks if the current post type is 'item'
317
-    if ( $typenow == 'wpi_item') {
318
-        if ( $wpinv_euvat->allow_vat_rules() ) {
319
-            echo wpinv_html_select( array(
320
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
317
+    if ($typenow == 'wpi_item') {
318
+        if ($wpinv_euvat->allow_vat_rules()) {
319
+            echo wpinv_html_select(array(
320
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
321 321
                     'name'             => 'vat_rule',
322 322
                     'id'               => 'vat_rule',
323
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
323
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
324 324
                     'show_option_all'  => false,
325 325
                     'show_option_none' => false,
326 326
                     'class'            => 'gdmbx2-text-medium',
327
-                ) );
327
+                ));
328 328
         }
329 329
         
330
-        if ( $wpinv_euvat->allow_vat_classes() ) {
331
-            echo wpinv_html_select( array(
332
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
330
+        if ($wpinv_euvat->allow_vat_classes()) {
331
+            echo wpinv_html_select(array(
332
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
333 333
                     'name'             => 'vat_class',
334 334
                     'id'               => 'vat_class',
335
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
335
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
336 336
                     'show_option_all'  => false,
337 337
                     'show_option_none' => false,
338 338
                     'class'            => 'gdmbx2-text-medium',
339
-                ) );
339
+                ));
340 340
         }
341 341
             
342
-        echo wpinv_html_select( array(
343
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
342
+        echo wpinv_html_select(array(
343
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
344 344
                 'name'             => 'type',
345 345
                 'id'               => 'type',
346
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
346
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
347 347
                 'show_option_all'  => false,
348 348
                 'show_option_none' => false,
349 349
                 'class'            => 'gdmbx2-text-medium',
350
-            ) );
350
+            ));
351 351
 
352
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
352
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
353 353
             echo '<input type="hidden" name="all_posts" value="1" />';
354 354
         }
355 355
     }
356 356
 }
357
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
357
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
358 358
 
359
-function wpinv_send_invoice_after_save( $invoice ) {
360
-    if ( empty( $_POST['wpi_save_send'] ) ) {
359
+function wpinv_send_invoice_after_save($invoice) {
360
+    if (empty($_POST['wpi_save_send'])) {
361 361
         return;
362 362
     }
363 363
     
364
-    if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) {
365
-        wpinv_user_invoice_notification( $invoice->ID );
364
+    if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) {
365
+        wpinv_user_invoice_notification($invoice->ID);
366 366
     }
367 367
 }
368
-add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 );
368
+add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1);
369 369
 
370
-function wpinv_send_register_new_user( $data, $postarr ) {
371
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
372
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
373
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
370
+function wpinv_send_register_new_user($data, $postarr) {
371
+    if (current_user_can('manage_options') && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
372
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
373
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
374 374
         
375
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
376
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
377
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
378
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
379
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
380
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
375
+        if ($is_new_user && $email && !email_exists($email)) {
376
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
377
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
378
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
379
+            $user_nicename = $display_name ? trim($display_name) : $email;
380
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
381 381
             
382
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
383
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
382
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
383
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
384 384
                 $new_user_login = strstr($email, '@', true);
385
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
386
-                    $user_login = sanitize_user($new_user_login, true );
385
+                if (validate_username($user_login) && username_exists($user_login)) {
386
+                    $user_login = sanitize_user($new_user_login, true);
387 387
                 }
388
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
389
-                    $user_append_text = rand(10,1000);
390
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
388
+                if (validate_username($user_login) && username_exists($user_login)) {
389
+                    $user_append_text = rand(10, 1000);
390
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
391 391
                 }
392 392
                 
393
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
393
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
394 394
                     $user_login = $email;
395 395
                 }
396 396
             }
397 397
             
398 398
             $userdata = array(
399 399
                 'user_login' => $user_login,
400
-                'user_pass' => wp_generate_password( 12, false ),
401
-                'user_email' => sanitize_text_field( $email ),
400
+                'user_pass' => wp_generate_password(12, false),
401
+                'user_email' => sanitize_text_field($email),
402 402
                 'first_name' => $first_name,
403 403
                 'last_name' => $last_name,
404
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
404
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
405 405
                 'nickname' => $display_name,
406 406
                 'display_name' => $display_name,
407 407
             );
408 408
 
409
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
409
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
410 410
             
411
-            $new_user_id = wp_insert_user( $userdata );
411
+            $new_user_id = wp_insert_user($userdata);
412 412
             
413
-            if ( !is_wp_error( $new_user_id ) ) {
413
+            if (!is_wp_error($new_user_id)) {
414 414
                 $data['post_author'] = $new_user_id;
415 415
                 $_POST['post_author'] = $new_user_id;
416 416
                 $_POST['post_author_override'] = $new_user_id;
@@ -431,27 +431,27 @@  discard block
 block discarded – undo
431 431
                 
432 432
                 $meta = array();
433 433
                 ///$meta['_wpinv_user_id'] = $new_user_id;
434
-                foreach ( $meta_fields as $field ) {
435
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
434
+                foreach ($meta_fields as $field) {
435
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
436 436
                 }
437 437
                 
438
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
438
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
439 439
 
440 440
                 // Update user meta.
441
-                foreach ( $meta as $key => $value ) {
442
-                    update_user_meta( $new_user_id, $key, $value );
441
+                foreach ($meta as $key => $value) {
442
+                    update_user_meta($new_user_id, $key, $value);
443 443
                 }
444 444
                 
445
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
445
+                if (function_exists('wp_send_new_user_notifications')) {
446 446
                     // Send email notifications related to the creation of new user.
447
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
447
+                    wp_send_new_user_notifications($new_user_id, 'user');
448 448
                 }
449 449
             } else {
450
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
450
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
451 451
             }
452 452
         }
453 453
     }
454 454
     
455 455
     return $data;
456 456
 }
457
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
458 457
\ No newline at end of file
458
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
459 459
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -1,72 +1,72 @@  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
-add_action( 'admin_menu', 'wpinv_add_options_link', 10 );
7
+add_action('admin_menu', 'wpinv_add_options_link', 10);
8 8
 function wpinv_add_options_link() {
9 9
     global $menu;
10 10
 
11
-    if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) {
11
+    if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) {
12 12
         return;
13 13
     }
14 14
 
15
-    $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' );
15
+    $capability = apply_filters('invoicing_capability', 'manage_invoicing');
16 16
 
17
-    if ( current_user_can( 'manage_options' ) ) {
18
-        $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );
17
+    if (current_user_can('manage_options')) {
18
+        $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv');
19 19
     }
20 20
 
21
-    $wpi_invoice = get_post_type_object( 'wpi_invoice' );
21
+    $wpi_invoice = get_post_type_object('wpi_invoice');
22 22
 
23
-    add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );
23
+    add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460');
24 24
 
25
-    $wpi_settings_page   = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', 'wpinv_options_page' );
25
+    $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', 'wpinv_options_page');
26 26
 }
27 27
 
28
-add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 );
28
+add_action('admin_menu', 'wpinv_remove_admin_submenus', 999);
29 29
 function wpinv_remove_admin_submenus() {
30
-    remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
30
+    remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
31 31
 }
32 32
 
33
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
34
-function wpinv_discount_columns( $existing_columns ) {
33
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
34
+function wpinv_discount_columns($existing_columns) {
35 35
     $columns                = array();
36 36
     $columns['cb']          = $existing_columns['cb'];
37
-    $columns['name']        = __( 'Name', 'invoicing' );
38
-    $columns['code']        = __( 'Code', 'invoicing' );
39
-    $columns['amount']      = __( 'Amount', 'invoicing' );
40
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
41
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
42
-    $columns['status']      = __( 'Status', 'invoicing' );
37
+    $columns['name']        = __('Name', 'invoicing');
38
+    $columns['code']        = __('Code', 'invoicing');
39
+    $columns['amount']      = __('Amount', 'invoicing');
40
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
41
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
42
+    $columns['status']      = __('Status', 'invoicing');
43 43
 
44 44
     return $columns;
45 45
 }
46 46
 
47
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
48
-function wpinv_discount_custom_column( $column ) {
47
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
48
+function wpinv_discount_custom_column($column) {
49 49
     global $post;
50 50
     
51 51
     $discount = $post;
52 52
 
53
-    switch ( $column ) {
53
+    switch ($column) {
54 54
         case 'name' :
55
-            echo get_the_title( $discount->ID );
55
+            echo get_the_title($discount->ID);
56 56
         break;
57 57
         case 'code' :
58
-            echo wpinv_get_discount_code( $discount->ID );
58
+            echo wpinv_get_discount_code($discount->ID);
59 59
         break;
60 60
         case 'amount' :
61
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
61
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
62 62
         break;
63 63
         case 'usage_limit' :
64
-            echo wpinv_get_discount_uses( $discount->ID );
64
+            echo wpinv_get_discount_uses($discount->ID);
65 65
         break;
66 66
         case 'usage' :
67
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
68
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
69
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
67
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
68
+            if (wpinv_get_discount_max_uses($discount->ID)) {
69
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
70 70
             } else {
71 71
                 $usage .= ' &infin;';
72 72
             }
@@ -74,162 +74,162 @@  discard block
 block discarded – undo
74 74
             echo $usage;
75 75
         break;
76 76
         case 'expiry_date' :
77
-            if ( wpinv_get_discount_expiration( $discount->ID ) ) {
78
-                $expiration = date_i18n( get_option( 'date_format' ), strtotime( wpinv_get_discount_expiration( $discount->ID ) ) );
77
+            if (wpinv_get_discount_expiration($discount->ID)) {
78
+                $expiration = date_i18n(get_option('date_format'), strtotime(wpinv_get_discount_expiration($discount->ID)));
79 79
             } else {
80
-                $expiration = __( 'Never', 'invoicing' );
80
+                $expiration = __('Never', 'invoicing');
81 81
             }
82 82
                 
83 83
             echo $expiration;
84 84
         break;
85 85
         case 'description' :
86
-            echo wp_kses_post( $post->post_excerpt );
86
+            echo wp_kses_post($post->post_excerpt);
87 87
         break;
88 88
         case 'status' :
89
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
89
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
90 90
             
91
-            echo wpinv_discount_status( $status );
91
+            echo wpinv_discount_status($status);
92 92
         break;
93 93
     }
94 94
 }
95 95
 
96
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
97
-function wpinv_post_row_actions( $actions, $post ) {
98
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
96
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
97
+function wpinv_post_row_actions($actions, $post) {
98
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
99 99
     
100
-    if ( $post_type == 'wpi_invoice' ) {
100
+    if ($post_type == 'wpi_invoice') {
101 101
         $actions = array();
102 102
     }
103 103
     
104
-    if ( $post_type == 'wpi_discount' ) {
105
-        $actions = wpinv_discount_row_actions( $post, $actions );
104
+    if ($post_type == 'wpi_discount') {
105
+        $actions = wpinv_discount_row_actions($post, $actions);
106 106
     }
107 107
     
108 108
     return $actions;
109 109
 }
110 110
 
111
-function wpinv_discount_row_actions( $discount, $row_actions ) {
112
-    $row_actions  = array();
113
-    $edit_link = get_edit_post_link( $discount->ID );
114
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
111
+function wpinv_discount_row_actions($discount, $row_actions) {
112
+    $row_actions = array();
113
+    $edit_link = get_edit_post_link($discount->ID);
114
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
115 115
 
116
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
117
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
118
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
119
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
116
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
117
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
118
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
119
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
120 120
     }
121 121
 
122
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
123
-        if ( isset( $row_actions['delete'] ) ) {
124
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
122
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
123
+        if (isset($row_actions['delete'])) {
124
+            unset($row_actions['delete']); // Don't delete used discounts.
125 125
         }
126 126
     } else {
127
-        $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';
127
+        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>';
128 128
     }
129 129
     
130 130
 
131
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
131
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
132 132
 
133 133
     return $row_actions;
134 134
 }
135 135
 
136
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
137
-function wpinv_table_primary_column( $default, $screen_id ) {
138
-    if ( 'edit-wpi_invoice' === $screen_id ) {
136
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
137
+function wpinv_table_primary_column($default, $screen_id) {
138
+    if ('edit-wpi_invoice' === $screen_id) {
139 139
         return 'name';
140 140
     }
141 141
     
142 142
     return $default;
143 143
 }
144 144
 
145
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
146
-    if ( !$display ) {
145
+function wpinv_discount_bulk_actions($actions, $display = false) {    
146
+    if (!$display) {
147 147
         return array();
148 148
     }
149 149
     
150 150
     $actions = array(
151
-        'activate'   => __( 'Activate', 'invoicing' ),
152
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
153
-        'delete'     => __( 'Delete', 'invoicing' ),
151
+        'activate'   => __('Activate', 'invoicing'),
152
+        'deactivate' => __('Deactivate', 'invoicing'),
153
+        'delete'     => __('Delete', 'invoicing'),
154 154
     );
155 155
     $two = '';
156 156
     $which = 'top';
157 157
     echo '</div><div class="alignleft actions bulkactions">';
158
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
159
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
160
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
158
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
159
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
160
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
161 161
 
162
-    foreach ( $actions as $name => $title ) {
162
+    foreach ($actions as $name => $title) {
163 163
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
164 164
 
165 165
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
166 166
     }
167 167
     echo "</select>";
168 168
 
169
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
169
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
170 170
     
171 171
     echo '</div><div class="alignleft actions">';
172 172
 }
173
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
173
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
174 174
 
175
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
176
-    if ( $post_type == 'wpi_discount' ) {
175
+function wpinv_disable_months_dropdown($disable, $post_type) {
176
+    if ($post_type == 'wpi_discount') {
177 177
         $disable = true;
178 178
     }
179 179
     
180 180
     return $disable;
181 181
 }
182
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
182
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
183 183
 
184 184
 function wpinv_restrict_manage_posts() {
185 185
     global $typenow;
186 186
 
187
-    if( 'wpi_discount' == $typenow ) {
187
+    if ('wpi_discount' == $typenow) {
188 188
         wpinv_discount_filters();
189 189
     }
190 190
 }
191
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
191
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
192 192
 
193 193
 function wpinv_discount_filters() {
194
-    echo wpinv_discount_bulk_actions( array(), true );
194
+    echo wpinv_discount_bulk_actions(array(), true);
195 195
     
196 196
     ?>
197 197
     <select name="discount_type" id="dropdown_wpinv_discount_type">
198
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
198
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
199 199
         <?php
200 200
             $types = wpinv_get_discount_types();
201 201
 
202
-            foreach ( $types as $name => $type ) {
203
-                echo '<option value="' . esc_attr( $name ) . '"';
202
+            foreach ($types as $name => $type) {
203
+                echo '<option value="' . esc_attr($name) . '"';
204 204
 
205
-                if ( isset( $_GET['discount_type'] ) )
206
-                    selected( $name, $_GET['discount_type'] );
205
+                if (isset($_GET['discount_type']))
206
+                    selected($name, $_GET['discount_type']);
207 207
 
208
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
208
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
209 209
             }
210 210
         ?>
211 211
     </select>
212 212
     <?php
213 213
 }
214 214
 
215
-function wpinv_request( $vars ) {
215
+function wpinv_request($vars) {
216 216
     global $typenow, $wp_query, $wp_post_statuses;
217 217
 
218
-    if ( 'wpi_invoice' === $typenow ) {
219
-        if ( !isset( $vars['post_status'] ) ) {
218
+    if ('wpi_invoice' === $typenow) {
219
+        if (!isset($vars['post_status'])) {
220 220
             $post_statuses = wpinv_get_invoice_statuses();
221 221
 
222
-            foreach ( $post_statuses as $status => $value ) {
223
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
224
-                    unset( $post_statuses[ $status ] );
222
+            foreach ($post_statuses as $status => $value) {
223
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
224
+                    unset($post_statuses[$status]);
225 225
                 }
226 226
             }
227 227
 
228
-            $vars['post_status'] = array_keys( $post_statuses );
228
+            $vars['post_status'] = array_keys($post_statuses);
229 229
         }
230 230
         
231
-        if ( isset( $vars['orderby'] ) ) {
232
-            if ( 'amount' == $vars['orderby'] ) {
231
+        if (isset($vars['orderby'])) {
232
+            if ('amount' == $vars['orderby']) {
233 233
                 $vars = array_merge(
234 234
                     $vars,
235 235
                     array(
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
                         'orderby'  => 'meta_value_num'
238 238
                     )
239 239
                 );
240
-            } else if ( 'customer' == $vars['orderby'] ) {
240
+            } else if ('customer' == $vars['orderby']) {
241 241
                 $vars = array_merge(
242 242
                     $vars,
243 243
                     array(
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
                         'orderby'  => 'meta_value'
246 246
                     )
247 247
                 );
248
-            } else if ( 'number' == $vars['orderby'] ) {
248
+            } else if ('number' == $vars['orderby']) {
249 249
                 $vars = array_merge(
250 250
                     $vars,
251 251
                     array(
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
                         'orderby'  => 'meta_value'
254 254
                     )
255 255
                 );
256
-            } else if ( 'payment_date' == $vars['orderby'] ) {
256
+            } else if ('payment_date' == $vars['orderby']) {
257 257
                 $vars = array_merge(
258 258
                     $vars,
259 259
                     array(
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
                 );
264 264
             }
265 265
         }
266
-    } else if ( 'wpi_item' == $typenow ) {
266
+    } else if ('wpi_item' == $typenow) {
267 267
         // Check if 'orderby' is set to "price"
268
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
268
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
269 269
             $vars = array_merge(
270 270
                 $vars,
271 271
                 array(
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
         }
277 277
 
278 278
         // Check if "orderby" is set to "vat_rule"
279
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
279
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
280 280
             $vars = array_merge(
281 281
                 $vars,
282 282
                 array(
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         }
288 288
 
289 289
         // Check if "orderby" is set to "vat_class"
290
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
290
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
291 291
             $vars = array_merge(
292 292
                 $vars,
293 293
                 array(
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         }
299 299
         
300 300
         // Check if "orderby" is set to "type"
301
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
301
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
302 302
             $vars = array_merge(
303 303
                 $vars,
304 304
                 array(
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         }
310 310
         
311 311
         // Check if "orderby" is set to "recurring"
312
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
312
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
313 313
             $vars = array_merge(
314 314
                 $vars,
315 315
                 array(
@@ -319,120 +319,120 @@  discard block
 block discarded – undo
319 319
             );
320 320
         }
321 321
 
322
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
322
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
323 323
         // Filter vat rule type
324
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
324
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
325 325
             $meta_query[] = array(
326 326
                     'key'   => '_wpinv_vat_rule',
327
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
327
+                    'value' => sanitize_text_field($_GET['vat_rule']),
328 328
                     'compare' => '='
329 329
                 );
330 330
         }
331 331
         
332 332
         // Filter vat class
333
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
333
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
334 334
             $meta_query[] = array(
335 335
                     'key'   => '_wpinv_vat_class',
336
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
336
+                    'value' => sanitize_text_field($_GET['vat_class']),
337 337
                     'compare' => '='
338 338
                 );
339 339
         }
340 340
         
341 341
         // Filter item type
342
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
342
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
343 343
             $meta_query[] = array(
344 344
                     'key'   => '_wpinv_type',
345
-                    'value' => sanitize_text_field( $_GET['type'] ),
345
+                    'value' => sanitize_text_field($_GET['type']),
346 346
                     'compare' => '='
347 347
                 );
348 348
         }
349 349
         
350
-        if ( !empty( $meta_query ) ) {
350
+        if (!empty($meta_query)) {
351 351
             $vars['meta_query'] = $meta_query;
352 352
         }
353
-    } else if ( 'wpi_discount' == $typenow ) {
354
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
353
+    } else if ('wpi_discount' == $typenow) {
354
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
355 355
         // Filter vat rule type
356
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
356
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
357 357
             $meta_query[] = array(
358 358
                     'key'   => '_wpi_discount_type',
359
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
359
+                    'value' => sanitize_text_field($_GET['discount_type']),
360 360
                     'compare' => '='
361 361
                 );
362 362
         }
363 363
         
364
-        if ( !empty( $meta_query ) ) {
364
+        if (!empty($meta_query)) {
365 365
             $vars['meta_query'] = $meta_query;
366 366
         }
367 367
     }
368 368
 
369 369
     return $vars;
370 370
 }
371
-add_filter( 'request', 'wpinv_request' );
371
+add_filter('request', 'wpinv_request');
372 372
 
373 373
 function wpinv_options_page() {
374
-    $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
374
+    $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
375 375
     
376
-    if ( $page !== 'wpinv-settings' ) {
376
+    if ($page !== 'wpinv-settings') {
377 377
         return;
378 378
     }
379 379
     
380 380
     $settings_tabs = wpinv_get_settings_tabs();
381 381
     $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
382
-    $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
383
-    $sections      = wpinv_get_settings_tab_sections( $active_tab );
382
+    $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
383
+    $sections      = wpinv_get_settings_tab_sections($active_tab);
384 384
     $key           = 'main';
385 385
 
386
-    if ( is_array( $sections ) ) {
387
-        $key = key( $sections );
386
+    if (is_array($sections)) {
387
+        $key = key($sections);
388 388
     }
389 389
 
390
-    $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
391
-    $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
390
+    $registered_sections = wpinv_get_settings_tab_sections($active_tab);
391
+    $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
392 392
     ob_start();
393 393
     ?>
394 394
     <div class="wrap">
395 395
         <h1 class="nav-tab-wrapper">
396 396
             <?php
397
-            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
398
-                $tab_url = add_query_arg( array(
397
+            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
398
+                $tab_url = add_query_arg(array(
399 399
                     'settings-updated' => false,
400 400
                     'tab' => $tab_id,
401
-                ) );
401
+                ));
402 402
 
403 403
                 // Remove the section from the tabs so we always end up at the main section
404
-                $tab_url = remove_query_arg( 'section', $tab_url );
405
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
404
+                $tab_url = remove_query_arg('section', $tab_url);
405
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
406 406
 
407 407
                 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
408 408
 
409
-                echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
410
-                    echo esc_html( $tab_name );
409
+                echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
410
+                    echo esc_html($tab_name);
411 411
                 echo '</a>';
412 412
             }
413 413
             ?>
414 414
         </h1>
415 415
         <?php
416
-        $number_of_sections = count( $sections );
416
+        $number_of_sections = count($sections);
417 417
         $number = 0;
418
-        if ( $number_of_sections > 1 ) {
418
+        if ($number_of_sections > 1) {
419 419
             echo '<div><ul class="subsubsub">';
420
-            foreach( $sections as $section_id => $section_name ) {
420
+            foreach ($sections as $section_id => $section_name) {
421 421
                 echo '<li>';
422 422
                 $number++;
423
-                $tab_url = add_query_arg( array(
423
+                $tab_url = add_query_arg(array(
424 424
                     'settings-updated' => false,
425 425
                     'tab' => $active_tab,
426 426
                     'section' => $section_id
427
-                ) );
428
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
427
+                ));
428
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
429 429
                 $class = '';
430
-                if ( $section == $section_id ) {
430
+                if ($section == $section_id) {
431 431
                     $class = 'current';
432 432
                 }
433
-                echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
433
+                echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
434 434
 
435
-                if ( $number != $number_of_sections ) {
435
+                if ($number != $number_of_sections) {
436 436
                     echo ' | ';
437 437
                 }
438 438
                 echo '</li>';
@@ -444,19 +444,19 @@  discard block
 block discarded – undo
444 444
             <form method="post" action="options.php">
445 445
                 <table class="form-table">
446 446
                 <?php
447
-                settings_fields( 'wpinv_settings' );
447
+                settings_fields('wpinv_settings');
448 448
 
449
-                if ( 'main' === $section ) {
450
-                    do_action( 'wpinv_settings_tab_top', $active_tab );
449
+                if ('main' === $section) {
450
+                    do_action('wpinv_settings_tab_top', $active_tab);
451 451
                 }
452 452
 
453
-                do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section );
454
-                do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section );
455
-                do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section  );
453
+                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section);
454
+                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section);
455
+                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section);
456 456
 
457 457
                 // For backwards compatibility
458
-                if ( 'main' === $section ) {
459
-                    do_action( 'wpinv_settings_tab_bottom', $active_tab );
458
+                if ('main' === $section) {
459
+                    do_action('wpinv_settings_tab_bottom', $active_tab);
460 460
                 }
461 461
                 ?>
462 462
                 </table>
@@ -469,53 +469,53 @@  discard block
 block discarded – undo
469 469
     echo $content;
470 470
 }
471 471
 
472
-function wpinv_item_type_class( $classes, $class, $post_id ) {
472
+function wpinv_item_type_class($classes, $class, $post_id) {
473 473
     global $pagenow, $typenow;
474 474
 
475
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
476
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
477
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
475
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
476
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
477
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
478 478
         }
479 479
         
480
-        if ( !wpinv_item_is_editable( $post_id ) ) {
480
+        if (!wpinv_item_is_editable($post_id)) {
481 481
             $classes[] = 'wpi-editable-n';
482 482
         }
483 483
     }
484 484
     return $classes;
485 485
 }
486
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
486
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
487 487
 
488 488
 function wpinv_check_quick_edit() {
489 489
     global $pagenow, $current_screen, $wpinv_item_screen;
490 490
 
491
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
492
-        if ( empty( $wpinv_item_screen ) ) {
493
-            if ( $current_screen->post_type == 'wpi_item' ) {
491
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
492
+        if (empty($wpinv_item_screen)) {
493
+            if ($current_screen->post_type == 'wpi_item') {
494 494
                 $wpinv_item_screen = 'y';
495 495
             } else {
496 496
                 $wpinv_item_screen = 'n';
497 497
             }
498 498
         }
499 499
 
500
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
501
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
502
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
500
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
501
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
502
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
503 503
         }
504 504
     }
505 505
 }
506
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
506
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
507 507
 
508
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
509
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
510
-        unset( $actions['inline hide-if-no-js'] );
508
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
509
+    if (isset($actions['inline hide-if-no-js'])) {
510
+        unset($actions['inline hide-if-no-js']);
511 511
     }
512 512
     
513
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
514
-        if ( isset( $actions['trash'] ) ) {
515
-            unset( $actions['trash'] );
513
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
514
+        if (isset($actions['trash'])) {
515
+            unset($actions['trash']);
516 516
         }
517
-        if ( isset( $actions['delete'] ) ) {
518
-            unset( $actions['delete'] );
517
+        if (isset($actions['delete'])) {
518
+            unset($actions['delete']);
519 519
         }
520 520
     }
521 521
 
@@ -532,19 +532,19 @@  discard block
 block discarded – undo
532 532
  * @param int $post_parent (default: 0) Parent for the new page
533 533
  * @return int page ID
534 534
  */
535
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
535
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
536 536
     global $wpdb;
537 537
 
538
-    $option_value = wpinv_get_option( $option );
538
+    $option_value = wpinv_get_option($option);
539 539
 
540
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
541
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
540
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
541
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
542 542
             // Valid page is already in place
543 543
             return $page_object->ID;
544 544
         }
545 545
     }
546 546
 
547
-    if(!empty($post_parent)){
547
+    if (!empty($post_parent)) {
548 548
         $page = get_page_by_path($post_parent);
549 549
         if ($page) {
550 550
             $post_parent = $page->ID;
@@ -553,40 +553,40 @@  discard block
 block discarded – undo
553 553
         }
554 554
     }
555 555
 
556
-    if ( strlen( $page_content ) > 0 ) {
556
+    if (strlen($page_content) > 0) {
557 557
         // Search for an existing page with the specified page content (typically a shortcode)
558
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
558
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
559 559
     } else {
560 560
         // Search for an existing page with the specified page slug
561
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
561
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
562 562
     }
563 563
 
564
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
564
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
565 565
 
566
-    if ( $valid_page_found ) {
567
-        if ( $option ) {
568
-            wpinv_update_option( $option, $valid_page_found );
566
+    if ($valid_page_found) {
567
+        if ($option) {
568
+            wpinv_update_option($option, $valid_page_found);
569 569
         }
570 570
         return $valid_page_found;
571 571
     }
572 572
 
573 573
     // Search for a matching valid trashed page
574
-    if ( strlen( $page_content ) > 0 ) {
574
+    if (strlen($page_content) > 0) {
575 575
         // Search for an existing page with the specified page content (typically a shortcode)
576
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
576
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
577 577
     } else {
578 578
         // Search for an existing page with the specified page slug
579
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
579
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
580 580
     }
581 581
 
582
-    if ( $trashed_page_found ) {
582
+    if ($trashed_page_found) {
583 583
         $page_id   = $trashed_page_found;
584 584
         $page_data = array(
585 585
             'ID'             => $page_id,
586 586
             'post_status'    => 'publish',
587 587
             'post_parent'    => $post_parent,
588 588
         );
589
-        wp_update_post( $page_data );
589
+        wp_update_post($page_data);
590 590
     } else {
591 591
         $page_data = array(
592 592
             'post_status'    => 'publish',
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
             'post_parent'    => $post_parent,
599 599
             'comment_status' => 'closed',
600 600
         );
601
-        $page_id = wp_insert_post( $page_data );
601
+        $page_id = wp_insert_post($page_data);
602 602
     }
603 603
 
604
-    if ( $option ) {
605
-        wpinv_update_option( $option, (int)$page_id );
604
+    if ($option) {
605
+        wpinv_update_option($option, (int)$page_id);
606 606
     }
607 607
 
608 608
     return $page_id;
Please login to merge, or discard this patch.