Last active
January 16, 2020 19:46
-
-
Save renventura/0aa7760d41ecd1ec4229 to your computer and use it in GitHub Desktop.
Registers an "Invoice" custom post type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //* Mind this opening PHP tag | |
/** | |
* Register Invoice Type | |
* | |
* @author Ren Ventura | |
* @link http://www.engagewp.com/create-invoices-gravty-forms-wordpress | |
*/ | |
add_action( 'init', 'rv_invoice_cpt' ); | |
function rv_invoice_cpt() { | |
$labels = array( | |
'name' => _x( 'Invoice', 'post type general name', 'engwp' ), | |
'singular_name' => _x( 'Invoice', 'post type singular name', 'engwp' ), | |
'menu_name' => _x( 'Invoices', 'admin menu', 'engwp' ), | |
'name_admin_bar' => _x( 'Invoice', 'add new on admin bar', 'engwp' ), | |
'add_new' => _x( 'Add New', 'Invoice', 'engwp' ), | |
'add_new_item' => __( 'Add New Invoice', 'engwp' ), | |
'new_item' => __( 'New Invoice', 'engwp' ), | |
'edit_item' => __( 'Edit Invoice', 'engwp' ), | |
'view_item' => __( 'View Invoice', 'engwp' ), | |
'all_items' => __( 'All Invoices', 'engwp' ), | |
'search_items' => __( 'Search Invoices', 'engwp' ), | |
'parent_item_colon' => __( 'Parent Invoice:', 'engwp' ), | |
'not_found' => __( 'No Invoices found.', 'engwp' ), | |
'not_found_in_trash' => __( 'No Invoices found in Trash.', 'engwp' ) | |
); | |
$args = array( | |
'description' => __( 'Invoice', 'engwp' ), | |
'labels' => $labels, | |
'supports' => array( 'title' ), | |
'hierarchical' => false, | |
'public' => true, | |
'publicly_queryable' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'invoice' ), | |
'show_ui' => true, | |
'menu_icon' => 'dashicons-media-spreadsheet', | |
'show_in_menu' => true, | |
'show_in_nav_menus' => false, | |
'show_in_admin_bar' => true, | |
// 'menu_position' => 5, | |
'can_export' => true, | |
'has_archive' => false, | |
'exclude_from_search' => true, | |
'capability_type' => 'post', | |
); | |
register_post_type( 'invoice', $args ); | |
// Deny access to the post_type query arg | |
if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'invoice' ) { | |
wp_die( 'Unauthorized' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment