<?php
/*
 * Plugin Name: Chat Custom Post Type
 */

class Chat_Post_Type {

	public static $post_type = 'tg_chat';

	const AD_GROUPS_TAXONOMY_SLUG = 'groups';

	public static function init() {
		add_action( 'init', [ __CLASS__, 'action_register_taxonomy' ] );
		add_action( 'init', [ __CLASS__, 'action_register_post_type' ] );
	}

	public static function action_register_taxonomy() {
		register_taxonomy(
			self::AD_GROUPS_TAXONOMY_SLUG,
			self::$post_type,
			[
				'label'              => 'AD Groups',
				'public'             => true,
				'show_in_rest'       => false,
				'publicly_queryable' => false,
				// This line causes a fatal error when saving Quick Edit:
				'meta_box_cb'        => 'post_categories_meta_box'
			]
		);
	}

	public static function action_register_post_type() {
		$args = [
			'label'               => 'Chat',
			'supports'            => [ 'title', 'custom-fields' ],
			'taxonomies'          => [ self::AD_GROUPS_TAXONOMY_SLUG ],
			'hierarchical'        => false,
			'public'              => false,
			'show_ui'             => true,
			'show_in_menu'        => true,
			'show_admin_column'   => true,
			'menu_position'       => 24,
			'menu_icon'           => 'dashicons-groups',
			'show_in_admin_bar'   => false,
			'show_in_nav_menus'   => false,
			'can_export'          => true,
			'has_archive'         => false,
			'exclude_from_search' => true,
			'publicly_queryable'  => true,
			'capability_type'     => 'page',
		];

		register_post_type( self::$post_type, $args );
	}
}

Chat_Post_Type::init();
