|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains functions related to Invoicing plugin. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 1.0.0 |
|
6
|
|
|
* @package Invoicing |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
// MUST have WordPress. |
|
10
|
|
|
if ( !defined( 'WPINC' ) ) { |
|
11
|
|
|
exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
function wpinv_bulk_actions( $actions ) { |
|
15
|
|
|
if ( isset( $actions['edit'] ) ) { |
|
16
|
|
|
unset( $actions['edit'] ); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
return $actions; |
|
20
|
|
|
} |
|
21
|
|
|
add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
22
|
|
|
add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
23
|
|
|
|
|
24
|
|
|
function wpinv_admin_post_id( $id = 0 ) { |
|
25
|
|
|
global $post; |
|
26
|
|
|
|
|
27
|
|
|
if ( isset( $id ) && ! empty( $id ) ) { |
|
28
|
|
|
return (int)$id; |
|
29
|
|
|
} else if ( get_the_ID() ) { |
|
30
|
|
|
return (int) get_the_ID(); |
|
31
|
|
|
} else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
32
|
|
|
return (int) $post->ID; |
|
33
|
|
|
} else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
34
|
|
|
return (int) $_GET['post']; |
|
35
|
|
|
} else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
36
|
|
|
return (int) $_GET['id']; |
|
37
|
|
|
} else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
38
|
|
|
return (int) $_POST['id']; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function wpinv_admin_post_type( $id = 0 ) { |
|
45
|
|
|
if ( !$id ) { |
|
46
|
|
|
$id = wpinv_admin_post_id(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$type = get_post_type( $id ); |
|
50
|
|
|
|
|
51
|
|
|
if ( !$type ) { |
|
52
|
|
|
$type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function wpinv_admin_messages() { |
|
59
|
|
|
global $wpinv_options, $pagenow, $post; |
|
60
|
|
|
|
|
61
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
62
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
66
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
70
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
74
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
78
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
82
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
86
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
90
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
94
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
98
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
102
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
106
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
110
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
114
|
|
|
$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
115
|
|
|
|
|
116
|
|
|
if ( !empty( $message ) ) { |
|
117
|
|
|
add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
settings_errors( 'wpinv-notices' ); |
|
122
|
|
|
} |
|
123
|
|
|
add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
124
|
|
|
|
|
125
|
|
|
add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
126
|
|
|
function wpinv_show_test_payment_gateway_notice(){ |
|
127
|
|
|
add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
function wpinv_test_payment_gateway_messages(){ |
|
131
|
|
|
$gateways = wpinv_get_enabled_payment_gateways(); |
|
132
|
|
|
$name = array(); $test_gateways = ''; |
|
133
|
|
|
if ($gateways) { |
|
134
|
|
|
foreach ($gateways as $id => $gateway) { |
|
135
|
|
|
if (wpinv_is_test_mode($id)) { |
|
136
|
|
|
$name[] = $gateway['checkout_label']; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
$test_gateways = implode(', ', $name); |
|
140
|
|
|
} |
|
141
|
|
|
if(isset($test_gateways) && !empty($test_gateways)){ |
|
142
|
|
|
$link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
143
|
|
|
$notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link ); |
|
144
|
|
|
?> |
|
145
|
|
|
<div class="notice notice-warning is-dismissible"> |
|
146
|
|
|
<p><?php echo $notice; ?></p> |
|
147
|
|
|
</div> |
|
148
|
|
|
<?php |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
function wpinv_items_columns( $existing_columns ) { |
|
153
|
|
|
global $wpinv_euvat; |
|
154
|
|
|
|
|
155
|
|
|
$columns = array(); |
|
156
|
|
|
$columns['cb'] = $existing_columns['cb']; |
|
157
|
|
|
$columns['title'] = __( 'Title', 'invoicing' ); |
|
158
|
|
|
$columns['price'] = __( 'Price', 'invoicing' ); |
|
159
|
|
|
$columns['shortcode'] = __( 'Shortcode', 'invoicing' ); |
|
160
|
|
|
if ( $wpinv_euvat->allow_vat_rules() ) { |
|
161
|
|
|
$columns['vat_rule'] = __( 'VAT rule type', 'invoicing' ); |
|
162
|
|
|
} |
|
163
|
|
|
if ( $wpinv_euvat->allow_vat_classes() ) { |
|
164
|
|
|
$columns['vat_class'] = __( 'VAT class', 'invoicing' ); |
|
165
|
|
|
} |
|
166
|
|
|
$columns['type'] = __( 'Type', 'invoicing' ); |
|
167
|
|
|
$columns['recurring'] = __( 'Recurring', 'invoicing' ); |
|
168
|
|
|
$columns['date'] = __( 'Date', 'invoicing' ); |
|
169
|
|
|
$columns['id'] = __( 'ID', 'invoicing' ); |
|
170
|
|
|
|
|
171
|
|
|
return apply_filters( 'wpinv_items_columns', $columns ); |
|
172
|
|
|
} |
|
173
|
|
|
add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' ); |
|
174
|
|
|
|
|
175
|
|
|
function wpinv_items_sortable_columns( $columns ) { |
|
176
|
|
|
$columns['price'] = 'price'; |
|
177
|
|
|
$columns['vat_rule'] = 'vat_rule'; |
|
178
|
|
|
$columns['vat_class'] = 'vat_class'; |
|
179
|
|
|
$columns['type'] = 'type'; |
|
180
|
|
|
//$columns['recurring'] = 'recurring'; |
|
181
|
|
|
$columns['id'] = 'ID'; |
|
182
|
|
|
|
|
183
|
|
|
return $columns; |
|
184
|
|
|
} |
|
185
|
|
|
add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' ); |
|
186
|
|
|
|
|
187
|
|
|
function wpinv_items_table_custom_column( $column ) { |
|
188
|
|
|
global $wpinv_euvat, $post, $wpi_item; |
|
189
|
|
|
|
|
190
|
|
|
if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) { |
|
191
|
|
|
$wpi_item = new WPInv_Item( $post->ID ); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
switch ( $column ) { |
|
195
|
|
|
case 'price' : |
|
196
|
|
|
echo wpinv_item_price( $post->ID ); |
|
|
|
|
|
|
197
|
|
|
break; |
|
198
|
|
|
case 'vat_rule' : |
|
199
|
|
|
echo $wpinv_euvat->item_rule_label( $post->ID ); |
|
200
|
|
|
break; |
|
201
|
|
|
case 'shortcode' : |
|
202
|
|
|
echo WPInv_Meta_Box_Items::shortcode( $post->ID ); |
|
|
|
|
|
|
203
|
|
|
break; |
|
204
|
|
|
case 'vat_class' : |
|
205
|
|
|
echo $wpinv_euvat->item_class_label( $post->ID ); |
|
206
|
|
|
break; |
|
207
|
|
|
case 'type' : |
|
208
|
|
|
echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
209
|
|
|
break; |
|
210
|
|
|
case 'recurring' : |
|
211
|
|
|
echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' ); |
|
212
|
|
|
break; |
|
213
|
|
|
case 'id' : |
|
214
|
|
|
echo $post->ID; |
|
215
|
|
|
echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
|
216
|
|
|
<div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
|
|
|
|
|
|
217
|
|
|
if ( $wpinv_euvat->allow_vat_rules() ) { |
|
218
|
|
|
echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
|
219
|
|
|
} |
|
220
|
|
|
if ( $wpinv_euvat->allow_vat_classes() ) { |
|
221
|
|
|
echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>'; |
|
222
|
|
|
} |
|
223
|
|
|
echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div> |
|
|
|
|
|
|
224
|
|
|
</div>'; |
|
225
|
|
|
break; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post ); |
|
229
|
|
|
} |
|
230
|
|
|
add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' ); |
|
231
|
|
|
|
|
232
|
|
|
function wpinv_add_items_filters() { |
|
233
|
|
|
global $wpinv_euvat, $typenow; |
|
234
|
|
|
|
|
235
|
|
|
// Checks if the current post type is 'item' |
|
236
|
|
|
if ( $typenow == 'wpi_item') { |
|
237
|
|
|
if ( $wpinv_euvat->allow_vat_rules() ) { |
|
238
|
|
|
|
|
239
|
|
|
// Sanitize selected vat rule. |
|
240
|
|
|
$vat_rule = ''; |
|
|
|
|
|
|
241
|
|
|
if( isset( $_GET['vat_rule'] ) && array_key_exists( $_GET['type'], $wpinv_euvat->get_rules() ) ) { |
|
242
|
|
|
$class = $_GET['type']; |
|
|
|
|
|
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
echo wpinv_html_select( array( |
|
246
|
|
|
'options' => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ), |
|
247
|
|
|
'name' => 'vat_rule', |
|
248
|
|
|
'id' => 'vat_rule', |
|
249
|
|
|
'selected' => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ), |
|
250
|
|
|
'show_option_all' => false, |
|
251
|
|
|
'show_option_none' => false, |
|
252
|
|
|
'class' => 'gdmbx2-text-medium wpi_select2', |
|
253
|
|
|
'placeholder' => __( 'Select VAT rule', 'invoicing' ), |
|
254
|
|
|
) ); |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
if ( $wpinv_euvat->allow_vat_classes() ) { |
|
258
|
|
|
|
|
259
|
|
|
$classes = $wpinv_euvat->get_all_classes(); |
|
260
|
|
|
|
|
261
|
|
|
// Sanitize selected vat class. |
|
262
|
|
|
$class = ''; |
|
263
|
|
|
if( isset( $_GET['vat_class'] ) && array_key_exists( $_GET['vat_class'], $classes ) ) { |
|
264
|
|
|
$class = $_GET['vat_class']; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
echo wpinv_html_select( array( |
|
268
|
|
|
'options' => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $classes ), |
|
269
|
|
|
'name' => 'vat_class', |
|
270
|
|
|
'id' => 'vat_class', |
|
271
|
|
|
'selected' => $class, |
|
272
|
|
|
'show_option_all' => false, |
|
273
|
|
|
'show_option_none' => false, |
|
274
|
|
|
'class' => 'gdmbx2-text-medium wpi_select2', |
|
275
|
|
|
'placeholder' => __( 'Select VAT class', 'invoicing' ), |
|
276
|
|
|
) ); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
// Sanitize selected item type. |
|
280
|
|
|
$type = ''; |
|
281
|
|
|
if( isset( $_GET['type'] ) && array_key_exists( $_GET['type'], wpinv_get_item_types() ) ) { |
|
282
|
|
|
$class = $_GET['type']; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
echo wpinv_html_select( array( |
|
286
|
|
|
'options' => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ), |
|
287
|
|
|
'name' => 'type', |
|
288
|
|
|
'id' => 'type', |
|
289
|
|
|
'selected' => $type, |
|
290
|
|
|
'show_option_all' => false, |
|
291
|
|
|
'show_option_none' => false, |
|
292
|
|
|
'class' => 'gdmbx2-text-medium', |
|
293
|
|
|
) ); |
|
294
|
|
|
|
|
295
|
|
|
if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) { |
|
296
|
|
|
echo '<input type="hidden" name="all_posts" value="1" />'; |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 ); |
|
301
|
|
|
|
|
302
|
|
|
function wpinv_send_invoice_after_save( $invoice ) { |
|
303
|
|
|
if ( empty( $_POST['wpi_save_send'] ) ) { |
|
304
|
|
|
return; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) { |
|
308
|
|
|
wpinv_user_invoice_notification( $invoice->ID ); |
|
309
|
|
|
} |
|
310
|
|
|
} |
|
311
|
|
|
add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
312
|
|
|
|
|
313
|
|
|
|
|
314
|
|
|
add_action('admin_init', 'admin_init_example_type'); |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* hook the posts search if we're on the admin page for our type |
|
318
|
|
|
*/ |
|
319
|
|
|
function admin_init_example_type() { |
|
320
|
|
|
global $typenow; |
|
321
|
|
|
|
|
322
|
|
|
if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
323
|
|
|
add_filter('posts_search', 'posts_search_example_type', 10, 2); |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* add query condition for search invoice by email |
|
329
|
|
|
* @param string $search the search string so far |
|
330
|
|
|
* @param WP_Query $query |
|
331
|
|
|
* @return string |
|
332
|
|
|
*/ |
|
333
|
|
|
function posts_search_example_type($search, $query) { |
|
334
|
|
|
global $wpdb; |
|
335
|
|
|
|
|
336
|
|
|
if ($query->is_main_query() && !empty($query->query['s'])) { |
|
337
|
|
|
$conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
|
|
|
|
|
338
|
|
|
if ( ! empty( $search ) ) { |
|
339
|
|
|
$search = preg_replace( '/^ AND /', '', $search ); |
|
340
|
|
|
$search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
|
341
|
|
|
} else { |
|
342
|
|
|
$search = " AND ( {$conditions_str} )"; |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
return $search; |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
add_action( 'admin_init', 'wpinv_reset_invoice_count' ); |
|
350
|
|
|
function wpinv_reset_invoice_count(){ |
|
351
|
|
|
if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
352
|
|
|
wpinv_update_option('invoice_sequence_start', 1); |
|
353
|
|
|
delete_option('wpinv_last_invoice_number'); |
|
354
|
|
|
$url = add_query_arg(array('reset_invoice_done' => 1)); |
|
355
|
|
|
$url = remove_query_arg(array('reset_invoice_count', '_nonce'), $url); |
|
356
|
|
|
wp_redirect($url); |
|
357
|
|
|
exit(); |
|
|
|
|
|
|
358
|
|
|
} |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
add_action('admin_notices', 'wpinv_invoice_count_reset_message'); |
|
362
|
|
|
function wpinv_invoice_count_reset_message(){ |
|
363
|
|
|
if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
364
|
|
|
$notice = __('Invoice number sequence reset successfully.', 'invoicing'); |
|
365
|
|
|
?> |
|
366
|
|
|
<div class="notice notice-success is-dismissible"> |
|
367
|
|
|
<p><?php echo $notice; ?></p> |
|
368
|
|
|
</div> |
|
369
|
|
|
<?php |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
|