Compare commits
4 Commits
8d2d1c2897
...
cc20a0fff1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc20a0fff1 | ||
|
|
12a3af83ed | ||
|
|
6f277c7c83 | ||
|
|
ac60bde9a9 |
|
|
@ -16,3 +16,4 @@ require_once(__DIR__ . '/includes/wysiwyg.php');
|
||||||
require_once(__DIR__ . '/includes/search.php');
|
require_once(__DIR__ . '/includes/search.php');
|
||||||
require_once(__DIR__ . '/includes/rooting.php');
|
require_once(__DIR__ . '/includes/rooting.php');
|
||||||
require_once(__DIR__ . '/includes/forms.php');
|
require_once(__DIR__ . '/includes/forms.php');
|
||||||
|
require_once(__DIR__ . '/includes/admin-columns.php');
|
||||||
|
|
|
||||||
116
includes/admin-columns.php
Normal file
116
includes/admin-columns.php
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
<?php
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
GESTION DE LA COLONNE THEMATIQUE DANS LA LISTE DES POSTS CONSEILS
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// AJOUT D'UNE COLONNE CUSTOM
|
||||||
|
function add_acf_posts_columns($columns)
|
||||||
|
{
|
||||||
|
global $current_screen;
|
||||||
|
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + array('thematiques_taxo' => 'Thématique') + array_slice($columns, 2, count($columns) - 2, true);
|
||||||
|
return array_merge($new_admin_col_arrays);
|
||||||
|
}
|
||||||
|
add_filter('manage_conseils_posts_columns', 'add_acf_posts_columns');
|
||||||
|
add_filter('manage_questions_posts_columns', 'add_acf_posts_columns');
|
||||||
|
add_filter('manage_brochures_posts_columns', 'add_acf_posts_columns');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
CUSTOMISATION DE LA COLONNE POUR AFFICHER : THEMATIQUE PARENT > THEMATIQUE
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
function handle_posts_custom_columns($column, $post_id)
|
||||||
|
{
|
||||||
|
if ($column != 'thematiques_taxo') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$tax = get_the_terms($post_id, ('thematiques'));
|
||||||
|
$edit_link = esc_url(get_edit_term_link($tax[0]->term_id, 'thematiques', 'conseils'));
|
||||||
|
|
||||||
|
echo '<a href="' . $edit_link . '">';
|
||||||
|
if (isset($tax[0]->parent) && $tax[0]->parent != 0) {
|
||||||
|
$tax_parent = get_term($tax[0]->parent, 'thematiques');
|
||||||
|
echo $tax_parent->name . " — ";
|
||||||
|
}
|
||||||
|
echo $tax[0]->name;
|
||||||
|
echo '</a>';
|
||||||
|
}
|
||||||
|
add_action('manage_conseils_posts_custom_column', 'handle_posts_custom_columns', 10, 2);
|
||||||
|
add_action('manage_questions_posts_custom_column', 'handle_posts_custom_columns', 10, 2);
|
||||||
|
add_action('manage_brochures_posts_custom_column', 'handle_posts_custom_columns', 10, 2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
GESTION DU FILTRAGE
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
// **** CREATION DES DROPDOWN SELECT DE FILTRAGE
|
||||||
|
function homegrade_brochures_filter_posts_declare_dropdowns()
|
||||||
|
{
|
||||||
|
global $typenow;
|
||||||
|
global $wp_meta_boxes;
|
||||||
|
|
||||||
|
$post_type = (isset($_GET['post_type'])) ? $_GET['post_type'] : 'post';
|
||||||
|
if ($post_type !== 'brochures' && $post_type !== 'fiches-infos' && $post_type !== 'videos-webinaires' && $post_type !== 'conseils' && $post_type !== 'questions') return;
|
||||||
|
|
||||||
|
$thematiques_by_parent = getAllThematiquesTermsByParents();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<select name="thematiques">
|
||||||
|
<option value="" class="please-select"><?php _e('Thématique', 'homegrade-theme'); ?></option>
|
||||||
|
<?php
|
||||||
|
$is_current = isset($_GET['thematiques']) ? $_GET['thematiques'] : '';
|
||||||
|
foreach ($thematiques_by_parent as $index => $parent_term_data) {
|
||||||
|
$parent_term = $parent_term_data['term'];
|
||||||
|
|
||||||
|
// Afficher le parent
|
||||||
|
printf(
|
||||||
|
'<option value="%s"%s>%s</option>',
|
||||||
|
$parent_term->slug,
|
||||||
|
$parent_term->slug == $is_current ? ' selected="selected"' : '',
|
||||||
|
$parent_term->name
|
||||||
|
);
|
||||||
|
|
||||||
|
// Afficher les enfants avec indentation
|
||||||
|
if (!empty($parent_term_data['children'])) {
|
||||||
|
foreach ($parent_term_data['children'] as $child_term) {
|
||||||
|
printf(
|
||||||
|
'<option value="%s"%s>— %s</option>',
|
||||||
|
$child_term->slug,
|
||||||
|
$child_term->slug == $is_current ? ' selected="selected"' : '',
|
||||||
|
$child_term->name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action('restrict_manage_posts', 'homegrade_brochures_filter_posts_declare_dropdowns');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
SUPPRIMER LA COLONNE RANK MATH SEO SI ELLE EST PRÉSENTE
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
function remove_rank_math_seo_column_for_artisans($columns)
|
||||||
|
{
|
||||||
|
if (isset($columns['rank_math_seo_details'])) {
|
||||||
|
unset($columns['rank_math_seo_details']);
|
||||||
|
}
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Appliquer le filtre uniquement pour le post type "artisans"
|
||||||
|
add_filter('manage_brochures_posts_columns', 'remove_rank_math_seo_column_for_artisans', 20);
|
||||||
|
|
@ -62,7 +62,6 @@ function my_custom_login_url($url)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------
|
/* ----------------------------------
|
||||||
ENQUEUE DU COLOR SCHEME ADMIN
|
ENQUEUE DU COLOR SCHEME ADMIN
|
||||||
-----------------------------------*/
|
-----------------------------------*/
|
||||||
|
|
@ -163,106 +162,6 @@ function change_login_logo_url($url)
|
||||||
add_filter('login_headerurl', 'change_login_logo_url');
|
add_filter('login_headerurl', 'change_login_logo_url');
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
|
||||||
GESTION DE LA COLONNE THEMATIQUE DANS LA LISTE DES POSTS CONSEILS
|
|
||||||
------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
// AJOUT D'UNE COLONNE CUSTOM
|
|
||||||
function add_acf_posts_columns($columns)
|
|
||||||
{
|
|
||||||
global $current_screen;
|
|
||||||
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + array('thematiques_taxo' => 'Thématique') + array_slice($columns, 2, count($columns) - 2, true);
|
|
||||||
return array_merge($new_admin_col_arrays);
|
|
||||||
}
|
|
||||||
add_filter('manage_conseils_posts_columns', 'add_acf_posts_columns');
|
|
||||||
add_filter('manage_questions_posts_columns', 'add_acf_posts_columns');
|
|
||||||
add_filter('manage_brochures_posts_columns', 'add_acf_posts_columns');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
|
||||||
CUSTOMISATION DE LA COLONNE POUR AFFICHER : THEMATIQUE PARENT > THEMATIQUE
|
|
||||||
------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
function handle_posts_custom_columns($column, $post_id)
|
|
||||||
{
|
|
||||||
if ($column != 'thematiques_taxo') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$tax = get_the_terms($post_id, ('thematiques'));
|
|
||||||
$edit_link = esc_url(get_edit_term_link($tax[0]->term_id, 'thematiques', 'conseils'));
|
|
||||||
|
|
||||||
echo '<a href="' . $edit_link . '">';
|
|
||||||
if (isset($tax[0]->parent) && $tax[0]->parent != 0) {
|
|
||||||
$tax_parent = get_term($tax[0]->parent, 'thematiques');
|
|
||||||
echo $tax_parent->name . " — ";
|
|
||||||
}
|
|
||||||
echo $tax[0]->name;
|
|
||||||
echo '</a>';
|
|
||||||
}
|
|
||||||
add_action('manage_conseils_posts_custom_column', 'handle_posts_custom_columns', 10, 2);
|
|
||||||
add_action('manage_questions_posts_custom_column', 'handle_posts_custom_columns', 10, 2);
|
|
||||||
add_action('manage_brochures_posts_custom_column', 'handle_posts_custom_columns', 10, 2);
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------
|
|
||||||
CREATION DU DROPDOWN SELECT AVEC LES OPTIONS
|
|
||||||
---------------------------------------------*/
|
|
||||||
|
|
||||||
function filter_posts_per_thematique_declare_dropdown()
|
|
||||||
{
|
|
||||||
global $pagenow;
|
|
||||||
$post_type = (isset($_GET['post_type'])) ? $_GET['post_type'] : 'post';
|
|
||||||
|
|
||||||
//only add filter to post type you want
|
|
||||||
if ($post_type == 'questions') {
|
|
||||||
$all_thematiques = get_terms([
|
|
||||||
'taxonomy' => 'thematiques',
|
|
||||||
'hide_empty' => true,
|
|
||||||
]);
|
|
||||||
?>
|
|
||||||
<select name="thematiques">
|
|
||||||
<option value=""><?php _e('Filtrer par Thématique', 'homegrade-theme__texte-backoffice'); ?></option>
|
|
||||||
<?php
|
|
||||||
$current_v = isset($_GET['thematiques']) ? $_GET['thematiques'] : '';
|
|
||||||
foreach ($all_thematiques as $index => $thematique) {
|
|
||||||
printf(
|
|
||||||
'<option value="%s"%s>%s</option>',
|
|
||||||
$thematique->slug,
|
|
||||||
$thematique->slug == $current_v ? ' selected="selected"' : '',
|
|
||||||
$thematique->name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</select>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('restrict_manage_posts', 'filter_posts_per_thematique_declare_dropdown');
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------
|
|
||||||
FILTRAGE DES POSTS QUAND LA QUERY DE FILTER EST ENVOYEE
|
|
||||||
--------------------------------------------------------*/
|
|
||||||
|
|
||||||
function filter_post_by_thematiques_query($query)
|
|
||||||
{
|
|
||||||
global $pagenow;
|
|
||||||
$type = 'questions'; // change to custom post name.
|
|
||||||
if (isset($_GET['post_type'])) {
|
|
||||||
$type = $_GET['post_type'];
|
|
||||||
}
|
|
||||||
if (($type === 'questions') && is_admin() && $pagenow == 'edit.php' && isset($_GET['thematiques']) && $_GET['thematiques'] != '') {
|
|
||||||
$query->query_vars['meta_key'] = 'thematiques_taxo'; // change to meta key created by acf.
|
|
||||||
$query->query_vars['meta_value'] = $_GET['thematiques'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add_filter('parse_query', 'filter_post_by_thematiques_query');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,7 @@ if (class_exists('GF_Field')) {
|
||||||
'meta_key' => 'brochure_pdf',
|
'meta_key' => 'brochure_pdf',
|
||||||
'meta_value' => false,
|
'meta_value' => false,
|
||||||
'meta_compare' => '!=',
|
'meta_compare' => '!=',
|
||||||
'post__not_in' => [4431, 4436]
|
'post__not_in' => [4431, 4436, 11404, 11411, 1582, 4294, 3353, 4297]
|
||||||
|
|
||||||
));
|
));
|
||||||
$choices = [];
|
$choices = [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,46 @@ function build_page_chapter_index($blocks)
|
||||||
return $chapterBlockIndex;
|
return $chapterBlockIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------
|
||||||
|
GET ALL THEMATIQUES ORGANIZED BY PARENTS
|
||||||
|
---------------------------------------------*/
|
||||||
|
function getAllThematiquesTermsByParents()
|
||||||
|
{
|
||||||
|
// Récupérer tous les termes de la taxonomie 'thematiques' avec une hiérarchie
|
||||||
|
$ThematiquesTerms = get_terms([
|
||||||
|
'taxonomy' => 'thematiques',
|
||||||
|
'orderby' => 'name',
|
||||||
|
'order' => 'ASC',
|
||||||
|
'hide_empty' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$terms_by_parent = [];
|
||||||
|
$child_terms = [];
|
||||||
|
|
||||||
|
if ($ThematiquesTerms) {
|
||||||
|
|
||||||
|
// Boucle pour organiser les termes en fonction de leurs parents
|
||||||
|
foreach ($ThematiquesTerms as $term) {
|
||||||
|
if ($term->parent == 0) {
|
||||||
|
// Si c'est un parent, on le place dans le tableau des parents
|
||||||
|
$terms_by_parent[$term->term_id] = ['term' => $term, 'children' => []];
|
||||||
|
} else {
|
||||||
|
$child_terms[$term->parent][] = $term;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Réunir les termes parents et leurs enfants
|
||||||
|
foreach ($terms_by_parent as $parent_id => &$parent_data) {
|
||||||
|
// Ajouter les enfants au parent
|
||||||
|
if (isset($child_terms[$parent_id])) {
|
||||||
|
$parent_data['children'] = $child_terms[$parent_id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $terms_by_parent;
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------
|
/* -------------------------------------------
|
||||||
GET PARCOURS PREVIOUS/NEXT POSTS
|
GET PARCOURS PREVIOUS/NEXT POSTS
|
||||||
---------------------------------------------*/
|
---------------------------------------------*/
|
||||||
|
|
|
||||||
|
|
@ -244,3 +244,13 @@ ol {
|
||||||
display: inline-block !important;
|
display: inline-block !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
body.post-type-conseils,
|
||||||
|
body.post-type-fiches-infos,
|
||||||
|
body.post-type-questions,
|
||||||
|
body.post-type-brochures {
|
||||||
|
.tablenav {
|
||||||
|
#rank-math-seo-filter {
|
||||||
|
@apply !hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user