Make WordPress Core

Ticket #31397: post.types.php

File post.types.php, 3.2 KB (added by lutond, 11 years ago)

This file is not initialized. I initialized it using init action.

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