| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * Plugin Name: Chat Custom Post Type |
|---|
| 4 | */ |
|---|
| 5 | |
|---|
| 6 | class Chat_Post_Type { |
|---|
| 7 | |
|---|
| 8 | public static $post_type = 'tg_chat'; |
|---|
| 9 | |
|---|
| 10 | const AD_GROUPS_TAXONOMY_SLUG = 'groups'; |
|---|
| 11 | |
|---|
| 12 | public static function init() { |
|---|
| 13 | add_action( 'init', [ __CLASS__, 'action_register_taxonomy' ] ); |
|---|
| 14 | add_action( 'init', [ __CLASS__, 'action_register_post_type' ] ); |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | public static function action_register_taxonomy() { |
|---|
| 18 | register_taxonomy( |
|---|
| 19 | self::AD_GROUPS_TAXONOMY_SLUG, |
|---|
| 20 | self::$post_type, |
|---|
| 21 | [ |
|---|
| 22 | 'label' => 'AD Groups', |
|---|
| 23 | 'public' => true, |
|---|
| 24 | 'show_in_rest' => false, |
|---|
| 25 | 'publicly_queryable' => false, |
|---|
| 26 | // This line causes a fatal error when saving Quick Edit: |
|---|
| 27 | 'meta_box_cb' => 'post_categories_meta_box' |
|---|
| 28 | ] |
|---|
| 29 | ); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | public static function action_register_post_type() { |
|---|
| 33 | $args = [ |
|---|
| 34 | 'label' => 'Chat', |
|---|
| 35 | 'supports' => [ 'title', 'custom-fields' ], |
|---|
| 36 | 'taxonomies' => [ self::AD_GROUPS_TAXONOMY_SLUG ], |
|---|
| 37 | 'hierarchical' => false, |
|---|
| 38 | 'public' => false, |
|---|
| 39 | 'show_ui' => true, |
|---|
| 40 | 'show_in_menu' => true, |
|---|
| 41 | 'show_admin_column' => true, |
|---|
| 42 | 'menu_position' => 24, |
|---|
| 43 | 'menu_icon' => 'dashicons-groups', |
|---|
| 44 | 'show_in_admin_bar' => false, |
|---|
| 45 | 'show_in_nav_menus' => false, |
|---|
| 46 | 'can_export' => true, |
|---|
| 47 | 'has_archive' => false, |
|---|
| 48 | 'exclude_from_search' => true, |
|---|
| 49 | 'publicly_queryable' => true, |
|---|
| 50 | 'capability_type' => 'page', |
|---|
| 51 | ]; |
|---|
| 52 | |
|---|
| 53 | register_post_type( self::$post_type, $args ); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | Chat_Post_Type::init(); |
|---|