<?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()
{
	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'),
			// 'supports' => array('title', 'custom-fields', 'editor'),
		)
	);

	register_post_type(
		'brochures',
		array(
			'labels' => array(
				'name' => __('Brochures', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Brochure', 'homegrade-theme__texte-backoffice')
			),
			'hierarchical' => true,
			'public' => true,
			'has_archive' => false,
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-book',
			'menu_position'       => 2,
			'position'       => 2,
			'supports' => array('custom-fields', 'page-attributes', 'title'),
		)
	);
	register_post_type(
		'questions',
		array(
			'labels' => array(
				'name' => __('Questions', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Question', 'homegrade-theme__texte-backoffice')
			),
			'public' => true,
			'has_archive' => false,
			// 'rewrite' => array('slug' => 'questions'),
			// 'rewrite' => array('slug' => 'questions/%thematiques%'),
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-editor-help',
			'menu_position'       => 2.1,
			'supports' => array('title', 'custom-fields', 'editor', 'excerpt'),
		)
	);
	register_post_type(
		'fiches-infos',
		array(
			'labels' => array(
				'name' => __('Fiches Infos', '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'),
		)
	);
	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,
			'rewrite' => array('slug' => 'fiche'),
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-testimonial',
			'menu_position'       => 5.1,
			'supports' => array('title', 'custom-fields'),
		)
	);
	register_post_type(
		'jobs',
		array(
			'labels' => array(
				'name' => __('Jobs', 'homegrade-theme__texte-backoffice'),
				'singular_name' => __('Job', 'homegrade-theme__texte-backoffice')
			),
			'public' => true,
			'has_archive' => true,
			'rewrite' => array('slug' => 'fiche'),
			'show_in_rest' => true,
			'menu_icon'           => 'dashicons-id-alt',
			'menu_position'       => 5.1,
			'supports'     => array('title', 'editor', 'custom-fields', 'page-attributes'),

		)
	);
	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'),

		)
	);
}

add_action('init', 'create_posttype');
