@@ -1,66 +1,66 @@ discard block |
||
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_filter( 'manage_wpi_payment_form_posts_columns', 'wpinv_payment_form_columns' ); |
|
8 | -function wpinv_payment_form_columns( $existing_columns ) { |
|
7 | +add_filter('manage_wpi_payment_form_posts_columns', 'wpinv_payment_form_columns'); |
|
8 | +function wpinv_payment_form_columns($existing_columns) { |
|
9 | 9 | $date = $existing_columns['date']; |
10 | - unset( $existing_columns['date'] ); |
|
11 | - $existing_columns['shortcode'] = __( 'Shortcode', 'invoicing' ); |
|
10 | + unset($existing_columns['date']); |
|
11 | + $existing_columns['shortcode'] = __('Shortcode', 'invoicing'); |
|
12 | 12 | $existing_columns['date'] = $date; |
13 | 13 | return $existing_columns; |
14 | 14 | } |
15 | 15 | |
16 | -add_action( 'manage_wpi_payment_form_posts_custom_column', 'wpinv_payment_form_custom_column' ); |
|
17 | -function wpinv_payment_form_custom_column( $column ) { |
|
16 | +add_action('manage_wpi_payment_form_posts_custom_column', 'wpinv_payment_form_custom_column'); |
|
17 | +function wpinv_payment_form_custom_column($column) { |
|
18 | 18 | global $post; |
19 | 19 | |
20 | - if( 'shortcode' == $column ) { |
|
21 | - WPInv_Meta_Box_Payment_Form::output_shortcode( $post ); |
|
20 | + if ('shortcode' == $column) { |
|
21 | + WPInv_Meta_Box_Payment_Form::output_shortcode($post); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | } |
25 | 25 | |
26 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
27 | -function wpinv_discount_columns( $existing_columns ) { |
|
26 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
27 | +function wpinv_discount_columns($existing_columns) { |
|
28 | 28 | $columns = array(); |
29 | 29 | $columns['cb'] = $existing_columns['cb']; |
30 | - $columns['name'] = __( 'Name', 'invoicing' ); |
|
31 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
32 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
33 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
34 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
35 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
36 | - $columns['status'] = __( 'Status', 'invoicing' ); |
|
30 | + $columns['name'] = __('Name', 'invoicing'); |
|
31 | + $columns['code'] = __('Code', 'invoicing'); |
|
32 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
33 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
34 | + $columns['start_date'] = __('Start Date', 'invoicing'); |
|
35 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
36 | + $columns['status'] = __('Status', 'invoicing'); |
|
37 | 37 | |
38 | 38 | return $columns; |
39 | 39 | } |
40 | 40 | |
41 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
42 | -function wpinv_discount_custom_column( $column ) { |
|
41 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
42 | +function wpinv_discount_custom_column($column) { |
|
43 | 43 | global $post; |
44 | 44 | |
45 | 45 | $discount = $post; |
46 | 46 | |
47 | - switch ( $column ) { |
|
47 | + switch ($column) { |
|
48 | 48 | case 'name' : |
49 | - echo get_the_title( $discount->ID ); |
|
49 | + echo get_the_title($discount->ID); |
|
50 | 50 | break; |
51 | 51 | case 'code' : |
52 | - echo wpinv_get_discount_code( $discount->ID ); |
|
52 | + echo wpinv_get_discount_code($discount->ID); |
|
53 | 53 | break; |
54 | 54 | case 'amount' : |
55 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
55 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
56 | 56 | break; |
57 | 57 | case 'usage_limit' : |
58 | - echo wpinv_get_discount_uses( $discount->ID ); |
|
58 | + echo wpinv_get_discount_uses($discount->ID); |
|
59 | 59 | break; |
60 | 60 | case 'usage' : |
61 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / '; |
|
62 | - if ( wpinv_get_discount_max_uses( $discount->ID ) ) { |
|
63 | - $usage .= wpinv_get_discount_max_uses( $discount->ID ); |
|
61 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / '; |
|
62 | + if (wpinv_get_discount_max_uses($discount->ID)) { |
|
63 | + $usage .= wpinv_get_discount_max_uses($discount->ID); |
|
64 | 64 | } else { |
65 | 65 | $usage .= ' ∞'; |
66 | 66 | } |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | echo $usage; |
69 | 69 | break; |
70 | 70 | case 'start_date' : |
71 | - if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) { |
|
72 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) ); |
|
71 | + if ($start_date = wpinv_get_discount_start_date($discount->ID)) { |
|
72 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date)); |
|
73 | 73 | } else { |
74 | 74 | $value = '-'; |
75 | 75 | } |
@@ -77,163 +77,163 @@ discard block |
||
77 | 77 | echo $value; |
78 | 78 | break; |
79 | 79 | case 'expiry_date' : |
80 | - if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) { |
|
81 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) ); |
|
80 | + if ($expiration = wpinv_get_discount_expiration($discount->ID)) { |
|
81 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration)); |
|
82 | 82 | } else { |
83 | - $value = __( 'Never', 'invoicing' ); |
|
83 | + $value = __('Never', 'invoicing'); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | echo $value; |
87 | 87 | break; |
88 | 88 | break; |
89 | 89 | case 'description' : |
90 | - echo wp_kses_post( $post->post_excerpt ); |
|
90 | + echo wp_kses_post($post->post_excerpt); |
|
91 | 91 | break; |
92 | 92 | case 'status' : |
93 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status; |
|
93 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status; |
|
94 | 94 | |
95 | - echo wpinv_discount_status( $status ); |
|
95 | + echo wpinv_discount_status($status); |
|
96 | 96 | break; |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
101 | -function wpinv_post_row_actions( $actions, $post ) { |
|
102 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
100 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
101 | +function wpinv_post_row_actions($actions, $post) { |
|
102 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
103 | 103 | |
104 | - if ( $post_type == 'wpi_invoice' ) { |
|
104 | + if ($post_type == 'wpi_invoice') { |
|
105 | 105 | $actions = array(); |
106 | 106 | } |
107 | 107 | |
108 | - if ( $post_type == 'wpi_discount' ) { |
|
109 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
108 | + if ($post_type == 'wpi_discount') { |
|
109 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | return $actions; |
113 | 113 | } |
114 | 114 | |
115 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
116 | - $row_actions = array(); |
|
117 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
118 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
115 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
116 | + $row_actions = array(); |
|
117 | + $edit_link = get_edit_post_link($discount->ID); |
|
118 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
119 | 119 | |
120 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
121 | - $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>'; |
|
122 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
123 | - $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 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
121 | + $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>'; |
|
122 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
123 | + $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>'; |
|
124 | 124 | } |
125 | 125 | |
126 | - if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { |
|
127 | - if ( isset( $row_actions['delete'] ) ) { |
|
128 | - unset( $row_actions['delete'] ); // Don't delete used discounts. |
|
126 | + if (wpinv_get_discount_uses($discount->ID) > 0) { |
|
127 | + if (isset($row_actions['delete'])) { |
|
128 | + unset($row_actions['delete']); // Don't delete used discounts. |
|
129 | 129 | } |
130 | 130 | } else { |
131 | - $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>'; |
|
131 | + $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>'; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
135 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
135 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
136 | 136 | |
137 | 137 | return $row_actions; |
138 | 138 | } |
139 | 139 | |
140 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
141 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
142 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
140 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
141 | +function wpinv_table_primary_column($default, $screen_id) { |
|
142 | + if ('edit-wpi_invoice' === $screen_id) { |
|
143 | 143 | return 'name'; |
144 | 144 | } |
145 | 145 | |
146 | 146 | return $default; |
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
150 | - if ( !$display ) { |
|
149 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
150 | + if (!$display) { |
|
151 | 151 | return array(); |
152 | 152 | } |
153 | 153 | |
154 | 154 | $actions = array( |
155 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
156 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
157 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
155 | + 'activate' => __('Activate', 'invoicing'), |
|
156 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
157 | + 'delete' => __('Delete', 'invoicing'), |
|
158 | 158 | ); |
159 | 159 | $two = ''; |
160 | 160 | $which = 'top'; |
161 | 161 | echo '</div><div class="alignleft actions bulkactions">'; |
162 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
163 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
164 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
162 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
163 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
164 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
165 | 165 | |
166 | - foreach ( $actions as $name => $title ) { |
|
166 | + foreach ($actions as $name => $title) { |
|
167 | 167 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
168 | 168 | |
169 | 169 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
170 | 170 | } |
171 | 171 | echo "</select>"; |
172 | 172 | |
173 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
173 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
174 | 174 | |
175 | 175 | echo '</div><div class="alignleft actions">'; |
176 | 176 | } |
177 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
177 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
178 | 178 | |
179 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
180 | - if ( $post_type == 'wpi_discount' ) { |
|
179 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
180 | + if ($post_type == 'wpi_discount') { |
|
181 | 181 | $disable = true; |
182 | 182 | } |
183 | 183 | |
184 | 184 | return $disable; |
185 | 185 | } |
186 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
186 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
187 | 187 | |
188 | 188 | function wpinv_restrict_manage_posts() { |
189 | 189 | global $typenow; |
190 | 190 | |
191 | - if( 'wpi_discount' == $typenow ) { |
|
191 | + if ('wpi_discount' == $typenow) { |
|
192 | 192 | wpinv_discount_filters(); |
193 | 193 | } |
194 | 194 | } |
195 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
195 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
196 | 196 | |
197 | 197 | function wpinv_discount_filters() { |
198 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
198 | + echo wpinv_discount_bulk_actions(array(), true); |
|
199 | 199 | |
200 | 200 | ?> |
201 | 201 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
202 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
202 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
203 | 203 | <?php |
204 | 204 | $types = wpinv_get_discount_types(); |
205 | 205 | |
206 | - foreach ( $types as $name => $type ) { |
|
207 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
206 | + foreach ($types as $name => $type) { |
|
207 | + echo '<option value="' . esc_attr($name) . '"'; |
|
208 | 208 | |
209 | - if ( isset( $_GET['discount_type'] ) ) |
|
210 | - selected( $name, $_GET['discount_type'] ); |
|
209 | + if (isset($_GET['discount_type'])) |
|
210 | + selected($name, $_GET['discount_type']); |
|
211 | 211 | |
212 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
212 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
213 | 213 | } |
214 | 214 | ?> |
215 | 215 | </select> |
216 | 216 | <?php |
217 | 217 | } |
218 | 218 | |
219 | -function wpinv_request( $vars ) { |
|
219 | +function wpinv_request($vars) { |
|
220 | 220 | global $typenow, $wp_query, $wp_post_statuses; |
221 | 221 | |
222 | - if ( 'wpi_invoice' === $typenow ) { |
|
223 | - if ( !isset( $vars['post_status'] ) ) { |
|
222 | + if ('wpi_invoice' === $typenow) { |
|
223 | + if (!isset($vars['post_status'])) { |
|
224 | 224 | $post_statuses = wpinv_get_invoice_statuses(); |
225 | 225 | |
226 | - foreach ( $post_statuses as $status => $value ) { |
|
227 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
228 | - unset( $post_statuses[ $status ] ); |
|
226 | + foreach ($post_statuses as $status => $value) { |
|
227 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
228 | + unset($post_statuses[$status]); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
232 | + $vars['post_status'] = array_keys($post_statuses); |
|
233 | 233 | } |
234 | 234 | |
235 | - if ( isset( $vars['orderby'] ) ) { |
|
236 | - if ( 'amount' == $vars['orderby'] ) { |
|
235 | + if (isset($vars['orderby'])) { |
|
236 | + if ('amount' == $vars['orderby']) { |
|
237 | 237 | $vars = array_merge( |
238 | 238 | $vars, |
239 | 239 | array( |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | 'orderby' => 'meta_value_num' |
242 | 242 | ) |
243 | 243 | ); |
244 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
244 | + } else if ('customer' == $vars['orderby']) { |
|
245 | 245 | $vars = array_merge( |
246 | 246 | $vars, |
247 | 247 | array( |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | 'orderby' => 'meta_value' |
250 | 250 | ) |
251 | 251 | ); |
252 | - } else if ( 'number' == $vars['orderby'] ) { |
|
252 | + } else if ('number' == $vars['orderby']) { |
|
253 | 253 | $vars = array_merge( |
254 | 254 | $vars, |
255 | 255 | array( |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | 'orderby' => 'meta_value' |
258 | 258 | ) |
259 | 259 | ); |
260 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
260 | + } else if ('payment_date' == $vars['orderby']) { |
|
261 | 261 | $vars = array_merge( |
262 | 262 | $vars, |
263 | 263 | array( |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | ); |
268 | 268 | } |
269 | 269 | } |
270 | - } else if ( 'wpi_item' == $typenow ) { |
|
270 | + } else if ('wpi_item' == $typenow) { |
|
271 | 271 | // Check if 'orderby' is set to "price" |
272 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
272 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
273 | 273 | $vars = array_merge( |
274 | 274 | $vars, |
275 | 275 | array( |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | // Check if "orderby" is set to "vat_rule" |
283 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
283 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
284 | 284 | $vars = array_merge( |
285 | 285 | $vars, |
286 | 286 | array( |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | |
293 | 293 | // Check if "orderby" is set to "vat_class" |
294 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
294 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
295 | 295 | $vars = array_merge( |
296 | 296 | $vars, |
297 | 297 | array( |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | // Check if "orderby" is set to "type" |
305 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
305 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
306 | 306 | $vars = array_merge( |
307 | 307 | $vars, |
308 | 308 | array( |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | } |
314 | 314 | |
315 | 315 | // Check if "orderby" is set to "recurring" |
316 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
316 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
317 | 317 | $vars = array_merge( |
318 | 318 | $vars, |
319 | 319 | array( |
@@ -323,104 +323,104 @@ discard block |
||
323 | 323 | ); |
324 | 324 | } |
325 | 325 | |
326 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
326 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
327 | 327 | // Filter vat rule type |
328 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
328 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
329 | 329 | $meta_query[] = array( |
330 | 330 | 'key' => '_wpinv_vat_rule', |
331 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
331 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
332 | 332 | 'compare' => '=' |
333 | 333 | ); |
334 | 334 | } |
335 | 335 | |
336 | 336 | // Filter vat class |
337 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
337 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
338 | 338 | $meta_query[] = array( |
339 | 339 | 'key' => '_wpinv_vat_class', |
340 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
340 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
341 | 341 | 'compare' => '=' |
342 | 342 | ); |
343 | 343 | } |
344 | 344 | |
345 | 345 | // Filter item type |
346 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
346 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
347 | 347 | $meta_query[] = array( |
348 | 348 | 'key' => '_wpinv_type', |
349 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
349 | + 'value' => sanitize_text_field($_GET['type']), |
|
350 | 350 | 'compare' => '=' |
351 | 351 | ); |
352 | 352 | } |
353 | 353 | |
354 | - if ( !empty( $meta_query ) ) { |
|
354 | + if (!empty($meta_query)) { |
|
355 | 355 | $vars['meta_query'] = $meta_query; |
356 | 356 | } |
357 | - } else if ( 'wpi_discount' == $typenow ) { |
|
358 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
357 | + } else if ('wpi_discount' == $typenow) { |
|
358 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
359 | 359 | // Filter vat rule type |
360 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
360 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
361 | 361 | $meta_query[] = array( |
362 | 362 | 'key' => '_wpi_discount_type', |
363 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
363 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
364 | 364 | 'compare' => '=' |
365 | 365 | ); |
366 | 366 | } |
367 | 367 | |
368 | - if ( !empty( $meta_query ) ) { |
|
368 | + if (!empty($meta_query)) { |
|
369 | 369 | $vars['meta_query'] = $meta_query; |
370 | 370 | } |
371 | 371 | } |
372 | 372 | |
373 | 373 | return $vars; |
374 | 374 | } |
375 | -add_filter( 'request', 'wpinv_request' ); |
|
375 | +add_filter('request', 'wpinv_request'); |
|
376 | 376 | |
377 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
377 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
378 | 378 | global $pagenow, $typenow; |
379 | 379 | |
380 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
381 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
382 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
380 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
381 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
382 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
383 | 383 | } |
384 | 384 | |
385 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
385 | + if (!wpinv_item_is_editable($post_id)) { |
|
386 | 386 | $classes[] = 'wpi-editable-n'; |
387 | 387 | } |
388 | 388 | } |
389 | 389 | return $classes; |
390 | 390 | } |
391 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
391 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
392 | 392 | |
393 | 393 | function wpinv_check_quick_edit() { |
394 | 394 | global $pagenow, $current_screen, $wpinv_item_screen; |
395 | 395 | |
396 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
397 | - if ( empty( $wpinv_item_screen ) ) { |
|
398 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
396 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
397 | + if (empty($wpinv_item_screen)) { |
|
398 | + if ($current_screen->post_type == 'wpi_item') { |
|
399 | 399 | $wpinv_item_screen = 'y'; |
400 | 400 | } else { |
401 | 401 | $wpinv_item_screen = 'n'; |
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
405 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
406 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
407 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
405 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
406 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
407 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | } |
411 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
411 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
412 | 412 | |
413 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
414 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
415 | - unset( $actions['inline hide-if-no-js'] ); |
|
413 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
414 | + if (isset($actions['inline hide-if-no-js'])) { |
|
415 | + unset($actions['inline hide-if-no-js']); |
|
416 | 416 | } |
417 | 417 | |
418 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
419 | - if ( isset( $actions['trash'] ) ) { |
|
420 | - unset( $actions['trash'] ); |
|
418 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
419 | + if (isset($actions['trash'])) { |
|
420 | + unset($actions['trash']); |
|
421 | 421 | } |
422 | - if ( isset( $actions['delete'] ) ) { |
|
423 | - unset( $actions['delete'] ); |
|
422 | + if (isset($actions['delete'])) { |
|
423 | + unset($actions['delete']); |
|
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
@@ -437,19 +437,19 @@ discard block |
||
437 | 437 | * @param int $post_parent (default: 0) Parent for the new page |
438 | 438 | * @return int page ID |
439 | 439 | */ |
440 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
440 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
441 | 441 | global $wpdb; |
442 | 442 | |
443 | - $option_value = wpinv_get_option( $option ); |
|
443 | + $option_value = wpinv_get_option($option); |
|
444 | 444 | |
445 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
446 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
445 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
446 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
447 | 447 | // Valid page is already in place |
448 | 448 | return $page_object->ID; |
449 | 449 | } |
450 | 450 | } |
451 | 451 | |
452 | - if(!empty($post_parent)){ |
|
452 | + if (!empty($post_parent)) { |
|
453 | 453 | $page = get_page_by_path($post_parent); |
454 | 454 | if ($page) { |
455 | 455 | $post_parent = $page->ID; |
@@ -458,40 +458,40 @@ discard block |
||
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - if ( strlen( $page_content ) > 0 ) { |
|
461 | + if (strlen($page_content) > 0) { |
|
462 | 462 | // Search for an existing page with the specified page content (typically a shortcode) |
463 | - $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}%" ) ); |
|
463 | + $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}%")); |
|
464 | 464 | } else { |
465 | 465 | // Search for an existing page with the specified page slug |
466 | - $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 ) ); |
|
466 | + $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)); |
|
467 | 467 | } |
468 | 468 | |
469 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
469 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
470 | 470 | |
471 | - if ( $valid_page_found ) { |
|
472 | - if ( $option ) { |
|
473 | - wpinv_update_option( $option, $valid_page_found ); |
|
471 | + if ($valid_page_found) { |
|
472 | + if ($option) { |
|
473 | + wpinv_update_option($option, $valid_page_found); |
|
474 | 474 | } |
475 | 475 | return $valid_page_found; |
476 | 476 | } |
477 | 477 | |
478 | 478 | // Search for a matching valid trashed page |
479 | - if ( strlen( $page_content ) > 0 ) { |
|
479 | + if (strlen($page_content) > 0) { |
|
480 | 480 | // Search for an existing page with the specified page content (typically a shortcode) |
481 | - $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}%" ) ); |
|
481 | + $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}%")); |
|
482 | 482 | } else { |
483 | 483 | // Search for an existing page with the specified page slug |
484 | - $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 ) ); |
|
484 | + $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)); |
|
485 | 485 | } |
486 | 486 | |
487 | - if ( $trashed_page_found ) { |
|
487 | + if ($trashed_page_found) { |
|
488 | 488 | $page_id = $trashed_page_found; |
489 | 489 | $page_data = array( |
490 | 490 | 'ID' => $page_id, |
491 | 491 | 'post_status' => 'publish', |
492 | 492 | 'post_parent' => $post_parent, |
493 | 493 | ); |
494 | - wp_update_post( $page_data ); |
|
494 | + wp_update_post($page_data); |
|
495 | 495 | } else { |
496 | 496 | $page_data = array( |
497 | 497 | 'post_status' => 'publish', |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | 'post_parent' => $post_parent, |
504 | 504 | 'comment_status' => 'closed', |
505 | 505 | ); |
506 | - $page_id = wp_insert_post( $page_data ); |
|
506 | + $page_id = wp_insert_post($page_data); |
|
507 | 507 | } |
508 | 508 | |
509 | - if ( $option ) { |
|
510 | - wpinv_update_option( $option, (int)$page_id ); |
|
509 | + if ($option) { |
|
510 | + wpinv_update_option($option, (int) $page_id); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | return $page_id; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Payment_Form { |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @param WP_Post $post |
13 | 13 | */ |
14 | - public static function output_shortcode( $post ) { |
|
14 | + public static function output_shortcode($post) { |
|
15 | 15 | |
16 | - if ( ! is_numeric( $post ) ) { |
|
16 | + if (!is_numeric($post)) { |
|
17 | 17 | $post = $post->ID; |
18 | 18 | } |
19 | 19 | |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param WP_Post $post |
27 | 27 | */ |
28 | - public static function output ( $post ) { |
|
29 | - $success_page = get_post_meta( $post->ID, 'wpinv_success_page', true ); |
|
30 | - $success_page = empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page |
|
28 | + public static function output($post) { |
|
29 | + $success_page = get_post_meta($post->ID, 'wpinv_success_page', true); |
|
30 | + $success_page = empty($success_page) ? wpinv_get_success_page_uri() : $success_page |
|
31 | 31 | ?> |
32 | 32 | |
33 | 33 | <div id="wpinv-form-builder" style="display: flex; flex-flow: wrap;"> |
@@ -35,20 +35,20 @@ discard block |
||
35 | 35 | <div class="wpinv-form-builder-left bsui" style="flex: 0 0 320px;"> |
36 | 36 | <ul class="wpinv-form-builder-tabs nav nav-tabs"> |
37 | 37 | <li class='nav-item' v-if="active_tab!='new_item'"> |
38 | - <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e( 'Add new element', 'invoicing' ); ?></a> |
|
38 | + <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e('Add new element', 'invoicing'); ?></a> |
|
39 | 39 | </li> |
40 | 40 | <li class='nav-item' v-if='false'> |
41 | - <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e( 'Edit element', 'invoicing' ); ?></a> |
|
41 | + <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e('Edit element', 'invoicing'); ?></a> |
|
42 | 42 | </li> |
43 | 43 | <li class='nav-item' v-if='false'> |
44 | - <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e( 'Settings', 'invoicing' ); ?></a> |
|
44 | + <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e('Settings', 'invoicing'); ?></a> |
|
45 | 45 | </li> |
46 | 46 | </ul> |
47 | 47 | |
48 | 48 | <div class="wpinv-form-builder-tab-content bsui" style="margin-top: 16px;"> |
49 | 49 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
50 | 50 | <div class="wpinv-form-builder-add-field-types"> |
51 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
51 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
52 | 52 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
53 | 53 | <li v-for="element in elements" style="width: 49%; background-color: #fafafa; margin-bottom: 9px; cursor: move; border: 1px solid #eeeeee;" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
54 | 54 | <button class="button btn" style="width: 100%; cursor: move;"> |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | |
64 | 64 | <div class="wpinv-form-builder-tab-pane bsui" v-if="active_tab=='edit_item'" style="font-size: 16px;"> |
65 | 65 | <div class="wpinv-form-builder-edit-field-wrapper"> |
66 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
66 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
67 | 67 | <div> |
68 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Field', 'invoicing' ); ?></button> |
|
68 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Field', 'invoicing'); ?></button> |
|
69 | 69 | </div> |
70 | 70 | </div> |
71 | 71 | </div> |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | <div class="wpinv-form-builder-settings-wrapper"> |
75 | 75 | |
76 | 76 | <div class='form-group'> |
77 | - <label for="wpi-success-page"><?php _e( 'Success Page', 'invoicing' ); ?></label> |
|
78 | - <input placeholder="https://" id='wpi-success-page' value="<?php echo esc_url( $success_page ); ?>" class='form-control' type='text'> |
|
79 | - <small class='form-text text-muted'><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></small> |
|
77 | + <label for="wpi-success-page"><?php _e('Success Page', 'invoicing'); ?></label> |
|
78 | + <input placeholder="https://" id='wpi-success-page' value="<?php echo esc_url($success_page); ?>" class='form-control' type='text'> |
|
79 | + <small class='form-text text-muted'><?php _e('Where should we redirect users after successfuly completing their payment?', 'invoicing'); ?></small> |
|
80 | 80 | </div> |
81 | 81 | |
82 | 82 | </div> |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | |
88 | 88 | <div class="wpinv-form-builder-right" style="flex: 1; padding-top: 40px;border-left: 1px solid #ddd;padding-left: 20px;min-height: 520px;margin-left: 10px;"> |
89 | 89 | |
90 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
91 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
90 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
91 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
92 | 92 | |
93 | 93 | <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;"> |
94 | 94 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element && active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
95 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
95 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
96 | 96 | </div> |
97 | 97 | </draggable> |
98 | 98 | </div> |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | <textarea style="display:none;" name="wpinv_form_items" v-model="itemString"></textarea> |
102 | 102 | </div> |
103 | 103 | |
104 | - <?php wp_nonce_field( 'wpinv_save_payment_form', 'wpinv_save_payment_form' ) ;?> |
|
104 | + <?php wp_nonce_field('wpinv_save_payment_form', 'wpinv_save_payment_form'); ?> |
|
105 | 105 | |
106 | 106 | <?php |
107 | 107 | } |
@@ -109,83 +109,83 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * Saves our payment forms. |
111 | 111 | */ |
112 | - public static function save( $post_id, $post ) { |
|
112 | + public static function save($post_id, $post) { |
|
113 | 113 | |
114 | - remove_action( 'save_post', 'WPInv_Meta_Box_Payment_Form::save' ); |
|
114 | + remove_action('save_post', 'WPInv_Meta_Box_Payment_Form::save'); |
|
115 | 115 | |
116 | 116 | // $post_id and $post are required. |
117 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
117 | + if (empty($post_id) || empty($post)) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Ensure that this user can edit the post. |
122 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
122 | + if (!current_user_can('edit_post', $post_id)) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | // Dont' save meta boxes for revisions or autosaves |
127 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
127 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
131 | 131 | // Do not save for ajax requests. |
132 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
132 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Confirm the security nonce. |
137 | - if ( empty( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) { |
|
137 | + if (empty($_POST['wpinv_save_payment_form']) || !wp_verify_nonce($_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form')) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | 141 | // Save form items. |
142 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
142 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
143 | 143 | |
144 | - if ( empty( $form_items ) ) { |
|
144 | + if (empty($form_items)) { |
|
145 | 145 | $form_items = array(); |
146 | 146 | } |
147 | 147 | |
148 | - update_post_meta( $post_id, 'wpinv_form_items', self::maybe_save_items( $form_items ) ); |
|
148 | + update_post_meta($post_id, 'wpinv_form_items', self::maybe_save_items($form_items)); |
|
149 | 149 | |
150 | 150 | // Save form elements. |
151 | - $wpinv_form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
152 | - if ( empty( $wpinv_form_elements ) ) { |
|
151 | + $wpinv_form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
152 | + if (empty($wpinv_form_elements)) { |
|
153 | 153 | $wpinv_form_elements = array(); |
154 | 154 | } |
155 | 155 | |
156 | - update_post_meta( $post_id, 'wpinv_form_elements', $wpinv_form_elements ); |
|
156 | + update_post_meta($post_id, 'wpinv_form_elements', $wpinv_form_elements); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | 160 | * Saves unsaved form items. |
161 | 161 | */ |
162 | - public static function maybe_save_items( $items ) { |
|
162 | + public static function maybe_save_items($items) { |
|
163 | 163 | |
164 | 164 | $saved = array(); |
165 | 165 | |
166 | - foreach( $items as $item ) { |
|
166 | + foreach ($items as $item) { |
|
167 | 167 | |
168 | - if ( is_numeric( $item['id'] ) ) { |
|
168 | + if (is_numeric($item['id'])) { |
|
169 | 169 | $saved[] = $item; |
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $data = array( |
174 | - 'post_title' => sanitize_text_field( $item['title'] ), |
|
175 | - 'post_excerpt' => wp_kses_post( $item['description'] ), |
|
174 | + 'post_title' => sanitize_text_field($item['title']), |
|
175 | + 'post_excerpt' => wp_kses_post($item['description']), |
|
176 | 176 | 'post_status' => 'publish', |
177 | 177 | 'meta' => array( |
178 | 178 | 'type' => 'custom', |
179 | - 'price' => wpinv_sanitize_amount( $item['price'] ), |
|
179 | + 'price' => wpinv_sanitize_amount($item['price']), |
|
180 | 180 | 'vat_rule' => 'digital', |
181 | 181 | 'vat_class' => '_standard', |
182 | 182 | ) |
183 | 183 | ); |
184 | 184 | |
185 | - $new_item = new WPInv_Item(); |
|
186 | - $new_item->create( $data ); |
|
185 | + $new_item = new WPInv_Item(); |
|
186 | + $new_item->create($data); |
|
187 | 187 | |
188 | - if ( ! empty( $new_item ) ) { |
|
188 | + if (!empty($new_item)) { |
|
189 | 189 | $item['id'] = $new_item->ID; |
190 | 190 | $saved[] = $item; |
191 | 191 | } |
@@ -198,5 +198,5 @@ discard block |
||
198 | 198 | |
199 | 199 | } |
200 | 200 | |
201 | -add_action( 'save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2 ); |
|
201 | +add_action('save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2); |
|
202 | 202 |