@@ -7,65 +7,65 @@ discard block |
||
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_bulk_actions( $actions ) { |
|
15 | - if ( isset( $actions['edit'] ) ) { |
|
16 | - unset( $actions['edit'] ); |
|
14 | +function wpinv_bulk_actions($actions) { |
|
15 | + if (isset($actions['edit'])) { |
|
16 | + unset($actions['edit']); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | return $actions; |
20 | 20 | } |
21 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
22 | -add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
21 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
22 | +add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions'); |
|
23 | 23 | |
24 | -function wpinv_admin_post_id( $id = 0 ) { |
|
24 | +function wpinv_admin_post_id($id = 0) { |
|
25 | 25 | global $post; |
26 | 26 | |
27 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
28 | - return (int)$id; |
|
29 | - } else if ( get_the_ID() ) { |
|
27 | + if (isset($id) && !empty($id)) { |
|
28 | + return (int) $id; |
|
29 | + } else if (get_the_ID()) { |
|
30 | 30 | return (int) get_the_ID(); |
31 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
31 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
32 | 32 | return (int) $post->ID; |
33 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
33 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
34 | 34 | return (int) $_GET['post']; |
35 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
35 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
36 | 36 | return (int) $_GET['id']; |
37 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
37 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
38 | 38 | return (int) $_POST['id']; |
39 | 39 | } |
40 | 40 | |
41 | 41 | return null; |
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_admin_post_type( $id = 0 ) { |
|
45 | - if ( !$id ) { |
|
44 | +function wpinv_admin_post_type($id = 0) { |
|
45 | + if (!$id) { |
|
46 | 46 | $id = wpinv_admin_post_id(); |
47 | 47 | } |
48 | 48 | |
49 | - $type = get_post_type( $id ); |
|
49 | + $type = get_post_type($id); |
|
50 | 50 | |
51 | - if ( !$type ) { |
|
52 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
51 | + if (!$type) { |
|
52 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
53 | 53 | } |
54 | 54 | |
55 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
55 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_admin_messages() { |
59 | - settings_errors( 'wpinv-notices' ); |
|
59 | + settings_errors('wpinv-notices'); |
|
60 | 60 | } |
61 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
61 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
62 | 62 | |
63 | -add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
64 | -function wpinv_show_test_payment_gateway_notice(){ |
|
65 | - add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
63 | +add_action('admin_init', 'wpinv_show_test_payment_gateway_notice'); |
|
64 | +function wpinv_show_test_payment_gateway_notice() { |
|
65 | + add_action('admin_notices', 'wpinv_test_payment_gateway_messages'); |
|
66 | 66 | } |
67 | 67 | |
68 | -function wpinv_test_payment_gateway_messages(){ |
|
68 | +function wpinv_test_payment_gateway_messages() { |
|
69 | 69 | $gateways = wpinv_get_enabled_payment_gateways(); |
70 | 70 | $name = array(); $test_gateways = ''; |
71 | 71 | if ($gateways) { |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | } |
77 | 77 | $test_gateways = implode(', ', $name); |
78 | 78 | } |
79 | - if(isset($test_gateways) && !empty($test_gateways) && wpinv_current_user_can_manage_invoicing()){ |
|
79 | + if (isset($test_gateways) && !empty($test_gateways) && wpinv_current_user_can_manage_invoicing()) { |
|
80 | 80 | $link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
81 | - $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link ); |
|
81 | + $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link); |
|
82 | 82 | ?> |
83 | 83 | <div class="notice notice-warning is-dismissible"> |
84 | 84 | <p><?php echo $notice; ?></p> |
@@ -95,29 +95,29 @@ discard block |
||
95 | 95 | global $wpdb; |
96 | 96 | |
97 | 97 | // Only do this on our settings page. |
98 | - if ( empty( $_GET[ 'page' ] ) || 'wpinv-settings' !== $_GET[ 'page' ] ) { |
|
98 | + if (empty($_GET['page']) || 'wpinv-settings' !== $_GET['page']) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Check tables. |
103 | - $tables = array( |
|
103 | + $tables = array( |
|
104 | 104 | "{$wpdb->prefix}wpinv_subscriptions", |
105 | 105 | "{$wpdb->prefix}getpaid_invoices", |
106 | 106 | "{$wpdb->prefix}getpaid_invoice_items", |
107 | 107 | ); |
108 | 108 | |
109 | - foreach ( $tables as $table ) { |
|
110 | - if ( $table != $wpdb->get_var( "SHOW TABLES LIKE '$table'" ) ) { |
|
109 | + foreach ($tables as $table) { |
|
110 | + if ($table != $wpdb->get_var("SHOW TABLES LIKE '$table'")) { |
|
111 | 111 | |
112 | - $url = esc_url( |
|
112 | + $url = esc_url( |
|
113 | 113 | wp_nonce_url( |
114 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
114 | + add_query_arg('getpaid-admin-action', 'create_missing_tables'), |
|
115 | 115 | 'getpaid-nonce', |
116 | 116 | 'getpaid-nonce' |
117 | 117 | ) |
118 | 118 | ); |
119 | - $message = __( 'Some GetPaid database tables are missing. To use GetPaid without any issues, click on the button below to create the missing tables.', 'invoicing' ); |
|
120 | - $message2 = __( 'Create Tables', 'invoicing' ); |
|
119 | + $message = __('Some GetPaid database tables are missing. To use GetPaid without any issues, click on the button below to create the missing tables.', 'invoicing'); |
|
120 | + $message2 = __('Create Tables', 'invoicing'); |
|
121 | 121 | echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
122 | 122 | break; |
123 | 123 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | } |
128 | -add_action( 'admin_notices', 'wpinv_check_for_missing_tables' ); |
|
128 | +add_action('admin_notices', 'wpinv_check_for_missing_tables'); |
|
129 | 129 | |
130 | 130 | add_action('admin_init', 'wpinv_admin_search_by_invoice'); |
131 | 131 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | function wpinv_admin_search_by_invoice() { |
136 | 136 | global $typenow; |
137 | 137 | |
138 | - if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
138 | + if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') { |
|
139 | 139 | add_filter('posts_search', 'wpinv_posts_search_example_type', 10, 2); |
140 | 140 | } |
141 | 141 | } |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | global $wpdb; |
151 | 151 | |
152 | 152 | if ($query->is_main_query() && !empty($query->query['s'])) { |
153 | - $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
154 | - if ( ! empty( $search ) ) { |
|
155 | - $search = preg_replace( '/^ AND /', '', $search ); |
|
153 | + $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )"; |
|
154 | + if (!empty($search)) { |
|
155 | + $search = preg_replace('/^ AND /', '', $search); |
|
156 | 156 | $search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
157 | 157 | } else { |
158 | 158 | $search = " AND ( {$conditions_str} )"; |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | /** |
166 | 166 | * Resets invoice counts. |
167 | 167 | */ |
168 | -function wpinv_reset_invoice_count(){ |
|
169 | - if ( ! empty( $_GET['reset_invoice_count'] ) && isset( $_GET['_nonce'] ) && wp_verify_nonce( $_GET['_nonce'], 'reset_invoice_count' ) ) { |
|
168 | +function wpinv_reset_invoice_count() { |
|
169 | + if (!empty($_GET['reset_invoice_count']) && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
170 | 170 | wpinv_update_option('invoice_sequence_start', 1); |
171 | 171 | delete_option('wpinv_last_invoice_number'); |
172 | - getpaid_admin()->show_success( __( 'Invoice number sequence reset successfully.', 'invoicing' ) ); |
|
173 | - $url = remove_query_arg( array('reset_invoice_count', '_nonce') ); |
|
172 | + getpaid_admin()->show_success(__('Invoice number sequence reset successfully.', 'invoicing')); |
|
173 | + $url = remove_query_arg(array('reset_invoice_count', '_nonce')); |
|
174 | 174 | wp_redirect($url); |
175 | 175 | exit(); |
176 | 176 | } |
177 | 177 | } |
178 | -add_action( 'admin_init', 'wpinv_reset_invoice_count' ); |
|
178 | +add_action('admin_init', 'wpinv_reset_invoice_count'); |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Displays line items on the invoice edit page. |
@@ -184,29 +184,29 @@ discard block |
||
184 | 184 | * @param array $columns |
185 | 185 | * @return string |
186 | 186 | */ |
187 | -function wpinv_admin_get_line_items( $invoice, $columns ) { |
|
187 | +function wpinv_admin_get_line_items($invoice, $columns) { |
|
188 | 188 | |
189 | 189 | ob_start(); |
190 | 190 | |
191 | - do_action( 'getpaid_admin_before_line_items', $invoice ); |
|
191 | + do_action('getpaid_admin_before_line_items', $invoice); |
|
192 | 192 | |
193 | 193 | $count = 0; |
194 | - foreach ( $invoice->get_items() as $item ) { |
|
194 | + foreach ($invoice->get_items() as $item) { |
|
195 | 195 | |
196 | - $item_price = wpinv_price( $item->get_price(), $invoice->get_currency() ); |
|
196 | + $item_price = wpinv_price($item->get_price(), $invoice->get_currency()); |
|
197 | 197 | $quantity = (int) $item->get_quantity(); |
198 | - $item_subtotal = wpinv_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
199 | - $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
198 | + $item_subtotal = wpinv_price($item->get_sub_total(), $invoice->get_currency()); |
|
199 | + $summary = apply_filters('getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice); |
|
200 | 200 | $item_tax = $item->item_tax; |
201 | - $tax_rate = wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2, true ) . '%';; |
|
202 | - $tax_rate = empty( $tax_rate ) ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
|
201 | + $tax_rate = wpinv_round_amount(getpaid_get_invoice_tax_rate($invoice, $item), 2, true) . '%'; ; |
|
202 | + $tax_rate = empty($tax_rate) ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
|
203 | 203 | $line_item_tax = $item_tax . $tax_rate; |
204 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . esc_attr( $item->get_id() ) . '">'; |
|
204 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . esc_attr($item->get_id()) . '">'; |
|
205 | 205 | $line_item .= '<td class="id">' . (int) $item->get_id() . '</td>'; |
206 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item->get_id() ) . '" target="_blank">' . $item->get_name() . '</a>'; |
|
206 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item->get_id()) . '" target="_blank">' . $item->get_name() . '</a>'; |
|
207 | 207 | |
208 | - if ( $summary !== '' ) { |
|
209 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
208 | + if ($summary !== '') { |
|
209 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | $line_item .= '</td>'; |
@@ -214,23 +214,23 @@ discard block |
||
214 | 214 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
215 | 215 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
216 | 216 | |
217 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
217 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
218 | 218 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
219 | 219 | } |
220 | 220 | |
221 | 221 | $line_item .= '<td class="action">'; |
222 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
222 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
223 | 223 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
224 | 224 | } |
225 | 225 | $line_item .= '</td>'; |
226 | 226 | $line_item .= '</tr>'; |
227 | 227 | |
228 | - echo apply_filters( 'getpaid_admin_line_item', $line_item, $item, $invoice ); |
|
228 | + echo apply_filters('getpaid_admin_line_item', $line_item, $item, $invoice); |
|
229 | 229 | |
230 | 230 | $count++; |
231 | 231 | } |
232 | 232 | |
233 | - do_action( 'getpaid_admin_after_line_items', $invoice ); |
|
233 | + do_action('getpaid_admin_after_line_items', $invoice); |
|
234 | 234 | |
235 | 235 | return ob_get_clean(); |
236 | 236 | } |