@@ -7,41 +7,41 @@ 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 | -add_action( 'init', 'wpinv_register_post_types', 1 ); |
|
14 | +add_action('init', 'wpinv_register_post_types', 1); |
|
15 | 15 | function wpinv_register_post_types() { |
16 | 16 | |
17 | 17 | $items_labels = array( |
18 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
19 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
20 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
21 | - 'add_new' => _x( 'Add New', 'wpi_item', 'invoicing' ), |
|
22 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
23 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
24 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
25 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
26 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
27 | - 'search_items' => __( 'Search Items', 'invoicing' ), |
|
18 | + 'name' => _x('Items', 'post type general name', 'invoicing'), |
|
19 | + 'singular_name' => _x('Item', 'post type singular name', 'invoicing'), |
|
20 | + 'menu_name' => _x('Items', 'admin menu', 'invoicing'), |
|
21 | + 'add_new' => _x('Add New', 'wpi_item', 'invoicing'), |
|
22 | + 'add_new_item' => __('Add New Item', 'invoicing'), |
|
23 | + 'new_item' => __('New Item', 'invoicing'), |
|
24 | + 'edit_item' => __('Edit Item', 'invoicing'), |
|
25 | + 'view_item' => __('View Item', 'invoicing'), |
|
26 | + 'all_items' => __('Items', 'invoicing'), |
|
27 | + 'search_items' => __('Search Items', 'invoicing'), |
|
28 | 28 | 'parent_item_colon' => '', |
29 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
30 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
29 | + 'not_found' => __('No items found.', 'invoicing'), |
|
30 | + 'not_found_in_trash' => __('No items found in trash.', 'invoicing') |
|
31 | 31 | ); |
32 | - $items_labels = apply_filters( 'wpinv_items_labels', $items_labels ); |
|
32 | + $items_labels = apply_filters('wpinv_items_labels', $items_labels); |
|
33 | 33 | |
34 | 34 | $cap_type = 'wpi_item'; |
35 | 35 | $invoice_item_args = array( |
36 | 36 | 'labels' => $items_labels, |
37 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
37 | + 'description' => __('This is where you can add new invoice items.', 'invoicing'), |
|
38 | 38 | 'public' => false, |
39 | 39 | 'has_archive' => false, |
40 | 40 | '_builtin' => false, |
41 | 41 | 'show_ui' => true, |
42 | 42 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
43 | 43 | 'show_in_nav_menus' => false, |
44 | - 'supports' => array( 'title', 'excerpt' ), |
|
44 | + 'supports' => array('title', 'excerpt'), |
|
45 | 45 | 'register_meta_box_cb' => 'wpinv_register_item_meta_boxes', |
46 | 46 | 'rewrite' => false, |
47 | 47 | 'query_var' => false, |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | ), |
69 | 69 | 'can_export' => true, |
70 | 70 | ); |
71 | - $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args ); |
|
71 | + $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args); |
|
72 | 72 | |
73 | - register_post_type( 'wpi_item', $invoice_item_args ); |
|
73 | + register_post_type('wpi_item', $invoice_item_args); |
|
74 | 74 | |
75 | 75 | $cap_type = 'wpi_payment_form'; |
76 | 76 | register_post_type( |
@@ -79,22 +79,22 @@ discard block |
||
79 | 79 | 'wpinv_register_post_type_payment_form', |
80 | 80 | array( |
81 | 81 | 'labels' => array( |
82 | - 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
83 | - 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
84 | - 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
85 | - 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
86 | - 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
87 | - 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
88 | - 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
89 | - 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
90 | - 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
91 | - 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
92 | - 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
93 | - 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
94 | - 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
95 | - 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
82 | + 'name' => _x('Payment Forms', 'post type general name', 'invoicing'), |
|
83 | + 'singular_name' => _x('Payment Form', 'post type singular name', 'invoicing'), |
|
84 | + 'menu_name' => _x('Payment Forms', 'admin menu', 'invoicing'), |
|
85 | + 'name_admin_bar' => _x('Payment Form', 'add new on admin bar', 'invoicing'), |
|
86 | + 'add_new' => _x('Add New', 'Payment Form', 'invoicing'), |
|
87 | + 'add_new_item' => __('Add New Payment Form', 'invoicing'), |
|
88 | + 'new_item' => __('New Payment Form', 'invoicing'), |
|
89 | + 'edit_item' => __('Edit Payment Form', 'invoicing'), |
|
90 | + 'view_item' => __('View Payment Form', 'invoicing'), |
|
91 | + 'all_items' => __('Payment Forms', 'invoicing'), |
|
92 | + 'search_items' => __('Search Payment Forms', 'invoicing'), |
|
93 | + 'parent_item_colon' => __('Parent Payment Forms:', 'invoicing'), |
|
94 | + 'not_found' => __('No payment forms found.', 'invoicing'), |
|
95 | + 'not_found_in_trash' => __('No payment forms found in trash.', 'invoicing') |
|
96 | 96 | ), |
97 | - 'description' => __( 'Stores payment forms.', 'invoicing' ), |
|
97 | + 'description' => __('Stores payment forms.', 'invoicing'), |
|
98 | 98 | 'public' => false, |
99 | 99 | 'show_ui' => true, |
100 | 100 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
@@ -105,37 +105,37 @@ discard block |
||
105 | 105 | 'has_archive' => false, |
106 | 106 | 'hierarchical' => false, |
107 | 107 | 'menu_position' => null, |
108 | - 'supports' => array( 'title' ), |
|
108 | + 'supports' => array('title'), |
|
109 | 109 | 'menu_icon' => 'dashicons-media-form', |
110 | 110 | ) |
111 | 111 | ) |
112 | 112 | ); |
113 | 113 | |
114 | 114 | $labels = array( |
115 | - 'name' => _x( 'Invoices', 'post type general name', 'invoicing' ), |
|
116 | - 'singular_name' => _x( 'Invoice', 'post type singular name', 'invoicing' ), |
|
117 | - 'menu_name' => _x( 'Invoices', 'admin menu', 'invoicing' ), |
|
118 | - 'name_admin_bar' => _x( 'Invoice', 'add new on admin bar', 'invoicing' ), |
|
119 | - 'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
120 | - 'add_new_item' => __( 'Add New Invoice', 'invoicing' ), |
|
121 | - 'new_item' => __( 'New Invoice', 'invoicing' ), |
|
122 | - 'edit_item' => __( 'Edit Invoice', 'invoicing' ), |
|
123 | - 'view_item' => __( 'View Invoice', 'invoicing' ), |
|
124 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
125 | - 'search_items' => __( 'Search Invoices', 'invoicing' ), |
|
126 | - 'parent_item_colon' => __( 'Parent Invoices:', 'invoicing' ), |
|
127 | - 'not_found' => __( 'No invoices found.', 'invoicing' ), |
|
128 | - 'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' ) |
|
115 | + 'name' => _x('Invoices', 'post type general name', 'invoicing'), |
|
116 | + 'singular_name' => _x('Invoice', 'post type singular name', 'invoicing'), |
|
117 | + 'menu_name' => _x('Invoices', 'admin menu', 'invoicing'), |
|
118 | + 'name_admin_bar' => _x('Invoice', 'add new on admin bar', 'invoicing'), |
|
119 | + 'add_new' => _x('Add New', 'book', 'invoicing'), |
|
120 | + 'add_new_item' => __('Add New Invoice', 'invoicing'), |
|
121 | + 'new_item' => __('New Invoice', 'invoicing'), |
|
122 | + 'edit_item' => __('Edit Invoice', 'invoicing'), |
|
123 | + 'view_item' => __('View Invoice', 'invoicing'), |
|
124 | + 'all_items' => __('Invoices', 'invoicing'), |
|
125 | + 'search_items' => __('Search Invoices', 'invoicing'), |
|
126 | + 'parent_item_colon' => __('Parent Invoices:', 'invoicing'), |
|
127 | + 'not_found' => __('No invoices found.', 'invoicing'), |
|
128 | + 'not_found_in_trash' => __('No invoices found in trash.', 'invoicing') |
|
129 | 129 | ); |
130 | - $labels = apply_filters( 'wpinv_labels', $labels ); |
|
130 | + $labels = apply_filters('wpinv_labels', $labels); |
|
131 | 131 | |
132 | 132 | $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico'; |
133 | - $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon ); |
|
133 | + $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon); |
|
134 | 134 | |
135 | 135 | $cap_type = 'wpi_invoice'; |
136 | 136 | $args = array( |
137 | 137 | 'labels' => $labels, |
138 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
138 | + 'description' => __('This is where invoices are stored.', 'invoicing'), |
|
139 | 139 | 'public' => true, |
140 | 140 | 'can_export' => true, |
141 | 141 | '_builtin' => false, |
@@ -168,37 +168,37 @@ discard block |
||
168 | 168 | 'has_archive' => false, |
169 | 169 | 'hierarchical' => false, |
170 | 170 | 'menu_position' => null, |
171 | - 'supports' => array( 'title', 'author' ), |
|
171 | + 'supports' => array('title', 'author'), |
|
172 | 172 | 'menu_icon' => 'dashicons-media-spreadsheet', |
173 | 173 | ); |
174 | 174 | |
175 | - $args = apply_filters( 'wpinv_register_post_type_invoice', $args ); |
|
175 | + $args = apply_filters('wpinv_register_post_type_invoice', $args); |
|
176 | 176 | |
177 | - register_post_type( 'wpi_invoice', $args ); |
|
177 | + register_post_type('wpi_invoice', $args); |
|
178 | 178 | |
179 | 179 | $labels = array( |
180 | - 'name' => _x( 'Discounts', 'post type general name', 'invoicing' ), |
|
181 | - 'singular_name' => _x( 'Discount', 'post type singular name', 'invoicing' ), |
|
182 | - 'menu_name' => _x( 'Discounts', 'admin menu', 'invoicing' ), |
|
183 | - 'name_admin_bar' => _x( 'Discount', 'add new on admin bar', 'invoicing' ), |
|
184 | - 'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
185 | - 'add_new_item' => __( 'Add New Discount', 'invoicing' ), |
|
186 | - 'new_item' => __( 'New Discount', 'invoicing' ), |
|
187 | - 'edit_item' => __( 'Edit Discount', 'invoicing' ), |
|
188 | - 'view_item' => __( 'View Discount', 'invoicing' ), |
|
189 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
190 | - 'search_items' => __( 'Search Discounts', 'invoicing' ), |
|
191 | - 'parent_item_colon' => __( 'Parent Discounts:', 'invoicing' ), |
|
192 | - 'not_found' => __( 'No discounts found.', 'invoicing' ), |
|
193 | - 'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' ) |
|
180 | + 'name' => _x('Discounts', 'post type general name', 'invoicing'), |
|
181 | + 'singular_name' => _x('Discount', 'post type singular name', 'invoicing'), |
|
182 | + 'menu_name' => _x('Discounts', 'admin menu', 'invoicing'), |
|
183 | + 'name_admin_bar' => _x('Discount', 'add new on admin bar', 'invoicing'), |
|
184 | + 'add_new' => _x('Add New', 'book', 'invoicing'), |
|
185 | + 'add_new_item' => __('Add New Discount', 'invoicing'), |
|
186 | + 'new_item' => __('New Discount', 'invoicing'), |
|
187 | + 'edit_item' => __('Edit Discount', 'invoicing'), |
|
188 | + 'view_item' => __('View Discount', 'invoicing'), |
|
189 | + 'all_items' => __('Discounts', 'invoicing'), |
|
190 | + 'search_items' => __('Search Discounts', 'invoicing'), |
|
191 | + 'parent_item_colon' => __('Parent Discounts:', 'invoicing'), |
|
192 | + 'not_found' => __('No discounts found.', 'invoicing'), |
|
193 | + 'not_found_in_trash' => __('No discounts found in trash.', 'invoicing') |
|
194 | 194 | ); |
195 | - $labels = apply_filters( 'wpinv_discounts_labels', $labels ); |
|
195 | + $labels = apply_filters('wpinv_discounts_labels', $labels); |
|
196 | 196 | |
197 | 197 | $cap_type = 'wpi_discount'; |
198 | 198 | |
199 | 199 | $args = array( |
200 | 200 | 'labels' => $labels, |
201 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
201 | + 'description' => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'), |
|
202 | 202 | 'public' => false, |
203 | 203 | 'can_export' => true, |
204 | 204 | '_builtin' => false, |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | ), |
230 | 230 | 'has_archive' => false, |
231 | 231 | 'hierarchical' => false, |
232 | - 'supports' => array( 'title', 'excerpt' ), |
|
232 | + 'supports' => array('title', 'excerpt'), |
|
233 | 233 | 'register_meta_box_cb' => 'wpinv_register_discount_meta_boxes', |
234 | 234 | 'show_in_nav_menus' => false, |
235 | 235 | 'show_in_admin_bar' => true, |
@@ -237,106 +237,106 @@ discard block |
||
237 | 237 | 'menu_position' => null, |
238 | 238 | ); |
239 | 239 | |
240 | - $args = apply_filters( 'wpinv_register_post_type_discount', $args ); |
|
240 | + $args = apply_filters('wpinv_register_post_type_discount', $args); |
|
241 | 241 | |
242 | - register_post_type( 'wpi_discount', $args ); |
|
242 | + register_post_type('wpi_discount', $args); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | function wpinv_get_default_labels() { |
246 | 246 | $defaults = array( |
247 | - 'singular' => __( 'Invoice', 'invoicing' ), |
|
248 | - 'plural' => __( 'Invoices', 'invoicing' ) |
|
247 | + 'singular' => __('Invoice', 'invoicing'), |
|
248 | + 'plural' => __('Invoices', 'invoicing') |
|
249 | 249 | ); |
250 | 250 | |
251 | - return apply_filters( 'wpinv_default_invoices_name', $defaults ); |
|
251 | + return apply_filters('wpinv_default_invoices_name', $defaults); |
|
252 | 252 | } |
253 | 253 | |
254 | -function wpinv_get_label_singular( $lowercase = false ) { |
|
254 | +function wpinv_get_label_singular($lowercase = false) { |
|
255 | 255 | $defaults = wpinv_get_default_labels(); |
256 | 256 | |
257 | - return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
|
257 | + return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular']; |
|
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_get_label_plural( $lowercase = false ) { |
|
260 | +function wpinv_get_label_plural($lowercase = false) { |
|
261 | 261 | $defaults = wpinv_get_default_labels(); |
262 | 262 | |
263 | - return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
|
263 | + return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural']; |
|
264 | 264 | } |
265 | 265 | |
266 | -function wpinv_change_default_title( $title ) { |
|
267 | - if ( !is_admin() ) { |
|
266 | +function wpinv_change_default_title($title) { |
|
267 | + if (!is_admin()) { |
|
268 | 268 | $label = wpinv_get_label_singular(); |
269 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
269 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
270 | 270 | return $title; |
271 | 271 | } |
272 | 272 | |
273 | 273 | $screen = get_current_screen(); |
274 | 274 | |
275 | - if ( 'wpi_invoice' == $screen->post_type ) { |
|
275 | + if ('wpi_invoice' == $screen->post_type) { |
|
276 | 276 | $label = wpinv_get_label_singular(); |
277 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
277 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | return $title; |
281 | 281 | } |
282 | -add_filter( 'enter_title_here', 'wpinv_change_default_title' ); |
|
282 | +add_filter('enter_title_here', 'wpinv_change_default_title'); |
|
283 | 283 | |
284 | 284 | function wpinv_register_post_status() { |
285 | - register_post_status( 'wpi-pending', array( |
|
286 | - 'label' => _x( 'Pending', 'Invoice status', 'invoicing' ), |
|
285 | + register_post_status('wpi-pending', array( |
|
286 | + 'label' => _x('Pending', 'Invoice status', 'invoicing'), |
|
287 | 287 | 'public' => true, |
288 | 288 | 'exclude_from_search' => true, |
289 | 289 | 'show_in_admin_all_list' => true, |
290 | 290 | 'show_in_admin_status_list' => true, |
291 | - 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing' ) |
|
292 | - ) ); |
|
293 | - register_post_status( 'wpi-processing', array( |
|
294 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
291 | + 'label_count' => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing') |
|
292 | + )); |
|
293 | + register_post_status('wpi-processing', array( |
|
294 | + 'label' => _x('Processing', 'Invoice status', 'invoicing'), |
|
295 | 295 | 'public' => true, |
296 | 296 | 'exclude_from_search' => true, |
297 | 297 | 'show_in_admin_all_list' => true, |
298 | 298 | 'show_in_admin_status_list' => true, |
299 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
300 | - ) ); |
|
301 | - register_post_status( 'wpi-onhold', array( |
|
302 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
299 | + 'label_count' => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing') |
|
300 | + )); |
|
301 | + register_post_status('wpi-onhold', array( |
|
302 | + 'label' => _x('On Hold', 'Invoice status', 'invoicing'), |
|
303 | 303 | 'public' => true, |
304 | 304 | 'exclude_from_search' => true, |
305 | 305 | 'show_in_admin_all_list' => true, |
306 | 306 | 'show_in_admin_status_list' => true, |
307 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
308 | - ) ); |
|
309 | - register_post_status( 'wpi-cancelled', array( |
|
310 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
307 | + 'label_count' => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing') |
|
308 | + )); |
|
309 | + register_post_status('wpi-cancelled', array( |
|
310 | + 'label' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
311 | 311 | 'public' => true, |
312 | 312 | 'exclude_from_search' => true, |
313 | 313 | 'show_in_admin_all_list' => true, |
314 | 314 | 'show_in_admin_status_list' => true, |
315 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
316 | - ) ); |
|
317 | - register_post_status( 'wpi-refunded', array( |
|
318 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
315 | + 'label_count' => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing') |
|
316 | + )); |
|
317 | + register_post_status('wpi-refunded', array( |
|
318 | + 'label' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
319 | 319 | 'public' => true, |
320 | 320 | 'exclude_from_search' => true, |
321 | 321 | 'show_in_admin_all_list' => true, |
322 | 322 | 'show_in_admin_status_list' => true, |
323 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
324 | - ) ); |
|
325 | - register_post_status( 'wpi-failed', array( |
|
326 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
323 | + 'label_count' => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing') |
|
324 | + )); |
|
325 | + register_post_status('wpi-failed', array( |
|
326 | + 'label' => _x('Failed', 'Invoice status', 'invoicing'), |
|
327 | 327 | 'public' => true, |
328 | 328 | 'exclude_from_search' => true, |
329 | 329 | 'show_in_admin_all_list' => true, |
330 | 330 | 'show_in_admin_status_list' => true, |
331 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
332 | - ) ); |
|
333 | - register_post_status( 'wpi-renewal', array( |
|
334 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
331 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing') |
|
332 | + )); |
|
333 | + register_post_status('wpi-renewal', array( |
|
334 | + 'label' => _x('Renewal', 'Invoice status', 'invoicing'), |
|
335 | 335 | 'public' => true, |
336 | 336 | 'exclude_from_search' => true, |
337 | 337 | 'show_in_admin_all_list' => true, |
338 | 338 | 'show_in_admin_status_list' => true, |
339 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
340 | - ) ); |
|
339 | + 'label_count' => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing') |
|
340 | + )); |
|
341 | 341 | } |
342 | -add_action( 'init', 'wpinv_register_post_status', 10 ); |
|
342 | +add_action('init', 'wpinv_register_post_status', 10); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Setup menus in WP admin. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WC_Admin_Menus Class. |
@@ -13,35 +13,35 @@ discard block |
||
13 | 13 | * Hook in tabs. |
14 | 14 | */ |
15 | 15 | public function __construct() { |
16 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
17 | - add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 ); |
|
18 | - add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 ); |
|
19 | - add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 ); |
|
20 | - add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); |
|
16 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
17 | + add_action('admin_menu', array($this, 'add_addons_menu'), 100); |
|
18 | + add_action('admin_menu', array($this, 'add_settings_menu'), 60); |
|
19 | + add_action('admin_menu', array($this, 'remove_admin_submenus'), 10); |
|
20 | + add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function admin_menu() { |
24 | 24 | global $menu, $submenu; |
25 | 25 | |
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
26 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
27 | 27 | return; |
28 | 28 | } |
29 | 29 | |
30 | - $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() ); |
|
30 | + $capability = apply_filters('invoicing_capability', wpinv_get_capability()); |
|
31 | 31 | |
32 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
33 | - $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' ); |
|
32 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
33 | + $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv'); |
|
34 | 34 | |
35 | 35 | // Allow users with 'manage_invocing' capability to create new invoices |
36 | - $submenu['post-new.php?post_type=wpi_item'][] = array( '', '', 'post-new.php?post_type=wpi_item', '' ); |
|
37 | - $submenu['post-new.php?post_type=wpi_invoice'][] = array( '', '', 'post-new.php?post_type=wpi_invoice', '' ); |
|
38 | - $submenu['post-new.php?post_type=wpi_discount'][] = array( '', '', 'post-new.php?post_type=wpi_discount', '' ); |
|
36 | + $submenu['post-new.php?post_type=wpi_item'][] = array('', '', 'post-new.php?post_type=wpi_item', ''); |
|
37 | + $submenu['post-new.php?post_type=wpi_invoice'][] = array('', '', 'post-new.php?post_type=wpi_invoice', ''); |
|
38 | + $submenu['post-new.php?post_type=wpi_discount'][] = array('', '', 'post-new.php?post_type=wpi_discount', ''); |
|
39 | 39 | |
40 | 40 | } |
41 | 41 | |
42 | - $wpi_invoice = get_post_type_object( 'wpi_invoice' ); |
|
42 | + $wpi_invoice = get_post_type_object('wpi_invoice'); |
|
43 | 43 | |
44 | - add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' ); |
|
44 | + add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460'); |
|
45 | 45 | |
46 | 46 | } |
47 | 47 | |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | public function add_settings_menu() { |
52 | 52 | add_submenu_page( |
53 | 53 | 'wpinv', |
54 | - __( 'Invoice Settings', 'invoicing' ), |
|
55 | - __( 'Settings', 'invoicing' ), |
|
56 | - apply_filters( 'invoicing_capability', wpinv_get_capability() ), |
|
54 | + __('Invoice Settings', 'invoicing'), |
|
55 | + __('Settings', 'invoicing'), |
|
56 | + apply_filters('invoicing_capability', wpinv_get_capability()), |
|
57 | 57 | 'wpinv-settings', |
58 | - array( $this, 'options_page' ) |
|
58 | + array($this, 'options_page') |
|
59 | 59 | ); |
60 | 60 | } |
61 | 61 | |
62 | - public function add_addons_menu(){ |
|
63 | - if ( !apply_filters( 'wpi_show_addons_page', true ) ) { |
|
62 | + public function add_addons_menu() { |
|
63 | + if (!apply_filters('wpi_show_addons_page', true)) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
@@ -70,78 +70,78 @@ discard block |
||
70 | 70 | __('Extensions', 'invoicing'), |
71 | 71 | 'manage_options', |
72 | 72 | 'wpi-addons', |
73 | - array( $this, 'addons_page' ) |
|
73 | + array($this, 'addons_page') |
|
74 | 74 | ); |
75 | 75 | } |
76 | 76 | |
77 | - public function addons_page(){ |
|
77 | + public function addons_page() { |
|
78 | 78 | $addon_obj = new WPInv_Admin_Addons(); |
79 | 79 | $addon_obj->output(); |
80 | 80 | } |
81 | 81 | |
82 | 82 | function options_page() { |
83 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
83 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
84 | 84 | |
85 | - if ( $page !== 'wpinv-settings' ) { |
|
85 | + if ($page !== 'wpinv-settings') { |
|
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | 89 | $settings_tabs = wpinv_get_settings_tabs(); |
90 | 90 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
91 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
92 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
91 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
92 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
93 | 93 | $key = 'main'; |
94 | 94 | |
95 | - if ( is_array( $sections ) ) { |
|
96 | - $key = key( $sections ); |
|
95 | + if (is_array($sections)) { |
|
96 | + $key = key($sections); |
|
97 | 97 | } |
98 | 98 | |
99 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
100 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
99 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
100 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
101 | 101 | ob_start(); |
102 | 102 | ?> |
103 | 103 | <div class="wrap"> |
104 | 104 | <h1 class="nav-tab-wrapper"> |
105 | 105 | <?php |
106 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
107 | - $tab_url = add_query_arg( array( |
|
106 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
107 | + $tab_url = add_query_arg(array( |
|
108 | 108 | 'settings-updated' => false, |
109 | 109 | 'tab' => $tab_id, |
110 | - ) ); |
|
110 | + )); |
|
111 | 111 | |
112 | 112 | // Remove the section from the tabs so we always end up at the main section |
113 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
114 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
113 | + $tab_url = remove_query_arg('section', $tab_url); |
|
114 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
115 | 115 | |
116 | 116 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
117 | 117 | |
118 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
119 | - echo esc_html( $tab_name ); |
|
118 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
119 | + echo esc_html($tab_name); |
|
120 | 120 | echo '</a>'; |
121 | 121 | } |
122 | 122 | ?> |
123 | 123 | </h1> |
124 | 124 | <?php |
125 | - $number_of_sections = count( $sections ); |
|
125 | + $number_of_sections = count($sections); |
|
126 | 126 | $number = 0; |
127 | - if ( $number_of_sections > 1 ) { |
|
127 | + if ($number_of_sections > 1) { |
|
128 | 128 | echo '<div><ul class="subsubsub">'; |
129 | - foreach( $sections as $section_id => $section_name ) { |
|
129 | + foreach ($sections as $section_id => $section_name) { |
|
130 | 130 | echo '<li>'; |
131 | 131 | $number++; |
132 | - $tab_url = add_query_arg( array( |
|
132 | + $tab_url = add_query_arg(array( |
|
133 | 133 | 'settings-updated' => false, |
134 | 134 | 'tab' => $active_tab, |
135 | 135 | 'section' => $section_id |
136 | - ) ); |
|
137 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
136 | + )); |
|
137 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
138 | 138 | $class = ''; |
139 | - if ( $section == $section_id ) { |
|
139 | + if ($section == $section_id) { |
|
140 | 140 | $class = 'current'; |
141 | 141 | } |
142 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
142 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
143 | 143 | |
144 | - if ( $number != $number_of_sections ) { |
|
144 | + if ($number != $number_of_sections) { |
|
145 | 145 | echo ' | '; |
146 | 146 | } |
147 | 147 | echo '</li>'; |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | <form method="post" action="options.php"> |
154 | 154 | <table class="form-table"> |
155 | 155 | <?php |
156 | - settings_fields( 'wpinv_settings' ); |
|
156 | + settings_fields('wpinv_settings'); |
|
157 | 157 | |
158 | - if ( 'main' === $section ) { |
|
159 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
158 | + if ('main' === $section) { |
|
159 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
160 | 160 | } |
161 | 161 | |
162 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
163 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
164 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
162 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
163 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
164 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
165 | 165 | |
166 | 166 | // For backwards compatibility |
167 | - if ( 'main' === $section ) { |
|
168 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
167 | + if ('main' === $section) { |
|
168 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
169 | 169 | } |
170 | 170 | ?> |
171 | 171 | </table> |
@@ -179,18 +179,18 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | public function remove_admin_submenus() { |
182 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
182 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
183 | 183 | } |
184 | 184 | |
185 | - public function add_nav_menu_meta_boxes(){ |
|
186 | - add_meta_box( 'wpinv_endpoints_nav_link', __( 'Invoicing Pages', 'invoicing' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' ); |
|
185 | + public function add_nav_menu_meta_boxes() { |
|
186 | + add_meta_box('wpinv_endpoints_nav_link', __('Invoicing Pages', 'invoicing'), array($this, 'nav_menu_links'), 'nav-menus', 'side', 'low'); |
|
187 | 187 | } |
188 | 188 | |
189 | - public function nav_menu_links(){ |
|
189 | + public function nav_menu_links() { |
|
190 | 190 | $endpoints = $this->get_menu_items(); |
191 | 191 | ?> |
192 | 192 | <div id="invoicing-endpoints" class="posttypediv"> |
193 | - <?php if(!empty($endpoints['pages'])){ ?> |
|
193 | + <?php if (!empty($endpoints['pages'])) { ?> |
|
194 | 194 | <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active"> |
195 | 195 | <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear"> |
196 | 196 | <?php |
@@ -202,29 +202,29 @@ discard block |
||
202 | 202 | <?php } ?> |
203 | 203 | <p class="button-controls"> |
204 | 204 | <span class="list-controls"> |
205 | - <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints' ); ?>" class="select-all"><?php _e( 'Select all', 'invoicing' ); ?></a> |
|
205 | + <a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints'); ?>" class="select-all"><?php _e('Select all', 'invoicing'); ?></a> |
|
206 | 206 | </span> |
207 | 207 | <span class="add-to-menu"> |
208 | - <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
208 | + <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
209 | 209 | <span class="spinner"></span> |
210 | 210 | </span> |
211 | 211 | </p> |
212 | 212 | <?php |
213 | 213 | } |
214 | 214 | |
215 | - public function get_menu_items(){ |
|
215 | + public function get_menu_items() { |
|
216 | 216 | $items = array(); |
217 | 217 | |
218 | - $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' ); |
|
219 | - if($wpinv_history_page_id > 0){ |
|
218 | + $wpinv_history_page_id = (int) wpinv_get_option('invoice_history_page'); |
|
219 | + if ($wpinv_history_page_id > 0) { |
|
220 | 220 | $item = new stdClass(); |
221 | 221 | $item->object_id = $wpinv_history_page_id; |
222 | 222 | $item->db_id = 0; |
223 | - $item->object = 'page'; |
|
223 | + $item->object = 'page'; |
|
224 | 224 | $item->menu_item_parent = 0; |
225 | 225 | $item->type = 'post_type'; |
226 | - $item->title = __('Invoice History Page','invoicing'); |
|
227 | - $item->url = get_permalink( $wpinv_history_page_id ); |
|
226 | + $item->title = __('Invoice History Page', 'invoicing'); |
|
227 | + $item->url = get_permalink($wpinv_history_page_id); |
|
228 | 228 | $item->target = ''; |
229 | 229 | $item->attr_title = ''; |
230 | 230 | $item->classes = array('wpinv-menu-item'); |
@@ -233,16 +233,16 @@ discard block |
||
233 | 233 | $items['pages'][] = $item; |
234 | 234 | } |
235 | 235 | |
236 | - $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' ); |
|
237 | - if($wpinv_sub_history_page_id > 0){ |
|
236 | + $wpinv_sub_history_page_id = (int) wpinv_get_option('invoice_subscription_page'); |
|
237 | + if ($wpinv_sub_history_page_id > 0) { |
|
238 | 238 | $item = new stdClass(); |
239 | 239 | $item->object_id = $wpinv_sub_history_page_id; |
240 | 240 | $item->db_id = 0; |
241 | - $item->object = 'page'; |
|
241 | + $item->object = 'page'; |
|
242 | 242 | $item->menu_item_parent = 0; |
243 | 243 | $item->type = 'post_type'; |
244 | - $item->title = __('Invoice Subscriptions Page','invoicing'); |
|
245 | - $item->url = get_permalink( $wpinv_sub_history_page_id ); |
|
244 | + $item->title = __('Invoice Subscriptions Page', 'invoicing'); |
|
245 | + $item->url = get_permalink($wpinv_sub_history_page_id); |
|
246 | 246 | $item->target = ''; |
247 | 247 | $item->attr_title = ''; |
248 | 248 | $item->classes = array('wpinv-menu-item'); |
@@ -251,16 +251,16 @@ discard block |
||
251 | 251 | $items['pages'][] = $item; |
252 | 252 | } |
253 | 253 | |
254 | - $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' ); |
|
255 | - if($wpinv_checkout_page_id > 0){ |
|
254 | + $wpinv_checkout_page_id = (int) wpinv_get_option('checkout_page'); |
|
255 | + if ($wpinv_checkout_page_id > 0) { |
|
256 | 256 | $item = new stdClass(); |
257 | 257 | $item->object_id = $wpinv_checkout_page_id; |
258 | 258 | $item->db_id = 0; |
259 | - $item->object = 'page'; |
|
259 | + $item->object = 'page'; |
|
260 | 260 | $item->menu_item_parent = 0; |
261 | 261 | $item->type = 'post_type'; |
262 | - $item->title = __('Checkout Page','invoicing'); |
|
263 | - $item->url = get_permalink( $wpinv_checkout_page_id ); |
|
262 | + $item->title = __('Checkout Page', 'invoicing'); |
|
263 | + $item->url = get_permalink($wpinv_checkout_page_id); |
|
264 | 264 | $item->target = ''; |
265 | 265 | $item->attr_title = ''; |
266 | 266 | $item->classes = array('wpinv-menu-item'); |
@@ -269,16 +269,16 @@ discard block |
||
269 | 269 | $items['pages'][] = $item; |
270 | 270 | } |
271 | 271 | |
272 | - $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' ); |
|
273 | - if($wpinv_tandc_page_id > 0){ |
|
272 | + $wpinv_tandc_page_id = (int) wpinv_get_option('tandc_page'); |
|
273 | + if ($wpinv_tandc_page_id > 0) { |
|
274 | 274 | $item = new stdClass(); |
275 | 275 | $item->object_id = $wpinv_tandc_page_id; |
276 | 276 | $item->db_id = 0; |
277 | - $item->object = 'page'; |
|
277 | + $item->object = 'page'; |
|
278 | 278 | $item->menu_item_parent = 0; |
279 | 279 | $item->type = 'post_type'; |
280 | - $item->title = __('Terms & Conditions','invoicing'); |
|
281 | - $item->url = get_permalink( $wpinv_tandc_page_id ); |
|
280 | + $item->title = __('Terms & Conditions', 'invoicing'); |
|
281 | + $item->url = get_permalink($wpinv_tandc_page_id); |
|
282 | 282 | $item->target = ''; |
283 | 283 | $item->attr_title = ''; |
284 | 284 | $item->classes = array('wpinv-menu-item'); |
@@ -287,16 +287,16 @@ discard block |
||
287 | 287 | $items['pages'][] = $item; |
288 | 288 | } |
289 | 289 | |
290 | - $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' ); |
|
291 | - if($wpinv_success_page_id > 0){ |
|
290 | + $wpinv_success_page_id = (int) wpinv_get_option('success_page'); |
|
291 | + if ($wpinv_success_page_id > 0) { |
|
292 | 292 | $item = new stdClass(); |
293 | 293 | $item->object_id = $wpinv_success_page_id; |
294 | 294 | $item->db_id = 0; |
295 | - $item->object = 'page'; |
|
295 | + $item->object = 'page'; |
|
296 | 296 | $item->menu_item_parent = 0; |
297 | 297 | $item->type = 'post_type'; |
298 | - $item->title = __('Success Page','invoicing'); |
|
299 | - $item->url = get_permalink( $wpinv_success_page_id ); |
|
298 | + $item->title = __('Success Page', 'invoicing'); |
|
299 | + $item->url = get_permalink($wpinv_success_page_id); |
|
300 | 300 | $item->target = ''; |
301 | 301 | $item->attr_title = ''; |
302 | 302 | $item->classes = array('wpinv-menu-item'); |
@@ -305,16 +305,16 @@ discard block |
||
305 | 305 | $items['pages'][] = $item; |
306 | 306 | } |
307 | 307 | |
308 | - $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' ); |
|
309 | - if($wpinv_failure_page_id > 0){ |
|
308 | + $wpinv_failure_page_id = (int) wpinv_get_option('failure_page'); |
|
309 | + if ($wpinv_failure_page_id > 0) { |
|
310 | 310 | $item = new stdClass(); |
311 | 311 | $item->object_id = $wpinv_failure_page_id; |
312 | 312 | $item->db_id = 0; |
313 | - $item->object = 'page'; |
|
313 | + $item->object = 'page'; |
|
314 | 314 | $item->menu_item_parent = 0; |
315 | 315 | $item->type = 'post_type'; |
316 | - $item->title = __('Failed Transaction Page','invoicing'); |
|
317 | - $item->url = get_permalink( $wpinv_failure_page_id ); |
|
316 | + $item->title = __('Failed Transaction Page', 'invoicing'); |
|
317 | + $item->url = get_permalink($wpinv_failure_page_id); |
|
318 | 318 | $item->target = ''; |
319 | 319 | $item->attr_title = ''; |
320 | 320 | $item->classes = array('wpinv-menu-item'); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $items['pages'][] = $item; |
324 | 324 | } |
325 | 325 | |
326 | - return apply_filters( 'wpinv_menu_items', $items ); |
|
326 | + return apply_filters('wpinv_menu_items', $items); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | } |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | function wpinv_subscription_init() { |
6 | 6 | return WPInv_Subscriptions::instance(); |
7 | 7 | } |
8 | -add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 ); |
|
8 | +add_action('plugins_loaded', 'wpinv_subscription_init', 100); |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * WPInv_Subscriptions Class. |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * Main WPInv_Subscriptions Instance |
21 | 21 | */ |
22 | 22 | public static function instance() { |
23 | - if ( ! isset( self::$instance ) ) { |
|
23 | + if (!isset(self::$instance)) { |
|
24 | 24 | self::$instance = new WPInv_Subscriptions; |
25 | 25 | |
26 | 26 | self::$instance->init(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | - private function __construct(){ |
|
37 | + private function __construct() { |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | private function setup_constants() { |
64 | 64 | |
65 | 65 | // Make sure CAL_GREGORIAN is defined. |
66 | - if ( ! defined( 'CAL_GREGORIAN' ) ) { |
|
67 | - define( 'CAL_GREGORIAN', 1 ); |
|
66 | + if (!defined('CAL_GREGORIAN')) { |
|
67 | + define('CAL_GREGORIAN', 1); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | */ |
77 | 77 | private function actions() { |
78 | 78 | |
79 | - add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 40 ); |
|
80 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
81 | - add_action( 'init', array( $this, 'wpinv_post_actions' ) ); |
|
82 | - add_action( 'init', array( $this, 'wpinv_get_actions' ) ); |
|
83 | - add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) ); |
|
84 | - add_action( 'wpinv_checkout_before_send_to_gateway', array( $this, 'wpinv_checkout_add_subscription' ), -999, 2 ); |
|
85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) ); |
|
79 | + add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 40); |
|
80 | + add_action('admin_notices', array($this, 'notices')); |
|
81 | + add_action('init', array($this, 'wpinv_post_actions')); |
|
82 | + add_action('init', array($this, 'wpinv_get_actions')); |
|
83 | + add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation')); |
|
84 | + add_action('wpinv_checkout_before_send_to_gateway', array($this, 'wpinv_checkout_add_subscription'), -999, 2); |
|
85 | + add_action('wpinv_subscriptions_front_notices', array($this, 'notices')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | public function wpinv_subscriptions_list() { |
105 | 105 | add_submenu_page( |
106 | 106 | 'wpinv', |
107 | - __( 'Subscriptions', 'invoicing' ), |
|
108 | - __( 'Subscriptions', 'invoicing' ), |
|
107 | + __('Subscriptions', 'invoicing'), |
|
108 | + __('Subscriptions', 'invoicing'), |
|
109 | 109 | wpinv_get_capability(), |
110 | 110 | 'wpinv-subscriptions', |
111 | 111 | 'wpinv_subscriptions_page' |
@@ -114,37 +114,37 @@ discard block |
||
114 | 114 | |
115 | 115 | public function notices() { |
116 | 116 | |
117 | - if( empty( $_GET['wpinv-message'] ) ) { |
|
117 | + if (empty($_GET['wpinv-message'])) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | $type = 'updated'; |
122 | 122 | $message = ''; |
123 | 123 | |
124 | - switch( strtolower( $_GET['wpinv-message'] ) ) { |
|
124 | + switch (strtolower($_GET['wpinv-message'])) { |
|
125 | 125 | |
126 | 126 | case 'updated' : |
127 | 127 | |
128 | - $message = __( 'Subscription updated successfully.', 'invoicing' ); |
|
128 | + $message = __('Subscription updated successfully.', 'invoicing'); |
|
129 | 129 | |
130 | 130 | break; |
131 | 131 | |
132 | 132 | case 'deleted' : |
133 | 133 | |
134 | - $message = __( 'Subscription deleted successfully.', 'invoicing' ); |
|
134 | + $message = __('Subscription deleted successfully.', 'invoicing'); |
|
135 | 135 | |
136 | 136 | break; |
137 | 137 | |
138 | 138 | case 'cancelled' : |
139 | 139 | |
140 | - $message = __( 'Subscription cancelled successfully.', 'invoicing' ); |
|
140 | + $message = __('Subscription cancelled successfully.', 'invoicing'); |
|
141 | 141 | |
142 | 142 | break; |
143 | 143 | |
144 | 144 | } |
145 | 145 | |
146 | - if ( ! empty( $message ) ) { |
|
147 | - echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>'; |
|
146 | + if (!empty($message)) { |
|
147 | + echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>'; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @return void |
158 | 158 | */ |
159 | 159 | function wpinv_get_actions() { |
160 | - if ( isset( $_GET['wpinv_action'] ) ) { |
|
161 | - do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET ); |
|
160 | + if (isset($_GET['wpinv_action'])) { |
|
161 | + do_action('wpinv_' . $_GET['wpinv_action'], $_GET); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * @return void |
171 | 171 | */ |
172 | 172 | function wpinv_post_actions() { |
173 | - if ( isset( $_POST['wpinv_action'] ) ) { |
|
174 | - do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST ); |
|
173 | + if (isset($_POST['wpinv_action'])) { |
|
174 | + do_action('wpinv_' . $_POST['wpinv_action'], $_POST); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -182,24 +182,24 @@ discard block |
||
182 | 182 | * @param int $frequency_count The frequency of the period. |
183 | 183 | * @return mixed|string|void |
184 | 184 | */ |
185 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) { |
|
185 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
186 | 186 | $frequency = ''; |
187 | 187 | //Format period details |
188 | - switch ( $period ) { |
|
188 | + switch ($period) { |
|
189 | 189 | case 'day' : |
190 | - $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
190 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
191 | 191 | break; |
192 | 192 | case 'week' : |
193 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
193 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
194 | 194 | break; |
195 | 195 | case 'month' : |
196 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
196 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
197 | 197 | break; |
198 | 198 | case 'year' : |
199 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
199 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
200 | 200 | break; |
201 | 201 | default : |
202 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
202 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
203 | 203 | break; |
204 | 204 | } |
205 | 205 | |
@@ -214,50 +214,50 @@ discard block |
||
214 | 214 | * @since 1.0.0 |
215 | 215 | * @return void |
216 | 216 | */ |
217 | - public function wpinv_process_cancellation( $data ) { |
|
217 | + public function wpinv_process_cancellation($data) { |
|
218 | 218 | |
219 | 219 | |
220 | - if( empty( $data['sub_id'] ) ) { |
|
220 | + if (empty($data['sub_id'])) { |
|
221 | 221 | return; |
222 | 222 | } |
223 | 223 | |
224 | - if( ! is_user_logged_in() ) { |
|
224 | + if (!is_user_logged_in()) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { |
|
229 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) ); |
|
228 | + if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { |
|
229 | + wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); |
|
230 | 230 | } |
231 | 231 | |
232 | - $data['sub_id'] = absint( $data['sub_id'] ); |
|
233 | - $subscription = new WPInv_Subscription( $data['sub_id'] ); |
|
232 | + $data['sub_id'] = absint($data['sub_id']); |
|
233 | + $subscription = new WPInv_Subscription($data['sub_id']); |
|
234 | 234 | |
235 | - if( ! $subscription->can_cancel() ) { |
|
236 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) ); |
|
235 | + if (!$subscription->can_cancel()) { |
|
236 | + wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | try { |
240 | 240 | |
241 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true ); |
|
241 | + do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); |
|
242 | 242 | |
243 | 243 | $subscription->cancel(); |
244 | 244 | |
245 | - if( is_admin() ) { |
|
245 | + if (is_admin()) { |
|
246 | 246 | |
247 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) ); |
|
247 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); |
|
248 | 248 | exit; |
249 | 249 | |
250 | 250 | } else { |
251 | 251 | |
252 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) ); |
|
253 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription ); |
|
254 | - wp_safe_redirect( $redirect ); |
|
252 | + $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); |
|
253 | + $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); |
|
254 | + wp_safe_redirect($redirect); |
|
255 | 255 | exit; |
256 | 256 | |
257 | 257 | } |
258 | 258 | |
259 | - } catch ( Exception $e ) { |
|
260 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) ); |
|
259 | + } catch (Exception $e) { |
|
260 | + wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | } |
@@ -270,40 +270,40 @@ discard block |
||
270 | 270 | * @since 1.0.0 |
271 | 271 | * @return void |
272 | 272 | */ |
273 | - public function wpinv_checkout_add_subscription( $invoice, $invoice_data ) { |
|
274 | - if ( ! ( ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
273 | + public function wpinv_checkout_add_subscription($invoice, $invoice_data) { |
|
274 | + if (!(!empty($invoice->ID) && $invoice->is_recurring())) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Should we create a subscription for the invoice? |
279 | - if ( apply_filters( 'wpinv_skip_invoice_subscription_creation', false, $invoice ) ) { |
|
279 | + if (apply_filters('wpinv_skip_invoice_subscription_creation', false, $invoice)) { |
|
280 | 280 | return; |
281 | 281 | } |
282 | 282 | |
283 | - $item = $invoice->get_recurring( true ); |
|
284 | - if ( empty( $item ) ) { |
|
283 | + $item = $invoice->get_recurring(true); |
|
284 | + if (empty($item)) { |
|
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
288 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
288 | + $invoice_date = $invoice->get_invoice_date(false); |
|
289 | 289 | $status = 'pending'; |
290 | 290 | |
291 | - $period = $item->get_recurring_period( true ); |
|
291 | + $period = $item->get_recurring_period(true); |
|
292 | 292 | $interval = $item->get_recurring_interval(); |
293 | - $bill_times = (int)$item->get_recurring_limit(); |
|
293 | + $bill_times = (int) $item->get_recurring_limit(); |
|
294 | 294 | $add_period = $interval . ' ' . $period; |
295 | 295 | $trial_period = ''; |
296 | 296 | |
297 | - if ( $invoice->is_free_trial() ) { |
|
297 | + if ($invoice->is_free_trial()) { |
|
298 | 298 | $status = 'trialling'; |
299 | - $trial_period = $item->get_trial_period( true ); |
|
299 | + $trial_period = $item->get_trial_period(true); |
|
300 | 300 | $free_interval = $item->get_trial_interval(); |
301 | 301 | $trial_period = $free_interval . ' ' . $trial_period; |
302 | 302 | |
303 | 303 | $add_period = $trial_period; |
304 | 304 | } |
305 | 305 | |
306 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
306 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
307 | 307 | |
308 | 308 | $args = array( |
309 | 309 | 'product_id' => $item->ID, |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | 'frequency' => $interval, |
314 | 314 | 'period' => $period, |
315 | 315 | 'initial_amount' => $invoice->get_total(), |
316 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
316 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
317 | 317 | 'bill_times' => $bill_times, |
318 | 318 | 'created' => $invoice_date, |
319 | 319 | 'expiration' => $expiration, |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | 'transaction_id' => '', |
323 | 323 | ); |
324 | 324 | |
325 | - $subscription = wpinv_get_subscription( $invoice ); |
|
325 | + $subscription = wpinv_get_subscription($invoice); |
|
326 | 326 | |
327 | - if ( empty( $subscription ) ) { |
|
327 | + if (empty($subscription)) { |
|
328 | 328 | $subscription = new WPInv_Subscription(); |
329 | - $subscription->create( $args ); |
|
329 | + $subscription->create($args); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | return $subscription; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -21,175 +21,175 @@ discard block |
||
21 | 21 | public function init() { |
22 | 22 | global $wp_filesystem; |
23 | 23 | |
24 | - if ( empty( $wp_filesystem ) ) { |
|
25 | - require_once( ABSPATH . '/wp-admin/includes/file.php' ); |
|
24 | + if (empty($wp_filesystem)) { |
|
25 | + require_once(ABSPATH . '/wp-admin/includes/file.php'); |
|
26 | 26 | WP_Filesystem(); |
27 | 27 | global $wp_filesystem; |
28 | 28 | } |
29 | 29 | $this->wp_filesystem = $wp_filesystem; |
30 | 30 | |
31 | 31 | $this->export_dir = $this->export_location(); |
32 | - $this->export_url = $this->export_location( true ); |
|
32 | + $this->export_url = $this->export_location(true); |
|
33 | 33 | $this->export = 'invoicing'; |
34 | 34 | $this->filetype = 'csv'; |
35 | 35 | $this->per_page = 20; |
36 | 36 | |
37 | - do_action( 'wpinv_class_reports_init', $this ); |
|
37 | + do_action('wpinv_class_reports_init', $this); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function includes() { |
41 | - do_action( 'wpinv_class_reports_includes', $this ); |
|
41 | + do_action('wpinv_class_reports_includes', $this); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function actions() { |
45 | - if ( is_admin() ) { |
|
46 | - add_action( 'admin_menu', array( $this, 'add_submenu' ), 20 ); |
|
47 | - add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) ); |
|
48 | - add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) ); |
|
49 | - add_action( 'wp_ajax_wpinv_ajax_discount_use_export', array( $this, 'discount_use_export' ) ); |
|
45 | + if (is_admin()) { |
|
46 | + add_action('admin_menu', array($this, 'add_submenu'), 20); |
|
47 | + add_action('wpinv_reports_tab_export', array($this, 'export')); |
|
48 | + add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export')); |
|
49 | + add_action('wp_ajax_wpinv_ajax_discount_use_export', array($this, 'discount_use_export')); |
|
50 | 50 | |
51 | 51 | // Export Invoices. |
52 | - add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) ); |
|
53 | - add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) ); |
|
54 | - add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) ); |
|
55 | - add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) ); |
|
52 | + add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export')); |
|
53 | + add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns')); |
|
54 | + add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data')); |
|
55 | + add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status')); |
|
56 | 56 | } |
57 | - do_action( 'wpinv_class_reports_actions', $this ); |
|
57 | + do_action('wpinv_class_reports_actions', $this); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public function add_submenu() { |
61 | 61 | global $wpi_reports_page; |
62 | - $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), wpinv_get_capability(), 'wpinv-reports', array( $this, 'reports_page' ) ); |
|
62 | + $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), wpinv_get_capability(), 'wpinv-reports', array($this, 'reports_page')); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | public function reports_page() { |
66 | - if ( !wp_script_is( 'postbox', 'enqueued' ) ) { |
|
67 | - wp_enqueue_script( 'postbox' ); |
|
66 | + if (!wp_script_is('postbox', 'enqueued')) { |
|
67 | + wp_enqueue_script('postbox'); |
|
68 | 68 | } |
69 | - if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) { |
|
70 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
69 | + if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) { |
|
70 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
71 | 71 | } |
72 | 72 | |
73 | - $current_page = admin_url( 'admin.php?page=wpinv-reports' ); |
|
74 | - $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export'; |
|
73 | + $current_page = admin_url('admin.php?page=wpinv-reports'); |
|
74 | + $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export'; |
|
75 | 75 | ?> |
76 | 76 | <div class="wrap wpi-reports-wrap"> |
77 | - <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1> |
|
77 | + <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1> |
|
78 | 78 | <h2 class="nav-tab-wrapper wp-clearfix"> |
79 | - <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a> |
|
80 | - <?php do_action( 'wpinv_reports_page_tabs' ); ;?> |
|
79 | + <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a> |
|
80 | + <?php do_action('wpinv_reports_page_tabs'); ;?> |
|
81 | 81 | </h2> |
82 | - <div class="wpi-reports-content wpi-reports-<?php echo esc_attr( $active_tab ); ?>"> |
|
82 | + <div class="wpi-reports-content wpi-reports-<?php echo esc_attr($active_tab); ?>"> |
|
83 | 83 | <?php |
84 | - do_action( 'wpinv_reports_page_top' ); |
|
85 | - do_action( 'wpinv_reports_tab_' . $active_tab ); |
|
86 | - do_action( 'wpinv_reports_page_bottom' ); |
|
84 | + do_action('wpinv_reports_page_top'); |
|
85 | + do_action('wpinv_reports_tab_' . $active_tab); |
|
86 | + do_action('wpinv_reports_page_bottom'); |
|
87 | 87 | ?> |
88 | 88 | </div> |
89 | 89 | <?php |
90 | 90 | } |
91 | 91 | |
92 | 92 | public function export() { |
93 | - $statuses = wpinv_get_invoice_statuses( true ); |
|
94 | - $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses ); |
|
93 | + $statuses = wpinv_get_invoice_statuses(true); |
|
94 | + $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses); |
|
95 | 95 | ?> |
96 | 96 | <div class="metabox-holder"> |
97 | 97 | <div id="post-body"> |
98 | 98 | <div id="post-body-content"> |
99 | - <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?> |
|
99 | + <?php do_action('wpinv_reports_tab_export_content_top'); ?> |
|
100 | 100 | |
101 | 101 | <div class="postbox wpi-export-invoices"> |
102 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2> |
|
102 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2> |
|
103 | 103 | <div class="inside"> |
104 | - <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p> |
|
104 | + <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p> |
|
105 | 105 | <form id="wpi-export-invoices" class="wpi-export-form" method="post"> |
106 | - <?php echo wpinv_html_date_field( array( |
|
106 | + <?php echo wpinv_html_date_field(array( |
|
107 | 107 | 'id' => 'wpi_export_from_date', |
108 | 108 | 'name' => 'from_date', |
109 | 109 | 'data' => array( |
110 | 110 | 'dateFormat' => 'yy-mm-dd' |
111 | 111 | ), |
112 | - 'placeholder' => __( 'From date', 'invoicing' ) ) |
|
112 | + 'placeholder' => __('From date', 'invoicing') ) |
|
113 | 113 | ); ?> |
114 | - <?php echo wpinv_html_date_field( array( |
|
114 | + <?php echo wpinv_html_date_field(array( |
|
115 | 115 | 'id' => 'wpi_export_to_date', |
116 | 116 | 'name' => 'to_date', |
117 | 117 | 'data' => array( |
118 | 118 | 'dateFormat' => 'yy-mm-dd' |
119 | 119 | ), |
120 | - 'placeholder' => __( 'To date', 'invoicing' ) ) |
|
120 | + 'placeholder' => __('To date', 'invoicing') ) |
|
121 | 121 | ); ?> |
122 | 122 | <span id="wpinv-status-wrap"> |
123 | - <?php echo wpinv_html_select( array( |
|
123 | + <?php echo wpinv_html_select(array( |
|
124 | 124 | 'options' => $statuses, |
125 | 125 | 'name' => 'status', |
126 | 126 | 'id' => 'wpi_export_status', |
127 | 127 | 'show_option_all' => false, |
128 | 128 | 'show_option_none' => false, |
129 | 129 | 'class' => 'wpi_select2', |
130 | - ) ); ?> |
|
131 | - <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?> |
|
130 | + )); ?> |
|
131 | + <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?> |
|
132 | 132 | </span> |
133 | 133 | <span id="wpinv-submit-wrap"> |
134 | 134 | <input type="hidden" value="invoices" name="export" /> |
135 | - <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" /> |
|
135 | + <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" /> |
|
136 | 136 | </span> |
137 | 137 | </form> |
138 | 138 | </div> |
139 | 139 | </div> |
140 | 140 | |
141 | 141 | <div class="postbox wpi-export-discount-uses"> |
142 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Discount Use','invoicing' ); ?></span></h2> |
|
142 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Discount Use', 'invoicing'); ?></span></h2> |
|
143 | 143 | <div class="inside"> |
144 | - <p><?php _e( 'Download a CSV of discount uses.', 'invoicing' ); ?></p> |
|
145 | - <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-ajax.php?action=wpinv_ajax_discount_use_export' ), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export' ) ); ?>"><?php _e( 'Generate CSV', 'invoicing' ); ?></a> |
|
144 | + <p><?php _e('Download a CSV of discount uses.', 'invoicing'); ?></p> |
|
145 | + <a class="button-primary" href="<?php echo esc_url(wp_nonce_url(admin_url('admin-ajax.php?action=wpinv_ajax_discount_use_export'), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export')); ?>"><?php _e('Generate CSV', 'invoicing'); ?></a> |
|
146 | 146 | </div> |
147 | 147 | </div> |
148 | 148 | |
149 | - <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?> |
|
149 | + <?php do_action('wpinv_reports_tab_export_content_bottom'); ?> |
|
150 | 150 | </div> |
151 | 151 | </div> |
152 | 152 | </div> |
153 | 153 | <?php |
154 | 154 | } |
155 | 155 | |
156 | - public function export_location( $relative = false ) { |
|
156 | + public function export_location($relative = false) { |
|
157 | 157 | $upload_dir = wp_upload_dir(); |
158 | - $export_location = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache'; |
|
159 | - $export_location = apply_filters( 'wpinv_export_location', $export_location, $relative ); |
|
158 | + $export_location = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache'; |
|
159 | + $export_location = apply_filters('wpinv_export_location', $export_location, $relative); |
|
160 | 160 | |
161 | - return trailingslashit( $export_location ); |
|
161 | + return trailingslashit($export_location); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | public function check_export_location() { |
165 | 165 | try { |
166 | - if ( empty( $this->wp_filesystem ) ) { |
|
167 | - return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' ); |
|
166 | + if (empty($this->wp_filesystem)) { |
|
167 | + return __('Filesystem ERROR: Could not access filesystem.', 'invoicing'); |
|
168 | 168 | } |
169 | 169 | |
170 | - if ( is_wp_error( $this->wp_filesystem ) ) { |
|
171 | - return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' ); |
|
170 | + if (is_wp_error($this->wp_filesystem)) { |
|
171 | + return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing'); |
|
172 | 172 | } |
173 | 173 | |
174 | - $is_dir = $this->wp_filesystem->is_dir( $this->export_dir ); |
|
175 | - $is_writeable = $is_dir && is_writeable( $this->export_dir ); |
|
174 | + $is_dir = $this->wp_filesystem->is_dir($this->export_dir); |
|
175 | + $is_writeable = $is_dir && is_writeable($this->export_dir); |
|
176 | 176 | |
177 | - if ( $is_dir && $is_writeable ) { |
|
177 | + if ($is_dir && $is_writeable) { |
|
178 | 178 | return true; |
179 | - } else if ( $is_dir && !$is_writeable ) { |
|
180 | - if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
181 | - return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir ); |
|
179 | + } else if ($is_dir && !$is_writeable) { |
|
180 | + if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) { |
|
181 | + return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return true; |
185 | 185 | } else { |
186 | - if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
187 | - return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir ); |
|
186 | + if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) { |
|
187 | + return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return true; |
191 | 191 | } |
192 | - } catch ( Exception $e ) { |
|
192 | + } catch (Exception $e) { |
|
193 | 193 | return $e->getMessage(); |
194 | 194 | } |
195 | 195 | } |
@@ -197,59 +197,59 @@ discard block |
||
197 | 197 | public function ajax_export() { |
198 | 198 | $response = array(); |
199 | 199 | $response['success'] = false; |
200 | - $response['msg'] = __( 'Invalid export request found.', 'invoicing' ); |
|
200 | + $response['msg'] = __('Invalid export request found.', 'invoicing'); |
|
201 | 201 | |
202 | - if ( empty( $_POST['data'] ) || ! wpinv_current_user_can_manage_invoicing() ) { |
|
203 | - wp_send_json( $response ); |
|
202 | + if (empty($_POST['data']) || !wpinv_current_user_can_manage_invoicing()) { |
|
203 | + wp_send_json($response); |
|
204 | 204 | } |
205 | 205 | |
206 | - parse_str( $_POST['data'], $data ); |
|
206 | + parse_str($_POST['data'], $data); |
|
207 | 207 | |
208 | - $data['step'] = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; |
|
208 | + $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1; |
|
209 | 209 | |
210 | - $_REQUEST = (array)$data; |
|
211 | - if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) { |
|
212 | - $response['msg'] = __( 'Security check failed.', 'invoicing' ); |
|
213 | - wp_send_json( $response ); |
|
210 | + $_REQUEST = (array) $data; |
|
211 | + if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) { |
|
212 | + $response['msg'] = __('Security check failed.', 'invoicing'); |
|
213 | + wp_send_json($response); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( ( $error = $this->check_export_location( true ) ) !== true ) { |
|
217 | - $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' ); |
|
218 | - wp_send_json( $response ); |
|
216 | + if (($error = $this->check_export_location(true)) !== true) { |
|
217 | + $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing'); |
|
218 | + wp_send_json($response); |
|
219 | 219 | } |
220 | 220 | |
221 | - $this->set_export_params( $_REQUEST ); |
|
221 | + $this->set_export_params($_REQUEST); |
|
222 | 222 | |
223 | 223 | $return = $this->process_export_step(); |
224 | 224 | $done = $this->get_export_status(); |
225 | 225 | |
226 | - if ( $return ) { |
|
226 | + if ($return) { |
|
227 | 227 | $this->step += 1; |
228 | 228 | |
229 | 229 | $response['success'] = true; |
230 | 230 | $response['msg'] = ''; |
231 | 231 | |
232 | - if ( $done >= 100 ) { |
|
232 | + if ($done >= 100) { |
|
233 | 233 | $this->step = 'done'; |
234 | - $new_filename = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype; |
|
234 | + $new_filename = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype; |
|
235 | 235 | $new_file = $this->export_dir . $new_filename; |
236 | 236 | |
237 | - if ( file_exists( $this->file ) ) { |
|
238 | - $this->wp_filesystem->move( $this->file, $new_file, true ); |
|
237 | + if (file_exists($this->file)) { |
|
238 | + $this->wp_filesystem->move($this->file, $new_file, true); |
|
239 | 239 | } |
240 | 240 | |
241 | - if ( file_exists( $new_file ) ) { |
|
242 | - $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) ); |
|
241 | + if (file_exists($new_file)) { |
|
242 | + $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2)); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | 246 | $response['data']['step'] = $this->step; |
247 | 247 | $response['data']['done'] = $done; |
248 | 248 | } else { |
249 | - $response['msg'] = __( 'No data found for export.', 'invoicing' ); |
|
249 | + $response['msg'] = __('No data found for export.', 'invoicing'); |
|
250 | 250 | } |
251 | 251 | |
252 | - wp_send_json( $response ); |
|
252 | + wp_send_json($response); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function discount_use_export() { |
259 | 259 | |
260 | - if ( ! wp_verify_nonce( $_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export' ) || ! wpinv_current_user_can_manage_invoicing() ) { |
|
260 | + if (!wp_verify_nonce($_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export') || !wpinv_current_user_can_manage_invoicing()) { |
|
261 | 261 | wp_die( -1, 403 ); |
262 | 262 | } |
263 | 263 | |
@@ -267,115 +267,115 @@ discard block |
||
267 | 267 | 'posts_per_page' => -1, |
268 | 268 | ); |
269 | 269 | |
270 | - $discounts = get_posts( $args ); |
|
270 | + $discounts = get_posts($args); |
|
271 | 271 | |
272 | - if ( empty( $discounts ) ) { |
|
273 | - die ( __( 'You have not set up any discounts', 'invoicing' ) ); |
|
272 | + if (empty($discounts)) { |
|
273 | + die (__('You have not set up any discounts', 'invoicing')); |
|
274 | 274 | } |
275 | 275 | |
276 | - $output = fopen( 'php://output', 'w' ) or die( 'Unsupported server' ); |
|
276 | + $output = fopen('php://output', 'w') or die('Unsupported server'); |
|
277 | 277 | |
278 | 278 | // Let the browser know what content we're streaming and how it should save the content. |
279 | 279 | $name = time(); |
280 | - header( "Content-Type:application/csv" ); |
|
281 | - header( "Content-Disposition:attachment;filename=noptin-subscribers-$name.csv" ); |
|
280 | + header("Content-Type:application/csv"); |
|
281 | + header("Content-Disposition:attachment;filename=noptin-subscribers-$name.csv"); |
|
282 | 282 | |
283 | 283 | // Output the csv column headers. |
284 | 284 | fputcsv( |
285 | 285 | $output, |
286 | 286 | array( |
287 | - __( 'Discount Id', 'invoicing' ), |
|
288 | - __( 'Discount Code', 'invoicing' ), |
|
289 | - __( 'Discount Type', 'invoicing' ), |
|
290 | - __( 'Discount Amount', 'invoicing' ), |
|
291 | - __( 'Uses', 'invoicing' ), |
|
287 | + __('Discount Id', 'invoicing'), |
|
288 | + __('Discount Code', 'invoicing'), |
|
289 | + __('Discount Type', 'invoicing'), |
|
290 | + __('Discount Amount', 'invoicing'), |
|
291 | + __('Uses', 'invoicing'), |
|
292 | 292 | ) |
293 | 293 | ); |
294 | 294 | |
295 | - foreach ( $discounts as $discount ) { |
|
295 | + foreach ($discounts as $discount) { |
|
296 | 296 | |
297 | 297 | $discount = (int) $discount; |
298 | 298 | $row = array( |
299 | 299 | $discount, |
300 | - get_post_meta( $discount, '_wpi_discount_code', true ), |
|
301 | - get_post_meta( $discount, '_wpi_discount_type', true ), |
|
302 | - get_post_meta( $discount, '_wpi_discount_amount', true ), |
|
303 | - (int) get_post_meta( $discount, '_wpi_discount_uses', true ) |
|
300 | + get_post_meta($discount, '_wpi_discount_code', true), |
|
301 | + get_post_meta($discount, '_wpi_discount_type', true), |
|
302 | + get_post_meta($discount, '_wpi_discount_amount', true), |
|
303 | + (int) get_post_meta($discount, '_wpi_discount_uses', true) |
|
304 | 304 | ); |
305 | - fputcsv( $output, $row ); |
|
305 | + fputcsv($output, $row); |
|
306 | 306 | } |
307 | 307 | |
308 | - fclose( $output ); |
|
308 | + fclose($output); |
|
309 | 309 | exit; |
310 | 310 | |
311 | 311 | } |
312 | 312 | |
313 | - public function set_export_params( $request ) { |
|
313 | + public function set_export_params($request) { |
|
314 | 314 | $this->empty = false; |
315 | - $this->step = !empty( $request['step'] ) ? absint( $request['step'] ) : 1; |
|
316 | - $this->export = !empty( $request['export'] ) ? $request['export'] : $this->export; |
|
315 | + $this->step = !empty($request['step']) ? absint($request['step']) : 1; |
|
316 | + $this->export = !empty($request['export']) ? $request['export'] : $this->export; |
|
317 | 317 | $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype; |
318 | 318 | $this->file = $this->export_dir . $this->filename; |
319 | 319 | |
320 | - do_action( 'wpinv_export_set_params_' . $this->export, $request ); |
|
320 | + do_action('wpinv_export_set_params_' . $this->export, $request); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | public function get_columns() { |
324 | 324 | $columns = array(); |
325 | 325 | |
326 | - return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns ); |
|
326 | + return apply_filters('wpinv_export_get_columns_' . $this->export, $columns); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | protected function get_export_file() { |
330 | 330 | $file = ''; |
331 | 331 | |
332 | - if ( $this->wp_filesystem->exists( $this->file ) ) { |
|
333 | - $file = $this->wp_filesystem->get_contents( $this->file ); |
|
332 | + if ($this->wp_filesystem->exists($this->file)) { |
|
333 | + $file = $this->wp_filesystem->get_contents($this->file); |
|
334 | 334 | } else { |
335 | - $this->wp_filesystem->put_contents( $this->file, '' ); |
|
335 | + $this->wp_filesystem->put_contents($this->file, ''); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | return $file; |
339 | 339 | } |
340 | 340 | |
341 | - protected function attach_export_data( $data = '' ) { |
|
342 | - $filedata = $this->get_export_file(); |
|
343 | - $filedata .= $data; |
|
341 | + protected function attach_export_data($data = '') { |
|
342 | + $filedata = $this->get_export_file(); |
|
343 | + $filedata .= $data; |
|
344 | 344 | |
345 | - $this->wp_filesystem->put_contents( $this->file, $filedata ); |
|
345 | + $this->wp_filesystem->put_contents($this->file, $filedata); |
|
346 | 346 | |
347 | - $rows = file( $this->file, FILE_SKIP_EMPTY_LINES ); |
|
347 | + $rows = file($this->file, FILE_SKIP_EMPTY_LINES); |
|
348 | 348 | $columns = $this->get_columns(); |
349 | - $columns = empty( $columns ) ? 0 : 1; |
|
349 | + $columns = empty($columns) ? 0 : 1; |
|
350 | 350 | |
351 | - $this->empty = count( $rows ) == $columns ? true : false; |
|
351 | + $this->empty = count($rows) == $columns ? true : false; |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | public function print_columns() { |
355 | 355 | $column_data = ''; |
356 | 356 | $columns = $this->get_columns(); |
357 | 357 | $i = 1; |
358 | - foreach( $columns as $key => $column ) { |
|
359 | - $column_data .= '"' . addslashes( $column ) . '"'; |
|
360 | - $column_data .= $i == count( $columns ) ? '' : ','; |
|
358 | + foreach ($columns as $key => $column) { |
|
359 | + $column_data .= '"' . addslashes($column) . '"'; |
|
360 | + $column_data .= $i == count($columns) ? '' : ','; |
|
361 | 361 | $i++; |
362 | 362 | } |
363 | 363 | $column_data .= "\r\n"; |
364 | 364 | |
365 | - $this->attach_export_data( $column_data ); |
|
365 | + $this->attach_export_data($column_data); |
|
366 | 366 | |
367 | 367 | return $column_data; |
368 | 368 | } |
369 | 369 | |
370 | 370 | public function process_export_step() { |
371 | - if ( $this->step < 2 ) { |
|
372 | - /** @scrutinizer ignore-unhandled */ @unlink( $this->file ); |
|
371 | + if ($this->step < 2) { |
|
372 | + /** @scrutinizer ignore-unhandled */ @unlink($this->file); |
|
373 | 373 | $this->print_columns(); |
374 | 374 | } |
375 | 375 | |
376 | 376 | $return = $this->print_rows(); |
377 | 377 | |
378 | - if ( $return ) { |
|
378 | + if ($return) { |
|
379 | 379 | return true; |
380 | 380 | } else { |
381 | 381 | return false; |
@@ -384,14 +384,14 @@ discard block |
||
384 | 384 | |
385 | 385 | public function get_export_status() { |
386 | 386 | $status = 100; |
387 | - return apply_filters( 'wpinv_get_export_status_' . $this->export, $status ); |
|
387 | + return apply_filters('wpinv_get_export_status_' . $this->export, $status); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | public function get_export_data() { |
391 | 391 | $data = array(); |
392 | 392 | |
393 | - $data = apply_filters( 'wpinv_export_get_data', $data ); |
|
394 | - $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data ); |
|
393 | + $data = apply_filters('wpinv_export_get_data', $data); |
|
394 | + $data = apply_filters('wpinv_export_get_data_' . $this->export, $data); |
|
395 | 395 | |
396 | 396 | return $data; |
397 | 397 | } |
@@ -401,20 +401,20 @@ discard block |
||
401 | 401 | $data = $this->get_export_data(); |
402 | 402 | $columns = $this->get_columns(); |
403 | 403 | |
404 | - if ( $data ) { |
|
405 | - foreach ( $data as $row ) { |
|
404 | + if ($data) { |
|
405 | + foreach ($data as $row) { |
|
406 | 406 | $i = 1; |
407 | - foreach ( $row as $key => $column ) { |
|
408 | - if ( array_key_exists( $key, $columns ) ) { |
|
409 | - $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"'; |
|
410 | - $row_data .= $i == count( $columns ) ? '' : ','; |
|
407 | + foreach ($row as $key => $column) { |
|
408 | + if (array_key_exists($key, $columns)) { |
|
409 | + $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"'; |
|
410 | + $row_data .= $i == count($columns) ? '' : ','; |
|
411 | 411 | $i++; |
412 | 412 | } |
413 | 413 | } |
414 | 414 | $row_data .= "\r\n"; |
415 | 415 | } |
416 | 416 | |
417 | - $this->attach_export_data( $row_data ); |
|
417 | + $this->attach_export_data($row_data); |
|
418 | 418 | |
419 | 419 | return $row_data; |
420 | 420 | } |
@@ -423,48 +423,48 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | // Export Invoices. |
426 | - public function set_invoices_export( $request ) { |
|
427 | - $this->from_date = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : ''; |
|
428 | - $this->to_date = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : ''; |
|
429 | - $this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish'; |
|
426 | + public function set_invoices_export($request) { |
|
427 | + $this->from_date = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : ''; |
|
428 | + $this->to_date = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : ''; |
|
429 | + $this->status = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish'; |
|
430 | 430 | } |
431 | 431 | |
432 | - public function get_invoices_columns( $columns = array() ) { |
|
432 | + public function get_invoices_columns($columns = array()) { |
|
433 | 433 | $columns = array( |
434 | - 'id' => __( 'ID', 'invoicing' ), |
|
435 | - 'number' => __( 'Number', 'invoicing' ), |
|
436 | - 'date' => __( 'Date', 'invoicing' ), |
|
437 | - 'due_date' => __( 'Due Date', 'invoicing' ), |
|
438 | - 'completed_date'=> __( 'Payment Done Date', 'invoicing' ), |
|
439 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
440 | - 'currency' => __( 'Currency', 'invoicing' ), |
|
441 | - 'items' => __( 'Items', 'invoicing' ), |
|
442 | - 'status_nicename' => __( 'Status Nicename', 'invoicing' ), |
|
443 | - 'status' => __( 'Status', 'invoicing' ), |
|
444 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
445 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
446 | - 'user_id' => __( 'User ID', 'invoicing' ), |
|
447 | - 'email' => __( 'Email', 'invoicing' ), |
|
448 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
449 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
450 | - 'address' => __( 'Address', 'invoicing' ), |
|
451 | - 'city' => __( 'City', 'invoicing' ), |
|
452 | - 'state' => __( 'State', 'invoicing' ), |
|
453 | - 'country' => __( 'Country', 'invoicing' ), |
|
454 | - 'zip' => __( 'Zipcode', 'invoicing' ), |
|
455 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
456 | - 'company' => __( 'Company', 'invoicing' ), |
|
457 | - 'vat_number' => __( 'Vat Number', 'invoicing' ), |
|
458 | - 'ip' => __( 'IP', 'invoicing' ), |
|
459 | - 'gateway' => __( 'Gateway', 'invoicing' ), |
|
460 | - 'gateway_nicename' => __( 'Gateway Nicename', 'invoicing' ), |
|
461 | - 'transaction_id'=> __( 'Transaction ID', 'invoicing' ), |
|
434 | + 'id' => __('ID', 'invoicing'), |
|
435 | + 'number' => __('Number', 'invoicing'), |
|
436 | + 'date' => __('Date', 'invoicing'), |
|
437 | + 'due_date' => __('Due Date', 'invoicing'), |
|
438 | + 'completed_date'=> __('Payment Done Date', 'invoicing'), |
|
439 | + 'amount' => __('Amount', 'invoicing'), |
|
440 | + 'currency' => __('Currency', 'invoicing'), |
|
441 | + 'items' => __('Items', 'invoicing'), |
|
442 | + 'status_nicename' => __('Status Nicename', 'invoicing'), |
|
443 | + 'status' => __('Status', 'invoicing'), |
|
444 | + 'tax' => __('Tax', 'invoicing'), |
|
445 | + 'discount' => __('Discount', 'invoicing'), |
|
446 | + 'user_id' => __('User ID', 'invoicing'), |
|
447 | + 'email' => __('Email', 'invoicing'), |
|
448 | + 'first_name' => __('First Name', 'invoicing'), |
|
449 | + 'last_name' => __('Last Name', 'invoicing'), |
|
450 | + 'address' => __('Address', 'invoicing'), |
|
451 | + 'city' => __('City', 'invoicing'), |
|
452 | + 'state' => __('State', 'invoicing'), |
|
453 | + 'country' => __('Country', 'invoicing'), |
|
454 | + 'zip' => __('Zipcode', 'invoicing'), |
|
455 | + 'phone' => __('Phone', 'invoicing'), |
|
456 | + 'company' => __('Company', 'invoicing'), |
|
457 | + 'vat_number' => __('Vat Number', 'invoicing'), |
|
458 | + 'ip' => __('IP', 'invoicing'), |
|
459 | + 'gateway' => __('Gateway', 'invoicing'), |
|
460 | + 'gateway_nicename' => __('Gateway Nicename', 'invoicing'), |
|
461 | + 'transaction_id'=> __('Transaction ID', 'invoicing'), |
|
462 | 462 | ); |
463 | 463 | |
464 | 464 | return $columns; |
465 | 465 | } |
466 | 466 | |
467 | - public function get_invoices_data( $response = array() ) { |
|
467 | + public function get_invoices_data($response = array()) { |
|
468 | 468 | $args = array( |
469 | 469 | 'limit' => $this->per_page, |
470 | 470 | 'page' => $this->step, |
@@ -472,42 +472,42 @@ discard block |
||
472 | 472 | 'orderby' => 'date', |
473 | 473 | ); |
474 | 474 | |
475 | - if ( $this->status != 'any' ) { |
|
475 | + if ($this->status != 'any') { |
|
476 | 476 | $args['status'] = $this->status; |
477 | 477 | } else { |
478 | - $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
478 | + $args['status'] = array_keys(wpinv_get_invoice_statuses(true)); |
|
479 | 479 | } |
480 | 480 | |
481 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
481 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
482 | 482 | $args['date_query'] = array( |
483 | 483 | array( |
484 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
485 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
484 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
485 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
486 | 486 | 'inclusive' => true |
487 | 487 | ) |
488 | 488 | ); |
489 | 489 | } |
490 | 490 | |
491 | - $invoices = wpinv_get_invoices( $args ); |
|
491 | + $invoices = wpinv_get_invoices($args); |
|
492 | 492 | |
493 | 493 | $data = array(); |
494 | 494 | |
495 | - if ( !empty( $invoices ) ) { |
|
496 | - foreach ( $invoices as $invoice ) { |
|
495 | + if (!empty($invoices)) { |
|
496 | + foreach ($invoices as $invoice) { |
|
497 | 497 | $items = $this->get_invoice_items($invoice); |
498 | 498 | $row = array( |
499 | 499 | 'id' => $invoice->ID, |
500 | 500 | 'number' => $invoice->get_number(), |
501 | - 'date' => $invoice->get_invoice_date( false ), |
|
502 | - 'due_date' => $invoice->get_due_date( false ), |
|
501 | + 'date' => $invoice->get_invoice_date(false), |
|
502 | + 'due_date' => $invoice->get_due_date(false), |
|
503 | 503 | 'completed_date'=> $invoice->get_completed_date(), |
504 | - 'amount' => wpinv_round_amount( $invoice->get_total() ), |
|
504 | + 'amount' => wpinv_round_amount($invoice->get_total()), |
|
505 | 505 | 'currency' => $invoice->get_currency(), |
506 | 506 | 'items' => $items, |
507 | - 'status_nicename' => $invoice->get_status( true ), |
|
507 | + 'status_nicename' => $invoice->get_status(true), |
|
508 | 508 | 'status' => $invoice->get_status(), |
509 | - 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '', |
|
510 | - 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '', |
|
509 | + 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '', |
|
510 | + 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '', |
|
511 | 511 | 'user_id' => $invoice->get_user_id(), |
512 | 512 | 'email' => $invoice->get_email(), |
513 | 513 | 'first_name' => $invoice->get_first_name(), |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | 'transaction_id'=> $invoice->gateway ? $invoice->get_transaction_id() : '', |
527 | 527 | ); |
528 | 528 | |
529 | - $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice ); |
|
529 | + $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | return $data; |
@@ -542,44 +542,44 @@ discard block |
||
542 | 542 | 'return' => 'ids', |
543 | 543 | ); |
544 | 544 | |
545 | - if ( $this->status != 'any' ) { |
|
545 | + if ($this->status != 'any') { |
|
546 | 546 | $args['status'] = $this->status; |
547 | 547 | } else { |
548 | - $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
548 | + $args['status'] = array_keys(wpinv_get_invoice_statuses(true)); |
|
549 | 549 | } |
550 | 550 | |
551 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
551 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
552 | 552 | $args['date_query'] = array( |
553 | 553 | array( |
554 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
555 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
554 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
555 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
556 | 556 | 'inclusive' => true |
557 | 557 | ) |
558 | 558 | ); |
559 | 559 | } |
560 | 560 | |
561 | - $invoices = wpinv_get_invoices( $args ); |
|
562 | - $total = !empty( $invoices ) ? count( $invoices ) : 0; |
|
561 | + $invoices = wpinv_get_invoices($args); |
|
562 | + $total = !empty($invoices) ? count($invoices) : 0; |
|
563 | 563 | $status = 100; |
564 | 564 | |
565 | - if ( $total > 0 ) { |
|
566 | - $status = ( ( $this->per_page * $this->step ) / $total ) * 100; |
|
565 | + if ($total > 0) { |
|
566 | + $status = (($this->per_page * $this->step) / $total) * 100; |
|
567 | 567 | } |
568 | 568 | |
569 | - if ( $status > 100 ) { |
|
569 | + if ($status > 100) { |
|
570 | 570 | $status = 100; |
571 | 571 | } |
572 | 572 | |
573 | 573 | return $status; |
574 | 574 | } |
575 | 575 | |
576 | - public function get_invoice_items($invoice){ |
|
577 | - if(!$invoice){ |
|
576 | + public function get_invoice_items($invoice) { |
|
577 | + if (!$invoice) { |
|
578 | 578 | return ''; |
579 | 579 | } |
580 | 580 | |
581 | 581 | $cart_details = $invoice->get_cart_details(); |
582 | - if(!empty($cart_details)){ |
|
582 | + if (!empty($cart_details)) { |
|
583 | 583 | $cart_details = maybe_serialize($cart_details); |
584 | 584 | } else { |
585 | 585 | $cart_details = ''; |