| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Plugin Name: LCD_Custom_Post_Type |
|---|
| 5 | * Author : Luton Datta |
|---|
| 6 | * Email : lutondatta@gmail.com |
|---|
| 7 | * Date : Feb 20, 2015, 9:00:58 AM |
|---|
| 8 | */ |
|---|
| 9 | class LCDEA_Custom_Post_Type { |
|---|
| 10 | public function __construct(){ |
|---|
| 11 | $this->_prepare_post_types(); |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | public function _prepare_post_types(){ |
|---|
| 15 | $types = array( |
|---|
| 16 | // $post_type, $supports |
|---|
| 17 | array( 'assignment',array('title','author','slug' ) ), |
|---|
| 18 | array( 'location',array('title','author','slug' ) ), |
|---|
| 19 | array( 'material',array('title','author','slug' ) ), |
|---|
| 20 | array( 'instructor',array('title','author','slug' ) ), |
|---|
| 21 | ); |
|---|
| 22 | |
|---|
| 23 | foreach( $types as $type ){ |
|---|
| 24 | $show_ui = ($type[0] == 'assignment') ? true : false; |
|---|
| 25 | //$menu_parent = $show_ui ? true : 'post-new.php?post_type=assignment'; |
|---|
| 26 | |
|---|
| 27 | $args[$type[0]] = array( |
|---|
| 28 | 'label' => ucwords( $type[0] ).'s', |
|---|
| 29 | 'labels' => array( |
|---|
| 30 | 'name' => ucwords($type[0]).'s', |
|---|
| 31 | 'singular_name' => ucwords( $type[0] ), |
|---|
| 32 | 'menu_name' => ucwords( $type[0] ).'s', |
|---|
| 33 | 'menu_admin_bar' => ucwords( $type[0] ), |
|---|
| 34 | 'add_new' => "Add ".ucwords( $type[0] ), |
|---|
| 35 | 'add_new_item' => 'Add '.ucwords( $type[0] ), |
|---|
| 36 | 'new_item' => 'New '.ucwords( $type[0] ), |
|---|
| 37 | 'edit_item' => 'Edit '.ucwords( $type[0] ), |
|---|
| 38 | 'view_item' => 'View '.ucwords( $type[0] ), |
|---|
| 39 | 'all_items' => 'All '.ucwords( $type[0] ).'s', |
|---|
| 40 | 'search_items' => 'Secrch '.ucwords( $type[0] ).'s', |
|---|
| 41 | 'parent_item_colon' => 'Search '.ucwords( $type[0] ).':', |
|---|
| 42 | 'not_found' => 'Not Found', |
|---|
| 43 | 'not_found_in_trash' => 'Not Found In Trash' |
|---|
| 44 | ), |
|---|
| 45 | 'public' => true, |
|---|
| 46 | 'exclude_from_search' => false, |
|---|
| 47 | 'publicly_queryable' => true, |
|---|
| 48 | 'show_ui' => $show_ui, |
|---|
| 49 | 'show_in_menu' => true,//$menu_parent, |
|---|
| 50 | //'show_in_nav_menus' => true, |
|---|
| 51 | 'show_in_admin_bar' => true, |
|---|
| 52 | 'menu_position' => 61, |
|---|
| 53 | 'menu_icon' => NULL, |
|---|
| 54 | 'capability_type' => 'post', |
|---|
| 55 | //'capabilities' => array(), |
|---|
| 56 | 'map_meta_cap' => null, |
|---|
| 57 | 'hierarchical' => true, |
|---|
| 58 | 'supports' => $type[1], |
|---|
| 59 | //'register_meta_box_cb', |
|---|
| 60 | //taxonomies, |
|---|
| 61 | 'has_archive' => ucwords( $type[0] ).'s', |
|---|
| 62 | 'permalink_epmask' => EP_PERMALINK, |
|---|
| 63 | 'rewrite' => true,//array('slug'=>$type[0]), |
|---|
| 64 | 'query_var' => true, |
|---|
| 65 | //'_builtin' => true |
|---|
| 66 | ); |
|---|
| 67 | register_post_type( $type[0], $args[$type[0]] ); |
|---|
| 68 | } |
|---|
| 69 | } // Function |
|---|
| 70 | } |
|---|
| 71 | add_action('init',function(){ |
|---|
| 72 | new LCDEA_Custom_Post_Type(); |
|---|
| 73 | }); |
|---|
| 74 | |
|---|