// ========================================================
// SECURITE WORDPRESS
// ========================================================
if (!defined('ABSPATH')) {
exit;
}
// ========================================================
// VERSION CHILD THEME
// ========================================================
define('KALLYAS_CHILD_VERSION', '1.0.0');
// ========================================================
// CPT : MEMBRES
// ========================================================
add_action('init', function () {
register_post_type('membre', [
'labels' => [
'name' => 'Membres',
'singular_name' => 'Membre',
'menu_name' => 'Membres',
'add_new' => 'Ajouter un membre',
'add_new_item' => 'Ajouter un membre',
'edit_item' => 'Profil membre',
'new_item' => 'Nouveau membre',
'view_item' => 'Voir le profil',
'search_items' => 'Rechercher un membre',
'not_found' => 'Aucun membre trouvé',
'not_found_in_trash' => 'Aucun membre dans la corbeille'
],
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-groups',
'supports' => ['title', 'thumbnail'],
'rewrite' => ['slug' => 'membres'],
'show_in_rest' => true
]);
});
// ========================================================
// META BOX MEMBRE
// ========================================================
add_action('add_meta_boxes', function () {
add_meta_box(
'membre_infos',
'Fiche membre',
function ($post) {
wp_nonce_field('save_membre', 'membre_nonce');
$nom = get_post_meta($post->ID, '_nom', true);
$prenom = get_post_meta($post->ID, '_prenom', true);
$email = get_post_meta($post->ID, '_member_email', true);
$tel = get_post_meta($post->ID, '_tel', true);
echo '
';
echo '
Identité
';
echo '';
echo '';
echo 'Contact
';
echo '';
echo '';
echo '';
},
'membre',
'normal',
'high'
);
});
// ========================================================
// SAVE SECURISÉ + TITRE AUTO
// ========================================================
add_action('save_post_membre', function ($post_id) {
static $running = false;
if ($running) return;
$running = true;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (
!isset($_POST['membre_nonce']) ||
!wp_verify_nonce($_POST['membre_nonce'], 'save_membre')
) return;
if (!current_user_can('edit_post', $post_id)) return;
$nom = sanitize_text_field($_POST['nom'] ?? '');
$prenom = sanitize_text_field($_POST['prenom'] ?? '');
$email = sanitize_email($_POST['member_email'] ?? '');
$tel = sanitize_text_field($_POST['tel'] ?? '');
update_post_meta($post_id, '_nom', $nom);
update_post_meta($post_id, '_prenom', $prenom);
update_post_meta($post_id, '_member_email', $email);
update_post_meta($post_id, '_tel', $tel);
if ($nom || $prenom) {
wp_update_post([
'ID' => $post_id,
'post_title' => trim($nom . ' ' . $prenom)
]);
}
$running = false;
}, 10, 1);
// ========================================================
// AJAX : LISTE MEMBRES (ALPHABET)
// ========================================================
add_action('wp_ajax_get_membres', 'get_membres');
function get_membres() {
$letter = isset($_POST['letter']) ? sanitize_text_field($_POST['letter']) : 'ALL';
$query = new WP_Query([
'post_type' => 'membre',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC'
]);
$data = [];
while ($query->have_posts()) {
$query->the_post();
$nom = get_post_meta(get_the_ID(), '_nom', true);
$prenom = get_post_meta(get_the_ID(), '_prenom', true);
if ($letter !== 'ALL') {
if (strtoupper(substr($nom, 0, 1)) !== $letter) {
continue;
}
}
$data[] = [
'id' => get_the_ID(),
'nom' => $nom,
'prenom' => $prenom
];
}
wp_reset_postdata();
wp_send_json($data);
}
// ========================================================
// AJAX : FICHE MEMBRE
// ========================================================
add_action('wp_ajax_get_membre', 'get_membre');
function get_membre() {
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
if (!$id) {
wp_send_json([]);
}
$data = [
'nom' => sanitize_text_field(get_post_meta($id, '_nom', true)),
'prenom' => sanitize_text_field(get_post_meta($id, '_prenom', true)),
'email' => sanitize_email(get_post_meta($id, '_member_email', true)),
'tel' => sanitize_text_field(get_post_meta($id, '_tel', true)),
];
wp_send_json($data);
}
https://pressediplo.com/page-sitemap.xml
2026-04-14T14:46:58+00:00