Olivier Niel
L'Invité(e)
<?php
/*
Plugin Name: LBDC Interviews
Plugin URI: https://leblogducommercial.fr
Description: Ajoute une section « Interviews » dédiée pour gérer les portraits d’experts (Custom Post Type).
Version: 1.0
Author: Assistant IA
Author URI: https://leblogducommercial.fr
License: GPL2
*/
if ( ! defined( ‘ABSPATH’ ) ) {
exit; // Sécurité
}
// 1. Enregistrement du Custom Post Type « Interview »
function lbdc_register_interview_cpt() {
$labels = array(
‘name’ => _x( ‘Interviews’, ‘Post Type General Name’, ‘lbdc’ ),
‘singular_name’ => _x( ‘Interview’, ‘Post Type Singular Name’, ‘lbdc’ ),
‘menu_name’ => __( ‘Interviews’, ‘lbdc’ ),
‘name_admin_bar’ => __( ‘Interview’, ‘lbdc’ ),
‘archives’ => __( ‘Archives des interviews’, ‘lbdc’ ),
‘attributes’ => __( ‘Attributs’, ‘lbdc’ ),
‘parent_item_colon’ => __( ‘Interview parente :’, ‘lbdc’ ),
‘all_items’ => __( ‘Toutes les interviews’, ‘lbdc’ ),
‘add_new_item’ => __( ‘Ajouter une nouvelle interview’, ‘lbdc’ ),
‘add_new’ => __( ‘Ajouter’, ‘lbdc’ ),
‘new_item’ => __( ‘Nouvelle interview’, ‘lbdc’ ),
‘edit_item’ => __( ‘Modifier l\’interview’, ‘lbdc’ ),
‘update_item’ => __( ‘Mettre à jour’, ‘lbdc’ ),
‘view_item’ => __( ‘Voir l\’interview’, ‘lbdc’ ),
‘view_items’ => __( ‘Voir les interviews’, ‘lbdc’ ),
‘search_items’ => __( ‘Rechercher une interview’, ‘lbdc’ ),
‘not_found’ => __( ‘Aucune interview trouvée’, ‘lbdc’ ),
‘not_found_in_trash’ => __( ‘Aucune interview dans la corbeille’, ‘lbdc’ ),
‘featured_image’ => __( ‘Photo de l\’invité’, ‘lbdc’ ),
‘set_featured_image’ => __( ‘Définir la photo’, ‘lbdc’ ),
‘remove_featured_image’ => __( ‘Retirer la photo’, ‘lbdc’ ),
‘use_featured_image’ => __( ‘Utiliser comme photo’, ‘lbdc’ ),
‘insert_into_item’ => __( ‘Insérer dans l\’interview’, ‘lbdc’ ),
‘uploaded_to_this_item’ => __( ‘Téléversé sur cette interview’, ‘lbdc’ ),
‘items_list’ => __( ‘Liste des interviews’, ‘lbdc’ ),
‘items_list_navigation’ => __( ‘Navigation de la liste’, ‘lbdc’ ),
‘filter_items_list’ => __( ‘Filtrer la liste’, ‘lbdc’ ),
);
$args = array(
‘label’ => __( ‘Interview’, ‘lbdc’ ),
‘description’ => __( ‘Portraits et entretiens avec des experts’, ‘lbdc’ ),
‘labels’ => $labels,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘excerpt’, ‘custom-fields’, ‘revisions’ ),
‘taxonomies’ => array( ‘category’, ‘post_tag’ ), // On garde les catégories standards pour le filtrage facile
‘hierarchical’ => false,
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘menu_position’ => 5,
‘menu_icon’ => ‘dashicons-microphone’, // Icône micro cool
‘show_in_admin_bar’ => true,
‘show_in_nav_menus’ => true,
‘can_export’ => true,
‘has_archive’ => true,
‘exclude_from_search’ => false,
‘publicly_queryable’ => true,
‘capability_type’ => ‘post’,
‘show_in_rest’ => true, // Important pour Gutenberg
‘rewrite’ => array(‘slug’ => ‘interview’),
);
register_post_type( ‘interview’, $args );
}
add_action( ‘init’, ‘lbdc_register_interview_cpt’, 0 );
// 2. (Optionnel) Champs personnalisés simples pour Poste et Entreprise
// Ajoute une metabox dans l’éditeur
function lbdc_interview_add_meta_boxes() {
add_meta_box(
‘lbdc_interview_details’,
‘Détails de l\’Invité’,
‘lbdc_interview_meta_box_callback’,
‘interview’,
‘side’,
‘high’
);
}
add_action( ‘add_meta_boxes’, ‘lbdc_interview_add_meta_boxes’ );
function lbdc_interview_meta_box_callback( $post ) {
wp_nonce_field( ‘lbdc_interview_save_meta_box_data’, ‘lbdc_interview_meta_box_nonce’ );
$job_title = get_post_meta( $post->ID, ‘_lbdc_job_title’, true );
$company = get_post_meta( $post->ID, ‘_lbdc_company’, true );
echo ‘<p><label for= »lbdc_job_title »>Poste / Rôle :</label><br>’;
echo ‘<input type= »text » id= »lbdc_job_title » name= »lbdc_job_title » value= »‘ . esc_attr( $job_title ) . ‘ » style= »width:100% » placeholder= »ex: VP Sales »></p>’;
echo ‘<p><label for= »lbdc_company »>Entreprise :</label><br>’;
echo ‘<input type= »text » id= »lbdc_company » name= »lbdc_company » value= »‘ . esc_attr( $company ) . ‘ » style= »width:100% » placeholder= »ex: Salesforce »></p>’;
}
function lbdc_interview_save_meta_box_data( $post_id ) {
if ( ! isset( $_POST[‘lbdc_interview_meta_box_nonce’] ) ) return;
if ( ! wp_verify_nonce( $_POST[‘lbdc_interview_meta_box_nonce’], ‘lbdc_interview_save_meta_box_data’ ) ) return;
if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return;
if ( ! current_user_can( ‘edit_post’, $post_id ) ) return;
if ( isset( $_POST[‘lbdc_job_title’] ) ) {
update_post_meta( $post_id, ‘_lbdc_job_title’, sanitize_text_field( $_POST[‘lbdc_job_title’] ) );
}
if ( isset( $_POST[‘lbdc_company’] ) ) {
update_post_meta( $post_id, ‘_lbdc_company’, sanitize_text_field( $_POST[‘lbdc_company’] ) );
}
}
add_action( ‘save_post’, ‘lbdc_interview_save_meta_box_data’ );
?>