<?php
// Change Defaults Posts to "News" in menu bar
function cp_change_post_object()
{
	$get_post_type = get_post_type_object('post');

	$labels = $get_post_type->labels;
	$labels->name = 'News';
	$labels->singular_name = 'News';
	$labels->add_new = 'Ajouter une Actu';
	$labels->add_new_item = 'Ajouter une Actu';
	$labels->edit_item = 'Editer l\'actualité';
	$labels->new_item = 'News';
	$labels->view_item = 'Voir l\'actualité';
	$labels->search_items = 'Chercher une Actualité';
	$labels->not_found = 'Pas de News trouvée';
	$labels->not_found_in_trash = 'Pas de News trouvée dans la corbeille';
	$labels->all_items = 'Toutes les Actus';
	$labels->menu_name = 'News';
	$labels->name_admin_bar = 'News';
}
add_action('init', 'cp_change_post_object');


// Change Defaults Posts Icon in menu bar

function change_menu_icon()
{

	// Access global variables.
	global $menu;

	foreach ($menu as $key => $val) {

		if (__('News', 'homegrade-theme__texte-backoffice') == $val[0]) {
			$menu[$key][6] = 'dashicons-welcome-widgets-menus';
		}
	}
}
add_action('admin_menu', 'change_menu_icon');

// #### POST TYPES
function create_posttype()
{

	if (get_current_blog_id() != 1) {
		return;
	}
	// **** CONSEILS
	register_post_type(
		'conseils',
		array(
			'labels' => array(
				'name' => __('Conseils', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Conseil', 'homegrade-theme__texte-backoffice')
			),
			'template' => [
				array('homegrade-content-blocks/chapter-header'),
				array('core/paragraph', ['placeholder' => 'Add truc  Description…',]),
			],
			'hierarchical' => true,
			'public' => true,
			'has_archive' => false,
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-pressthis',
			'menu_position'       => 2,
			'supports'     => array('title', 'editor', 'page-attributes', 'thumbnail', 'revisions', 'excerpt'),

			// 'supports' => array('title', 'custom-fields', 'editor'),
		)
	);

	// **** BROCHURES
	register_post_type(
		'brochures',
		array(
			'labels' => array(
				'name' => __('Brochures', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Brochure', 'homegrade-theme__texte-backoffice')
			),
			'hierarchical' => true,
			'show_in_rest' => true,
			'public' => true,
			'has_archive' => false,
			'menu_icon'           => 'dashicons-book',
			'menu_position'       => 2,
			'position'       => 2,
			'supports' => array('custom-fields', 'page-attributes', 'title'),
		)
	);

	// **** QUESTIONS
	register_post_type(
		'questions',
		array(
			'labels' => array(
				'name' => __('Questions', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Question', 'homegrade-theme__texte-backoffice'),
				'add_new' => __('Ajouter', 'homegrade-theme__texte-backoffice'),
				'add_new_item' => __('Ajouter une question', 'homegrade-theme__texte-backoffice'),
				'new_item' => __('Nouvelle question', 'homegrade-theme__texte-backoffice'),
				'edit_item' => __('Modifier la question', 'homegrade-theme__texte-backoffice'),
				'view_item' => __('Voir la question', 'homegrade-theme__texte-backoffice'),
				'all_items' => __('Toutes les questions', 'homegrade-theme__texte-backoffice'),
				'search_items' => __('Rechercher des questions', 'homegrade-theme__texte-backoffice'),
				'not_found' => __('Aucune question trouvée', 'homegrade-theme__texte-backoffice'),
				'not_found_in_trash' => __('Aucune question trouvée dans la corbeille', 'homegrade-theme__texte-backoffice')
			),
			'public' => true,
			'has_archive' => false,
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-editor-help',
			'menu_position'       => 2.1,
			'supports' => array('title', 'custom-fields', 'editor', 'excerpt', 'revisions'),

			// 'rewrite' => array('slug' => 'questions'),
			// 'rewrite' => array('slug' => 'questions/%thematiques%'),
		)
	);

	// **** FICHES-INFOS
	register_post_type(
		'fiches-infos',
		array(
			'labels' => array(
				'name' => __('Fiches info', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Fiches Info', 'homegrade-theme__texte-backoffice')
			),
			'public' => true,
			'has_archive' => false,
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-info-outline',
			'menu_position'       => 2.1,
			'supports' => array('title', 'custom-fields'),
		)
	);

	// **** VOCABULAIRE
	register_post_type(
		'vocabulaire',
		array(
			'labels' => array(
				'name' => __('Vocabulaire', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Vocabulaire', 'homegrade-theme__texte-backoffice')
			),
			'public' => true,
			'has_archive' => true,
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-testimonial',
			'menu_position'       => 5.1,
			'supports' => array('title', 'custom-fields'),
		)
	);

	// **** JOBS
	register_post_type(
		'jobs',
		array(
			'labels' => array(
				'name' => __('Jobs', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Job', 'homegrade-theme__texte-backoffice')
			),
			'rewrite' => array('slug' => 'job'),
			'public' => true,
			'has_archive' => true,
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-id-alt',
			'menu_position'       => 5.1,
			'supports'     => array('title', 'editor', 'custom-fields', 'page-attributes'),

		)
	);

	// **** VIDEOS / WEBINAIRES
	register_post_type(
		'videos-webinaires',
		array(
			'labels' => array(
				'name' => __('Webinaires', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Webinaire', 'homegrade-theme__texte-backoffice')
			),
			'public' => true,
			'has_archive' => true,
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-video-alt2',
			'menu_position'       => 5.1,
			'supports' => array('title', 'custom-fields'),
			'supports'     => array('title', 'custom-fields', 'excerpt', 'thumbnail'),

		)
	);

	// **** VIDEOS / WEBINAIRES
	register_post_type(
		'parcours',
		array(
			'labels' => array(
				'name' => __('Parcours', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Parcours', 'homegrade-theme__texte-backoffice')
			),
			'public' => true,
			'has_archive' => true,
			'hierarchical' => true,
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-forms',
			'supports' => array('title', 'custom-fields'),
			'supports'     => array('title', 'editor', 'page-attributes', 'thumbnail', 'revisions', 'excerpt'),

		)
	);
}

add_action('init', 'create_posttype');
