Completed
Push — master ( 35a6df...32735f )
by Brian
18s queued 13s
created
includes/wpinv-post-types.php 1 patch
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -7,38 +7,38 @@  discard block
 block discarded – undo
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
     $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' )
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 32
     );
33
-    $labels = apply_filters( 'wpinv_labels', $labels );
33
+    $labels = apply_filters('wpinv_labels', $labels);
34 34
     
35 35
     $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico';
36
-    $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon );
36
+    $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon);
37 37
 
38 38
     $cap_type = 'wpi_invoice';
39 39
     $args = array(
40 40
         'labels'             => $labels,
41
-        'description'        => __( 'This is where invoices are stored.', 'invoicing' ),
41
+        'description'        => __('This is where invoices are stored.', 'invoicing'),
42 42
         'public'             => true,
43 43
         'can_export'         => true,
44 44
         '_builtin'           => false,
@@ -71,42 +71,42 @@  discard block
 block discarded – undo
71 71
         'has_archive'        => false,
72 72
         'hierarchical'       => false,
73 73
         'menu_position'      => null,
74
-        'supports'           => array( 'title', 'author' ),
74
+        'supports'           => array('title', 'author'),
75 75
         'menu_icon'          => 'dashicons-media-spreadsheet',
76 76
     );
77 77
             
78
-    $args = apply_filters( 'wpinv_register_post_type_invoice', $args );
78
+    $args = apply_filters('wpinv_register_post_type_invoice', $args);
79 79
     
80
-    register_post_type( 'wpi_invoice', $args );
80
+    register_post_type('wpi_invoice', $args);
81 81
     
82 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' ),
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 93
         'parent_item_colon'  => '',
94
-        'not_found'          => __( 'No items found.', 'invoicing' ),
95
-        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
94
+        'not_found'          => __('No items found.', 'invoicing'),
95
+        'not_found_in_trash' => __('No items found in trash.', 'invoicing')
96 96
     );
97
-    $items_labels = apply_filters( 'wpinv_items_labels', $items_labels );
97
+    $items_labels = apply_filters('wpinv_items_labels', $items_labels);
98 98
 
99 99
     $cap_type          = 'wpi_item';
100 100
     $invoice_item_args = array(
101 101
         'labels'                => $items_labels,
102
-        'description'           => __( 'This is where you can add new invoice items.', 'invoicing' ),
102
+        'description'           => __('This is where you can add new invoice items.', 'invoicing'),
103 103
         'public'                => false,
104 104
         'has_archive'           => false,
105 105
         '_builtin'              => false,
106 106
         'show_ui'               => true,
107 107
         'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
108 108
         'show_in_nav_menus'     => false,
109
-        'supports'              => array( 'title', 'excerpt' ),
109
+        'supports'              => array('title', 'excerpt'),
110 110
         'register_meta_box_cb'  => 'wpinv_register_item_meta_boxes',
111 111
         'rewrite'               => false,
112 112
         'query_var'             => false,
@@ -133,33 +133,33 @@  discard block
 block discarded – undo
133 133
         ),
134 134
         'can_export'            => true,
135 135
     );
136
-    $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args );
136
+    $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args);
137 137
 
138
-    register_post_type( 'wpi_item', $invoice_item_args );
138
+    register_post_type('wpi_item', $invoice_item_args);
139 139
     
140 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' )
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 155
     );
156
-    $labels = apply_filters( 'wpinv_discounts_labels', $labels );
156
+    $labels = apply_filters('wpinv_discounts_labels', $labels);
157 157
 
158 158
     $cap_type = 'wpi_discount';
159 159
     
160 160
     $args = array(
161 161
         'labels'             => $labels,
162
-        'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
162
+        'description'        => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'),
163 163
         'public'             => false,
164 164
         'can_export'         => true,
165 165
         '_builtin'           => false,
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         ),
191 191
         'has_archive'        => false,
192 192
         'hierarchical'       => false,
193
-        'supports'           => array( 'title', 'excerpt' ),
193
+        'supports'           => array('title', 'excerpt'),
194 194
         'register_meta_box_cb'  => 'wpinv_register_discount_meta_boxes',
195 195
         'show_in_nav_menus'  => false,
196 196
         'show_in_admin_bar'  => true,
@@ -198,121 +198,121 @@  discard block
 block discarded – undo
198 198
         'menu_position'      => null,
199 199
     );
200 200
             
201
-    $args = apply_filters( 'wpinv_register_post_type_discount', $args );
201
+    $args = apply_filters('wpinv_register_post_type_discount', $args);
202 202
     
203
-    register_post_type( 'wpi_discount', $args );
203
+    register_post_type('wpi_discount', $args);
204 204
 }
205 205
 
