|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
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
|
|
|
add_action( 'init', 'wpinv_register_post_types', 1 ); |
|
15
|
|
|
function wpinv_register_post_types() { |
|
16
|
|
|
|
|
17
|
|
|
$labels = array( |
|
18
|
|
|
'name' => _x( 'Invoices', 'post type general name', 'invoicing' ), |
|
19
|
|
|
'singular_name' => _x( 'Invoice', 'post type singular name', 'invoicing' ), |
|
20
|
|
|
'menu_name' => _x( 'Invoices', 'admin menu', 'invoicing' ), |
|
21
|
|
|
'name_admin_bar' => _x( 'Invoice', 'add new on admin bar', 'invoicing' ), |
|
22
|
|
|
'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
23
|
|
|
'add_new_item' => __( 'Add New Invoice', 'invoicing' ), |
|
24
|
|
|
'new_item' => __( 'New Invoice', 'invoicing' ), |
|
25
|
|
|
'edit_item' => __( 'Edit Invoice', 'invoicing' ), |
|
26
|
|
|
'view_item' => __( 'View Invoice', 'invoicing' ), |
|
27
|
|
|
'all_items' => __( 'Invoices', 'invoicing' ), |
|
28
|
|
|
'search_items' => __( 'Search Invoices', 'invoicing' ), |
|
29
|
|
|
'parent_item_colon' => __( 'Parent Invoices:', 'invoicing' ), |
|
30
|
|
|
'not_found' => __( 'No invoices found.', 'invoicing' ), |
|
31
|
|
|
'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' ) |
|
32
|
|
|
); |
|
33
|
|
|
$labels = apply_filters( 'wpinv_labels', $labels ); |
|
34
|
|
|
|
|
35
|
|
|
$menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico'; |
|
36
|
|
|
$menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon ); |
|
37
|
|
|
|
|
38
|
|
|
$cap_type = 'wpi_invoice'; |
|
39
|
|
|
$args = array( |
|
40
|
|
|
'labels' => $labels, |
|
41
|
|
|
'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
42
|
|
|
'public' => true, |
|
43
|
|
|
'can_export' => true, |
|
44
|
|
|
'_builtin' => false, |
|
45
|
|
|
'publicly_queryable' => true, |
|
46
|
|
|
'exclude_from_search'=> true, |
|
47
|
|
|
'show_ui' => true, |
|
48
|
|
|
'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
|
49
|
|
|
'show_in_nav_menus' => false, |
|
50
|
|
|
'query_var' => false, |
|
51
|
|
|
'rewrite' => true, |
|
52
|
|
|
'capability_type' => 'wpi_invoice', |
|
53
|
|
|
'map_meta_cap' => true, |
|
54
|
|
|
'capabilities' => array( |
|
55
|
|
|
//'create_posts' => wpinv_get_capability(), |
|
56
|
|
|
'delete_post' => "delete_{$cap_type}", |
|
57
|
|
|
'delete_posts' => "delete_{$cap_type}s", |
|
58
|
|
|
'delete_private_posts' => "delete_private_{$cap_type}s", |
|
59
|
|
|
'delete_published_posts' => "delete_published_{$cap_type}s", |
|
60
|
|
|
'delete_others_posts' => "delete_others_{$cap_type}s", |
|
61
|
|
|
'edit_post' => "edit_{$cap_type}", |
|
62
|
|
|
'edit_posts' => "edit_{$cap_type}s", |
|
63
|
|
|
'edit_others_posts' => "edit_others_{$cap_type}s", |
|
64
|
|
|
'edit_private_posts' => "edit_private_{$cap_type}s", |
|
65
|
|
|
'edit_published_posts' => "edit_published_{$cap_type}s", |
|
66
|
|
|
'publish_posts' => "publish_{$cap_type}s", |
|
67
|
|
|
'read_post' => "read_{$cap_type}", |
|
68
|
|
|
'read_private_posts' => "read_private_{$cap_type}s", |
|
69
|
|
|
|
|
70
|
|
|
), |
|
71
|
|
|
'has_archive' => false, |
|
72
|
|
|
'hierarchical' => false, |
|
73
|
|
|
'menu_position' => null, |
|
74
|
|
|
'supports' => array( 'title', 'author' ), |
|
75
|
|
|
'menu_icon' => 'dashicons-media-spreadsheet', |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$args = apply_filters( 'wpinv_register_post_type_invoice', $args ); |
|
79
|
|
|
|
|
80
|
|
|
register_post_type( 'wpi_invoice', $args ); |
|
81
|
|
|
|
|
82
|
|
|
$items_labels = array( |
|
83
|
|
|
'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
84
|
|
|
'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
85
|
|
|
'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
86
|
|
|
'add_new' => _x( 'Add New', 'wpi_item', 'invoicing' ), |
|
87
|
|
|
'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
88
|
|
|
'new_item' => __( 'New Item', 'invoicing' ), |
|
89
|
|
|
'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
90
|
|
|
'view_item' => __( 'View Item', 'invoicing' ), |
|
91
|
|
|
'all_items' => __( 'Items', 'invoicing' ), |
|
92
|
|
|
'search_items' => __( 'Search Items', 'invoicing' ), |
|
93
|
|
|
'parent_item_colon' => '', |
|
94
|
|
|
'not_found' => __( 'No items found.', 'invoicing' ), |
|
95
|
|
|
'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
96
|
|
|
); |
|
97
|
|
|
$items_labels = apply_filters( 'wpinv_items_labels', $items_labels ); |
|
98
|
|
|
|
|
99
|
|
|
$cap_type = 'wpi_item'; |
|
100
|
|
|
$invoice_item_args = array( |
|
101
|
|
|
'labels' => $items_labels, |
|
102
|
|
|
'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
103
|
|
|
'public' => false, |
|
104
|
|
|
'has_archive' => false, |
|
105
|
|
|
'_builtin' => false, |
|
106
|
|
|
'show_ui' => true, |
|
107
|
|
|
'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
108
|
|
|
'show_in_nav_menus' => false, |
|
109
|
|
|
'supports' => array( 'title', 'excerpt' ), |
|
110
|
|
|
'register_meta_box_cb' => 'wpinv_register_item_meta_boxes', |
|
111
|
|
|
'rewrite' => false, |
|
112
|
|
|
'query_var' => false, |
|
113
|
|
|
'capability_type' => $cap_type, |
|
114
|
|
|
'map_meta_cap' => true, |
|
115
|
|
|
'show_in_admin_bar' => true, |
|
116
|
|
|
'capabilities' => array( |
|
117
|
|
|
//'create_posts' => wpinv_get_capability(), |
|
118
|
|
|
'delete_post' => "delete_{$cap_type}", |
|
119
|
|
|
'delete_posts' => "delete_{$cap_type}s", |
|
120
|
|
|
'delete_private_posts' => "delete_private_{$cap_type}s", |
|
121
|
|
|
'delete_published_posts' => "delete_published_{$cap_type}s", |
|
122
|
|
|
'delete_others_posts' => "delete_others_{$cap_type}s", |
|
123
|
|
|
'edit_post' => "edit_{$cap_type}", |
|
124
|
|
|
'edit_posts' => "edit_{$cap_type}s", |
|
125
|
|
|
'edit_others_posts' => "edit_others_{$cap_type}s", |
|
126
|
|
|
'edit_private_posts' => "edit_private_{$cap_type}s", |
|
127
|
|
|
'edit_published_posts' => "edit_published_{$cap_type}s", |
|
128
|
|
|
'publish_posts' => "publish_{$cap_type}s", |
|
129
|
|
|
'read_post' => "read_{$cap_type}", |
|
130
|
|
|
'read_private_posts' => "read_private_{$cap_type}s", |
|
131
|
|
|
//'create_posts' => "create_{$cap_type}s", |
|
132
|
|
|
|
|
133
|
|
|
), |
|
134
|
|
|
'can_export' => true, |
|
135
|
|
|
); |
|
136
|
|
|
$invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args ); |
|
137
|
|
|
|
|
138
|
|
|
register_post_type( 'wpi_item', $invoice_item_args ); |
|
139
|
|
|
|
|
140
|
|
|
$labels = array( |
|
141
|
|
|
'name' => _x( 'Discounts', 'post type general name', 'invoicing' ), |
|
142
|
|
|
'singular_name' => _x( 'Discount', 'post type singular name', 'invoicing' ), |
|
143
|
|
|
'menu_name' => _x( 'Discounts', 'admin menu', 'invoicing' ), |
|
144
|
|
|
'name_admin_bar' => _x( 'Discount', 'add new on admin bar', 'invoicing' ), |
|
145
|
|
|
'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
146
|
|
|
'add_new_item' => __( 'Add New Discount', 'invoicing' ), |
|
147
|
|
|
'new_item' => __( 'New Discount', 'invoicing' ), |
|
148
|
|
|
'edit_item' => __( 'Edit Discount', 'invoicing' ), |
|
149
|
|
|
'view_item' => __( 'View Discount', 'invoicing' ), |
|
150
|
|
|
'all_items' => __( 'Discounts', 'invoicing' ), |
|
151
|
|
|
'search_items' => __( 'Search Discounts', 'invoicing' ), |
|
152
|
|
|
'parent_item_colon' => __( 'Parent Discounts:', 'invoicing' ), |
|
153
|
|
|
'not_found' => __( 'No discounts found.', 'invoicing' ), |
|
154
|
|
|
'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' ) |
|
155
|
|
|
); |
|
156
|
|
|
$labels = apply_filters( 'wpinv_discounts_labels', $labels ); |
|
157
|
|
|
|
|
158
|
|
|
$cap_type = 'wpi_discount'; |
|
159
|
|
|
|
|
160
|
|
|
$args = array( |
|
161
|
|
|
'labels' => $labels, |
|
162
|
|
|
'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
163
|
|
|
'public' => false, |
|
164
|
|
|
'can_export' => true, |
|
165
|
|
|
'_builtin' => false, |
|
166
|
|
|
'publicly_queryable' => false, |
|
167
|
|
|
'exclude_from_search'=> true, |
|
168
|
|
|
'show_ui' => true, |
|
169
|
|
|
'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
170
|
|
|
'query_var' => false, |
|
171
|
|
|
'rewrite' => false, |
|
172
|
|
|
'capability_type' => $cap_type, |
|
173
|
|
|
'map_meta_cap' => true, |
|
174
|
|
|
'capabilities' => array( |
|
175
|
|
|
//'create_posts' => wpinv_get_capability(), |
|
176
|
|
|
'delete_post' => "delete_{$cap_type}", |
|
177
|
|
|
'delete_posts' => "delete_{$cap_type}s", |
|
178
|
|
|
'delete_private_posts' => "delete_private_{$cap_type}s", |
|
179
|
|
|
'delete_published_posts' => "delete_published_{$cap_type}s", |
|
180
|
|
|
'delete_others_posts' => "delete_others_{$cap_type}s", |
|
181
|
|
|
'edit_post' => "edit_{$cap_type}", |
|
182
|
|
|
'edit_posts' => "edit_{$cap_type}s", |
|
183
|
|
|
'edit_others_posts' => "edit_others_{$cap_type}s", |
|
184
|
|
|
'edit_private_posts' => "edit_private_{$cap_type}s", |
|
185
|
|
|
'edit_published_posts' => "edit_published_{$cap_type}s", |
|
186
|
|
|
'publish_posts' => "publish_{$cap_type}s", |
|
187
|
|
|
'read_post' => "read_{$cap_type}", |
|
188
|
|
|
'read_private_posts' => "read_private_{$cap_type}s", |
|
189
|
|
|
|
|
190
|
|
|
), |
|
191
|
|
|
'has_archive' => false, |
|
192
|
|
|
'hierarchical' => false, |
|
193
|
|
|
'supports' => array( 'title', 'excerpt' ), |
|
194
|
|
|
'register_meta_box_cb' => 'wpinv_register_discount_meta_boxes', |
|
195
|
|
|
'show_in_nav_menus' => false, |
|
196
|
|
|
'show_in_admin_bar' => true, |
|
197
|
|
|
'menu_icon' => $menu_icon, |
|
198
|
|
|
'menu_position' => null, |
|
199
|
|
|
); |
|
200
|
|
|
|
|
201
|
|
|
$args = apply_filters( 'wpinv_register_post_type_discount', $args ); |
|
202
|
|
|
|
|
203
|
|
|
register_post_type( 'wpi_discount', $args ); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
function wpinv_get_default_labels() { |
|
207
|
|
|
$defaults = array( |
|
208
|
|
|
'singular' => __( 'Invoice', 'invoicing' ), |
|
209
|
|
|
'plural' => __( 'Invoices', 'invoicing' ) |
|
210
|
|
|
); |
|
211
|
|
|
|
|
212
|
|
|
return apply_filters( 'wpinv_default_invoices_name', $defaults ); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
function wpinv_get_label_singular( $lowercase = false ) { |
|
216
|
|
|
$defaults = wpinv_get_default_labels(); |
|
217
|
|
|
|
|
218
|
|
|
return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
function wpinv_get_label_plural( $lowercase = false ) { |
|
222
|
|
|
$defaults = wpinv_get_default_labels(); |
|
223
|
|
|
|
|
224
|
|
|
return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
function wpinv_change_default_title( $title ) { |
|
228
|
|
|
if ( !is_admin() ) { |
|
229
|
|
|
$label = wpinv_get_label_singular(); |
|
230
|
|
|
$title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
231
|
|
|
return $title; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
$screen = get_current_screen(); |
|
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
if ( 'wpi_invoice' == $screen->post_type ) { |
|
237
|
|
|
$label = wpinv_get_label_singular(); |
|
238
|
|
|
$title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
return $title; |
|
242
|
|
|
} |
|
243
|
|
|
add_filter( 'enter_title_here', 'wpinv_change_default_title' ); |
|
244
|
|
|
|
|
245
|
|
|
function wpinv_register_post_status() { |
|
246
|
|
|
register_post_status( 'wpi-pending', array( |
|
247
|
|
|
'label' => _x( 'Pending', 'Invoice status', 'invoicing' ), |
|
248
|
|
|
'public' => true, |
|
249
|
|
|
'exclude_from_search' => true, |
|
250
|
|
|
'show_in_admin_all_list' => true, |
|
251
|
|
|
'show_in_admin_status_list' => true, |
|
252
|
|
|
'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing' ) |
|
253
|
|
|
) ); |
|
254
|
|
|
register_post_status( 'wpi-processing', array( |
|
255
|
|
|
'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
256
|
|
|
'public' => true, |
|
257
|
|
|
'exclude_from_search' => true, |
|
258
|
|
|
'show_in_admin_all_list' => true, |
|
259
|
|
|
'show_in_admin_status_list' => true, |
|
260
|
|
|
'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
261
|
|
|
) ); |
|
262
|
|
|
register_post_status( 'wpi-onhold', array( |
|
263
|
|
|
'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
264
|
|
|
'public' => true, |
|
265
|
|
|
'exclude_from_search' => true, |
|
266
|
|
|
'show_in_admin_all_list' => true, |
|
267
|
|
|
'show_in_admin_status_list' => true, |
|
268
|
|
|
'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
269
|
|
|
) ); |
|
270
|
|
|
register_post_status( 'wpi-cancelled', array( |
|
271
|
|
|
'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
272
|
|
|
'public' => true, |
|
273
|
|
|
'exclude_from_search' => true, |
|
274
|
|
|
'show_in_admin_all_list' => true, |
|
275
|
|
|
'show_in_admin_status_list' => true, |
|
276
|
|
|
'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
277
|
|
|
) ); |
|
278
|
|
|
register_post_status( 'wpi-refunded', array( |
|
279
|
|
|
'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
280
|
|
|
'public' => true, |
|
281
|
|
|
'exclude_from_search' => true, |
|
282
|
|
|
'show_in_admin_all_list' => true, |
|
283
|
|
|
'show_in_admin_status_list' => true, |
|
284
|
|
|
'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
285
|
|
|
) ); |
|
286
|
|
|
register_post_status( 'wpi-failed', array( |
|
287
|
|
|
'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
288
|
|
|
'public' => true, |
|
289
|
|
|
'exclude_from_search' => true, |
|
290
|
|
|
'show_in_admin_all_list' => true, |
|
291
|
|
|
'show_in_admin_status_list' => true, |
|
292
|
|
|
'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
293
|
|
|
) ); |
|
294
|
|
|
register_post_status( 'wpi-renewal', array( |
|
295
|
|
|
'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
296
|
|
|
'public' => true, |
|
297
|
|
|
'exclude_from_search' => true, |
|
298
|
|
|
'show_in_admin_all_list' => true, |
|
299
|
|
|
'show_in_admin_status_list' => true, |
|
300
|
|
|
'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
301
|
|
|
) ); |
|
302
|
|
|
} |
|
303
|
|
|
add_action( 'init', 'wpinv_register_post_status', 10 ); |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* Hides invoice counts on public facing user profile pages. |
|
307
|
|
|
* |
|
308
|
|
|
* @link https://wpinvoicing.com/support/topic/number-of-invoices-show-on-a-public-profile/ |
|
309
|
|
|
*/ |
|
310
|
|
|
function wpinv_hide_uwp_user_invoices_count( $counts ){ |
|
311
|
|
|
|
|
312
|
|
|
if ( apply_filters( 'wpinv_hide_uwp_user_invoices_count', true ) && isset( $counts['wpi_invoice'] ) ) { |
|
313
|
|
|
unset( $counts['wpi_invoice'] ); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
return $counts; |
|
317
|
|
|
} |
|
318
|
|
|
add_filter('uwp_get_user_post_counts', 'wpinv_hide_uwp_user_invoices_count' ); |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.