<?php


function cpt_customer()
{

	register_post_type(
		'customer',
		array(
			'label' => __('Customers'),
			'singular_label' => __('Customer'),
			'public' => true,
			'show_ui' => true,
			'_builtin' => false,
			'_edit_link' => 'post.php?post=%d',
			'capability_type' => 'post',
			'hierarchical' => false,
			'rewrite' => array("slug" => "customers"),
			'query_var' => "customers",
			'supports' => array('title', 'editor', 'thumbnail') //titre + zone de texte + champs personnalisés + miniature valeur possible : 'title','editor','author','thumbnail','excerpt'
		)
	);
	register_taxonomy_for_object_type('post_tag', 'customer', 'show_tagcloud=1&hierarchical=true');


	register_post_type(
		'portfolio',
		array(
			'label' => __('Projets'),
			'singular_label' => __('Projets'),
			'public' => true,
			'menu_icon'           => 'dashicons-forms',
			'show_ui' => true,
			'hierarchical' => false,
			'supports' => array('title', 'thumbnail', 'editor', 'excerpt', 'custom-fields', 'revisions', 'page-attributes'),
			'show_in_rest'       => true, // Active l'éditeur de blocs (Gutenberg).
			'rewrite' => array('slug' => 'projets'),

		)
	);
}
add_action('init', 'cpt_customer');

function my_custom_post_type() {}

add_action('init', 'my_custom_post_type');




/* ----------------------------------------------------------------------
	DÉCLARATION DES COLONNES CUSTOM DANS LA LISTE DES POSTS ARTISANS
 ------------------------------------------------------------------------*/

// ****  AJOUT DES COLONNES
function deligraph_projets_add_acf_posts_columns($columns)
{
	global $current_screen;


	$customColumns = array(
		'client' => 'Client',
	);
	$new_admin_col_arrays = array_slice($columns, 0, 2, true) + $customColumns +  array_slice($columns, 2, count($columns) - 2, true);
	return array_merge($new_admin_col_arrays);
}
add_filter('manage_portfolio_posts_columns', 'deligraph_projets_add_acf_posts_columns');



/* ----------------------------------------------------------------------
	GESTION DE LA VALEUR DE CHAQUE COLONNE
 ------------------------------------------------------------------------*/
function deligraph_projets_handle_posts_custom_columns($column)
{

	$post_id = get_the_ID();

	if ($column == 'client') {
		$client = get_field('client_name', $post_id);
		if (!$client) return;
		echo $client;
	}
}
add_action('manage_portfolio_posts_custom_column', 'deligraph_projets_handle_posts_custom_columns', 10, 2);