206 206
 function wpinv_get_default_labels() {
207 207
     $defaults = array(
208
-       'singular' => __( 'Invoice', 'invoicing' ),
209
-       'plural'   => __( 'Invoices', 'invoicing' )
208
+       'singular' => __('Invoice', 'invoicing'),
209
+       'plural'   => __('Invoices', 'invoicing')
210 210
     );
211 211
     
212
-    return apply_filters( 'wpinv_default_invoices_name', $defaults );
212
+    return apply_filters('wpinv_default_invoices_name', $defaults);
213 213
 }
214 214
 
215
-function wpinv_get_label_singular( $lowercase = false ) {
215
+function wpinv_get_label_singular($lowercase = false) {
216 216
     $defaults = wpinv_get_default_labels();
217 217
     
218
-    return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
218
+    return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular'];
219 219
 }
220 220
 
221
-function wpinv_get_label_plural( $lowercase = false ) {
221
+function wpinv_get_label_plural($lowercase = false) {
222 222
     $defaults = wpinv_get_default_labels();
223 223
     
224
-    return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
224
+    return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural'];
225 225
 }
226 226
 
227
-function wpinv_change_default_title( $title ) {
228
-     if ( !is_admin() ) {
227
+function wpinv_change_default_title($title) {
228
+     if (!is_admin()) {
229 229
         $label = wpinv_get_label_singular();
230
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
230
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
231 231
         return $title;
232 232
      }
233 233
 
234 234
      $screen = get_current_screen();
235 235
 
236
-     if ( 'wpi_invoice' == $screen->post_type ) {
236
+     if ('wpi_invoice' == $screen->post_type) {
237 237
         $label = wpinv_get_label_singular();
238
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
238
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
239 239
      }
240 240
 
241 241
      return $title;
242 242
 }
243
-add_filter( 'enter_title_here', 'wpinv_change_default_title' );
243
+add_filter('enter_title_here', 'wpinv_change_default_title');
244 244
 
245 245
 function wpinv_register_post_status() {
246
-    register_post_status( 'wpi-pending', array(
247
-        'label'                     => _x( 'Pending', 'Invoice status', 'invoicing' ),
246
+    register_post_status('wpi-pending', array(
247
+        'label'                     => _x('Pending', 'Invoice status', 'invoicing'),
248 248
         'public'                    => true,
249 249
         'exclude_from_search'       => true,
250 250
         'show_in_admin_all_list'    => true,
251 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' ),
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 256
         'public'                    => true,
257 257
         'exclude_from_search'       => true,
258 258
         'show_in_admin_all_list'    => true,
259 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' ),
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 264
         'public'                    => true,
265 265
         'exclude_from_search'       => true,
266 266
         'show_in_admin_all_list'    => true,
267 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' ),
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 272
         'public'                    => true,
273 273
         'exclude_from_search'       => true,
274 274
         'show_in_admin_all_list'    => true,
275 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' ),
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 280
         'public'                    => true,
281 281
         'exclude_from_search'       => true,
282 282
         'show_in_admin_all_list'    => true,
283 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' ),
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 288
         'public'                    => true,
289 289
         'exclude_from_search'       => true,
290 290
         'show_in_admin_all_list'    => true,
291 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' ),
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 296
         'public'                    => true,
297 297
         'exclude_from_search'       => true,
298 298
         'show_in_admin_all_list'    => true,
299 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
-    ) );
300
+        'label_count'               => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing')
301
+    ));
302 302
 }
303
-add_action( 'init', 'wpinv_register_post_status', 10 );
303
+add_action('init', 'wpinv_register_post_status', 10);
304 304
 
305 305
 /**
306 306
  * Hides invoice counts on public facing user profile pages.
307 307
  * 
308 308
  * @link https://wpinvoicing.com/support/topic/number-of-invoices-show-on-a-public-profile/
309 309
  */
310
-function wpinv_hide_uwp_user_invoices_count( $counts ){
310
+function wpinv_hide_uwp_user_invoices_count($counts) {
311 311
 
312
-    if ( apply_filters( 'wpinv_hide_uwp_user_invoices_count', true ) && isset( $counts['wpi_invoice'] ) ) {
313
-	    unset( $counts['wpi_invoice'] );
312
+    if (apply_filters('wpinv_hide_uwp_user_invoices_count', true) && isset($counts['wpi_invoice'])) {
313
+	    unset($counts['wpi_invoice']);
314 314
     }
315 315
 
316 316
     return $counts;
317 317
 }
318
-add_filter('uwp_get_user_post_counts', 'wpinv_hide_uwp_user_invoices_count' );
319 318
\ No newline at end of file
319
+add_filter('uwp_get_user_post_counts', 'wpinv_hide_uwp_user_invoices_count');
320 320
\ No newline at end of file
Please login to merge, or discard this patch.