'articles', 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => 'related_revue', 'value' => $revueID, 'compare' => '=', ), ), )); $authors = array(); foreach ($revueRelatedArticles->posts as $article) { $currentArticleAuthors = get_field('authors', $article->ID); if (empty($currentArticleAuthors) || !is_array($currentArticleAuthors)) continue; foreach ($currentArticleAuthors as $authorID) { $authors[] = $authorID; } } return array_unique($authors); } function get_revue_terms($revueID, $taxonomy) { $revueRelatedArticles = new WP_Query(array( 'post_type' => 'articles', 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => 'related_revue', 'value' => $revueID, 'compare' => '=', ), ), )); $terms = array(); foreach ($revueRelatedArticles->posts as $article) { $currentArticleTerms = get_the_terms($article->ID, $taxonomy); if (empty($currentArticleTerms) || !is_array($currentArticleTerms)) continue; foreach ($currentArticleTerms as $term) { $terms[] = $term->term_id; } } foreach (array_unique($terms) as $term) { $termObject = get_term($term, $taxonomy); $uniquesTermsArray[] = $termObject; } return $uniquesTermsArray; } function count_user_articles($userID, $postType) { $args = array( 'post_type' => $postType, 'meta_query' => array( array( 'key' => 'authors', 'value' => '"' . $userID . '"', 'compare' => 'LIKE', ), ), ); $query = new WP_Query($args); return $query->found_posts; } function build_sommaire_from_content($postID) { $blocks = parse_blocks(get_the_content($postID)); $titleBlocks = array_filter( $blocks, function ($block) { // Vérifier si c'est un bloc heading if ($block['blockName'] !== 'core/heading') { return false; } // Extraire le niveau depuis le HTML si les attributs sont vides if (empty($block['attrs']['level'])) { // Chercher seulement h2 dans le HTML if (preg_match('/]*>/i', $block['innerHTML'], $matches)) { return true; } return false; } // Utiliser le niveau des attributs s'il existe return $block['attrs']['level'] === 2; } ); $outputIndex = []; foreach ($titleBlocks as $block) { $title = strip_tags($block['innerHTML']); // Extraire le niveau depuis le HTML ou les attributs $level = $block['attrs']['level'] ?? null; if (!$level && preg_match('/]*>/i', $block['innerHTML'], $matches)) { $level = 2; } if ($level !== 2) continue; $anchor = $block['attrs']['idName'] ?? sanitize_title($title); // Ajouter un préfixe si l'ancre commence par un chiffre if (!empty($anchor) && preg_match('/^[0-9]/', $anchor)) { $anchor = 'anchor-' . $anchor; } $outputIndex[] = [ 'title' => $title, 'anchor' => $anchor, 'level' => $level, ]; } return $outputIndex; } function build_footnotes_index_from_content($content) { if (empty($content)) { return []; } $footnotes = []; // Trouve les balises avec classe footnote-reference ET attribut footnote-content (ordre flexible) $pattern = '/]*class="[^"]*footnote-reference[^"]*"[^>]*footnote-content="([^"]*)"[^>]*>|]*footnote-content="([^"]*)"[^>]*class="[^"]*footnote-reference[^"]*"[^>]*>/i'; $has_footnotes = preg_match_all($pattern, $content, $matches, PREG_SET_ORDER); if ($has_footnotes) { foreach ($matches as $index => $match) { // Le contenu peut être dans match[1] ou match[2] selon l'ordre des attributs $footnote_content = !empty($match[1]) ? $match[1] : $match[2]; if (!empty($footnote_content)) { $footnotes[] = array( 'key' => $index + 1, 'anchorID' => $index + 1, 'content' => $footnote_content ); } } } return $footnotes; } function apply_footnotes_urls_to_content($content) { $post_type = get_post_type(); if ($post_type !== 'articles' && !is_admin()) return $content; // Compter les références de notes de bas de page $footnote_count = 0; // Utiliser preg_replace_callback pour traiter chaque occurrence individuellement $content = preg_replace_callback( '/]*class="[^"]*footnote-reference[^"]*"[^>]*)>/i', function ($matches) use (&$footnote_count) { $footnote_count++; return ''; }, $content ); return $content; } add_filter('the_content', 'apply_footnotes_urls_to_content', 10);