Last active
August 29, 2015 14:26
-
-
Save shawnkfinn/cee68719c21da50f6beb to your computer and use it in GitHub Desktop.
wppb.io - Add description, menu icon, menu order and custom slug
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
// Public Function (Replace lines 39-58 of wppb.io's default class-your-custom-post-type.php) | |
public function __construct ( $post_type = '', $plural = '', $single = '', $description = '', $menu_position = '', $menu_icon = '', $slug = '' ) { | |
if ( ! $post_type || ! $plural || ! $single ) return; | |
// Post type name and labels | |
$this->post_type = $post_type; | |
$this->plural = $plural; | |
$this->single = $single; | |
$this->description = $description; | |
$this->menu_position = $menu_position; | |
$this->menu_icon = $menu_icon; | |
$this->slug = $slug; | |
// Register post type | |
add_action( 'init' , array( $this, 'register_post_type' ) ); | |
// Display custom update messages for posts edits | |
add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); | |
add_filter( 'bulk_post_updated_messages', array( $this, 'bulk_updated_messages' ), 10, 2 ); | |
} | |
// Add $this->slug & rewrite section / Add $rewrite, $this->menu_position, $this->menu_icon | |
(Replace lines 39-58 of wppb.io's default class-your-custom-post-type.php) | |
/** | |
* Register new post type | |
* @return void | |
*/ | |
public function register_post_type () { | |
$labels = array( | |
'name' => $this->plural, | |
'singular_name' => $this->single, | |
'name_admin_bar' => $this->single, | |
'add_new' => _x( 'Add New', $this->post_type , 'your-plugin-name-cpts' ), | |
'add_new_item' => sprintf( __( 'Add New %s' , 'your-plugin-name-cpts' ), $this->single ), | |
'edit_item' => sprintf( __( 'Edit %s' , 'your-plugin-name-cpts' ), $this->single ), | |
'new_item' => sprintf( __( 'New %s' , 'your-plugin-name-cpts' ), $this->single ), | |
'all_items' => sprintf( __( 'All %s' , 'your-plugin-name-cpts' ), $this->plural ), | |
'view_item' => sprintf( __( 'View %s' , 'your-plugin-name-cpts' ), $this->single ), | |
'search_items' => sprintf( __( 'Search %s' , 'your-plugin-name-cpts' ), $this->plural ), | |
'not_found' => sprintf( __( 'No %s Found' , 'your-plugin-name-cpts' ), $this->plural ), | |
'not_found_in_trash' => sprintf( __( 'No %s Found In Trash' , 'your-plugin-name-cpts' ), $this->plural ), | |
'parent_item_colon' => sprintf( __( 'Parent %s' ), $this->single ), | |
'menu_name' => $this->plural, | |
); | |
$rewrite = array( | |
'slug' => $this->slug, | |
'with_front' => true, | |
'pages' => true, | |
'feeds' => true, | |
); | |
$args = array( | |
'labels' => apply_filters( $this->post_type . '_labels', $labels ), | |
'description' => $this->description, | |
'public' => true, | |
'publicly_queryable' => true, | |
'exclude_from_search' => false, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'query_var' => true, | |
'can_export' => true, | |
'rewrite' => $rewrite, | |
'capability_type' => 'post', | |
'has_archive' => true, | |
'hierarchical' => true, | |
'supports' => array( 'title', 'editor', 'publicize', 'excerpt', 'comments', 'thumbnail' ), | |
'menu_position' => $this->menu_position, | |
'menu_icon' => $this->menu_icon, | |
); | |
register_post_type( $this->post_type, apply_filters( $this->post_type . '_register_args', $args, $this->post_type ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment