true,
'edit_posts' => false,
'edit_pages' => false,
'publish_posts' => false,
'upload_files' => false,
'delete_posts' => false,
'moderate_comments' => false,
)
);
}
// --- Rôle ANIMATEUR ---
if ( ! get_role( 'animateur' ) ) {
add_role(
'animateur',
'Animateur',
array(
'read' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'delete_posts' => true,
'delete_published_posts' => true,
'publish_posts' => true,
'edit_pages' => true,
'edit_published_pages' => true,
'publish_pages' => true,
'delete_pages' => true,
'delete_published_pages' => true,
'upload_files' => true,
)
);
}
}
add_action( 'init', 'dp_creer_roles_personnalises' );
// ============================================================================
// 3) Shortcode [page_discussion] : zone de discussion liée à la page
// ============================================================================
function dp_page_discussion_shortcode( $atts ) {
if ( ! is_singular() ) {
return '';
}
$post_id = get_the_ID();
if ( ! comments_open( $post_id ) ) {
return '
La discussion n’est pas ouverte pour cette page.
';
}
ob_start();
?>
Discussion
$post_id,
'status' => 'approve',
'order' => 'ASC',
) );
if ( ! empty( $comments ) ) :
?>
Aucun message pour le moment. Lancez la discussion !
'Ajouter un message',
'title_reply_to' => 'Répondre à %s',
'label_submit' => 'Envoyer',
'comment_notes_before' => '',
'comment_notes_after' => '',
), $post_id );
?>
'Sources',
'singular_name' => 'Source',
'search_items' => 'Rechercher des sources',
'all_items' => 'Toutes les sources',
'parent_item' => 'Source parente',
'parent_item_colon' => 'Source parente :',
'edit_item' => 'Modifier la source',
'update_item' => 'Mettre à jour la source',
'add_new_item' => 'Ajouter une nouvelle source',
'new_item_name' => 'Nom de la nouvelle source',
'menu_name' => 'Sources',
);
$args = array(
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'rewrite' => array( 'slug' => 'sources' ),
);
register_taxonomy( 'sources', array( 'post' ), $args );
}
add_action( 'init', 'journal_register_taxonomy_sources' );
// ============================================================================
// 5) Fonction utilitaire : afficher un arbre hiérarchique de taxonomie
// ============================================================================
function journal_afficher_arbre_taxonomie( $taxonomy, $title ) {
$terms = get_terms( array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
));
if ( empty( $terms ) || is_wp_error( $terms ) ) {
return 'Aucun terme trouvé pour : ' . esc_html( $taxonomy ) . '
';
}
// Hiérarchie parent -> enfants
$hierarchie = array();
foreach ( $terms as $term ) {
$hierarchie[ $term->parent ][] = $term;
}
$selected = array();
if ( isset( $_GET['tax_query'][ $taxonomy ] ) && is_array( $_GET['tax_query'][ $taxonomy ] ) ) {
$selected = array_map( 'intval', $_GET['tax_query'][ $taxonomy ] );
}
$build_tree = function( $parent_id ) use ( &$build_tree, $hierarchie, $selected, $taxonomy ) {
if ( ! isset( $hierarchie[ $parent_id ] ) ) {
return '';
}
$html = '';
return $html;
};
return '' . esc_html( $title ) . '
' . $build_tree( 0 );
}
// ============================================================================
// 6) Shortcode [blog_filtrable_relevanssi]
// ============================================================================
function journal_shortcode_blog_filtrable_relevanssi( $atts = array() ) {
$atts = shortcode_atts(
array(
'post_type' => 'post',
'taxonomies' => 'category,sources',
'per_page' => 10,
'order_by' => 'date',
'order' => 'DESC',
'intro' => '',
),
$atts,
'blog_filtrable_relevanssi'
);
$post_type = sanitize_text_field( $atts['post_type'] );
$per_page = max( 1, intval( $atts['per_page'] ) );
$order_by = sanitize_key( $atts['order_by'] );
$order = ( strtoupper( $atts['order'] ) === 'ASC' ) ? 'ASC' : 'DESC';
$intro = wp_kses_post( $atts['intro'] );
$taxonomies = array();
foreach ( explode( ',', $atts['taxonomies'] ) as $tx ) {
$tx = trim( $tx );
if ( $tx !== '' ) {
$taxonomies[] = $tx;
}
}
$search_term = isset( $_GET['bfrr_s'] ) ? sanitize_text_field( $_GET['bfrr_s'] ) : '';
$tax_query = array();
if ( isset( $_GET['tax_query'] ) && is_array( $_GET['tax_query'] ) ) {
foreach ( $_GET['tax_query'] as $taxonomy => $terms ) {
$terms = array_filter( array_map( 'intval', (array) $terms ) );
if ( ! empty( $terms ) ) {
$tax_query[] = array(
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => $terms,
'operator' => 'IN',
);
}
}
}
if ( count( $tax_query ) > 1 ) {
$tax_query = array_merge( array( 'relation' => 'AND' ), $tax_query );
}
// Texte "Filtre appliqué"
$filtre_applique = array();
foreach ( $taxonomies as $tx ) {
if ( isset( $_GET['tax_query'][ $tx ] ) && is_array( $_GET['tax_query'][ $tx ] ) ) {
$ids = array_filter( array_map( 'intval', $_GET['tax_query'][ $tx ] ) );
if ( ! empty( $ids ) ) {
$terms_tx = get_terms( array(
'taxonomy' => $tx,
'include' => $ids,
) );
if ( ! is_wp_error( $terms_tx ) && ! empty( $terms_tx ) ) {
$noms = wp_list_pluck( $terms_tx, 'name' );
$tax_obj = get_taxonomy( $tx );
$label = ( $tax_obj && ! empty( $tax_obj->labels->name ) )
? $tax_obj->labels->name
: ucfirst( $tx );
$filtre_applique[] = $label . ' : ' . implode( ', ', $noms );
}
}
}
}
if ( empty( $filtre_applique ) && empty( $search_term ) ) {
$filtre_applique_texte = 'Aucun filtre : tous les articles';
} else {
$parts = array();
if ( ! empty( $search_term ) ) {
$parts[] = 'Texte : « ' . $search_term . ' »';
}
if ( ! empty( $filtre_applique ) ) {
$parts = array_merge( $parts, $filtre_applique );
}
$filtre_applique_texte = 'Filtre appliqué : ' . implode( ' | ', $parts );
}
ob_start();
$page_obj = get_post();
if ( ! $page_obj ) {
return '';
}
$form_action = get_permalink( $page_obj->ID );
$form_action = strtok( $form_action, '?' );
if ( ! empty( $intro ) ) {
echo '' . $intro . '
';
}
echo '';
$paged = max(
1,
get_query_var( 'paged' )
? get_query_var( 'paged' )
: ( isset( $_GET['paged'] ) ? intval( $_GET['paged'] ) : 1 )
);
$args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
's' => $search_term,
'paged' => $paged,
'posts_per_page' => $per_page,
'orderby' => $order_by,
'order' => $order,
);
if ( ! empty( $tax_query ) ) {
$args['tax_query'] = $tax_query;
}
$query = new WP_Query( $args );
if ( function_exists( 'relevanssi_do_query' ) && ! empty( $search_term ) ) {
relevanssi_do_query( $query );
}
echo '';
echo '
' . esc_html( $filtre_applique_texte ) . '
';
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '
';
echo '';
echo '';
echo '';
}
echo paginate_links( array(
'total' => $query->max_num_pages,
'current' => $paged,
) );
} else {
echo '
Aucun article trouvé.
';
}
echo '
';
wp_reset_postdata();
?>
1,
),
$atts,
'dernier_article'
);
$nb = max( 1, intval( $atts['nb'] ) );
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $nb,
);
$query = new WP_Query( $args );
if ( ! $query->have_posts() ) {
return 'Aucun article trouvé.
';
}
ob_start();
while ( $query->have_posts() ) {
$query->the_post();
$post_id = get_the_ID();
$permalink = get_permalink();
echo '';
echo '';
echo 'Publié le ' . esc_html( get_the_date() ) . '
';
$cats_list = get_the_category_list( ', ' );
if ( $cats_list ) {
echo 'Catégories : ' . wp_kses_post( $cats_list ) . '
';
}
$sources = get_the_terms( $post_id, 'sources' );
if ( $sources && ! is_wp_error( $sources ) ) {
$sources_names = wp_list_pluck( $sources, 'name' );
echo 'Sources : ' . esc_html( implode( ', ', $sources_names ) ) . '
';
}
$tags_list = get_the_tag_list( '', ', ' );
if ( $tags_list ) {
echo 'Étiquettes : ' . wp_kses_post( $tags_list ) . '
';
}
echo '';
echo wp_kses_post( wp_trim_words( get_the_excerpt(), 55, '...' ) );
echo '
';
echo '';
echo 'Lire l’article complet';
echo '
';
echo '';
}
wp_reset_postdata();
return ob_get_clean();
}
}
add_shortcode( 'dernier_article', 'bfrr_dernier_article_shortcode' );
// ============================================================================
// 8) Injection du bouton "Vider la requête" en JS
// ============================================================================
add_action( 'wp_footer', function() {
?>
'atelier',
'singular_name' => 'Article atelier',
'menu_name' => 'Ateliers',
'name_admin_bar' => 'Atelier',
'add_new' => 'Ajouter',
'add_new_item' => 'Ajouter un article',
'new_item' => 'Nouvel article',
'edit_item' => 'Modifier l’article',
'view_item' => 'Voir l’article',
'all_items' => 'Tous les articles atelier',
'search_items' => 'Rechercher dans atelier',
'parent_item_colon' => 'Article parent :',
'not_found' => 'Aucun article trouvé.',
'not_found_in_trash' => 'Aucun article trouvé dans la corbeille.',
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'menu_position' => 21,
'menu_icon' => 'dashicons-welcome-write-blog',
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'author',
'comments',
),
'rewrite' => array(
'slug' => 'atelier',
'with_front' => true,
),
);
register_post_type( 'atelier', $args );
}
add_action( 'init', 'dp_register_atelier_cpt' );
function dp_register_atelier_sujet_taxonomy() {
$labels = array(
'name' => 'Sujets',
'singular_name' => 'Sujet',
'search_items' => 'Rechercher des sujets',
'all_items' => 'Tous les sujets',
'parent_item' => 'Sujet parent',
'parent_item_colon' => 'Sujet parent :',
'edit_item' => 'Modifier le sujet',
'update_item' => 'Mettre à jour le sujet',
'add_new_item' => 'Ajouter un nouveau sujet',
'new_item_name' => 'Nom du nouveau sujet',
'menu_name' => 'Sujet',
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'public' => true,
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'atelier-sujet',
),
);
register_taxonomy( 'atelier_sujet', array( 'atelier' ), $args );
}
add_action( 'init', 'dp_register_atelier_sujet_taxonomy' );
function dp_register_atelier_fiche_taxonomy() {
$labels = array(
'name' => 'fiche',
'singular_name' => 'fiche atelier',
'search_items' => 'Rechercher des fiches',
'all_items' => 'Tous les fiches',
'parent_item' => 'fiche parent',
'parent_item_colon' => 'fiche parent :',
'edit_item' => 'Modifier le fiche',
'update_item' => 'Mettre à jour le fiche',
'add_new_item' => 'Ajouter un nouveau fiche',
'new_item_name' => 'Nom du nouveau fiche',
'menu_name' => 'Fiche',
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'public' => true,
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'atelier-fiche',
),
);
register_taxonomy( 'atelier_fiche', array( 'atelier' ), $args );
}
add_action( 'init', 'dp_register_atelier_fiche_taxonomy' );