From 9e6b7820058f64b774bdd77b5e4b4fdf6fefc579 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Mon, 25 Nov 2024 15:38:32 +0100 Subject: [PATCH] refining statuses colors and layout --- includes/admin.php | 91 +++++++++++++++++++---- resources/css/admin-style.css | 132 ++++++++++++++++++++++++++++------ 2 files changed, 189 insertions(+), 34 deletions(-) diff --git a/includes/admin.php b/includes/admin.php index c168e49..348305a 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -35,10 +35,10 @@ add_action('admin_init', 'metiers_remove_meta_boxes'); CUSTOM POST STATUS ---------------------------*/ -function metiers_patrimoine_custom_post_status() +function custom_post_status() { register_post_status('offline', array( - 'label' => _x('Offline', 'post'), + 'label' => _x('offline', 'post'), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, @@ -46,31 +46,94 @@ function metiers_patrimoine_custom_post_status() 'label_count' => _n_noop('Unread (%s)', 'Unread (%s)'), )); } -add_action('init', 'metiers_patrimoine_custom_post_status'); +add_action('init', 'custom_post_status'); -function metiers_patrimoine_add_to_post_status_dropdown() + +function add_to_post_status_dropdown() { global $post; - // if ($post->post_type != 'pdf_order') - // return false; - $status = ($post->post_statu == 'offline') ? "jQuery( '#post-status-display' ).text( 'Offline' ); jQuery( -'select[name=\"post_status\"]' ).val('completed');" : ''; + + // Ajoute une option 'offline' au menu déroulant des statuts echo ""; } -add_action('post_submitbox_misc_actions', 'metiers_patrimoine_add_to_post_status_dropdown'); - +add_action('post_submitbox_misc_actions', 'add_to_post_status_dropdown'); add_action('edit_form_after_title', function () { // Vérifie si on est sur le bon post type $screen = get_current_screen(); - if ($screen && $screen->post_type === 'artisans') { // Remplacez 'votre_cpt' par le slug de votre CPT + if ($screen && $screen->post_type === 'artisans') { echo '

' . get_the_title() . '

'; } }); + + +// Ajouter un filtre pour afficher les posts avec le statut 'offline' +add_filter('views_edit-artisans', function ($views) { + global $wpdb; + + $post_type = 'artisans'; + $status = 'offline'; + + // Compte le nombre de posts avec le statut 'offline' + $count = $wpdb->get_var($wpdb->prepare( + "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s", + $post_type, + $status + )); + + if ($count > 0) { + $class = (isset($_GET['post_status']) && $_GET['post_status'] === $status) ? 'current' : ''; + $views[$status] = sprintf( + '%s (%d)', + $post_type, + $status, + $class, + __('Offline', 'text-domain'), + $count + ); + } + + return $views; +}); + + + + +// Ajouter un statut personnalisé dans la colonne des statuts, uniquement dans la vue "Tous" +function add_custom_post_status($post_states, $post) +{ + // Vérifier si on est dans l'admin et si le post appartient au CPT 'artisans' + if ('artisans' === $post->post_type) { + global $pagenow; + + // Vérifier si on est sur la page d'index des articles (Tous les articles) + if ('edit.php' === $pagenow && !isset($_GET['post_status'])) { + + // Ajouter le statut "Publié" si l'article est publié + if ('publish' === $post->post_status) { + $post_states[] = __('Publié', 'text-domain'); // Affiche "Publié" + } + + // Ajouter votre statut personnalisé (ex : "offline") si c'est le cas + if ('offline' === get_post_status($post->ID)) { + $post_states[] = __('Offline', 'text-domain'); // Affiche "En attente" + } + } + } + + return $post_states; +} +add_filter('display_post_states', 'add_custom_post_status', 10, 2); diff --git a/resources/css/admin-style.css b/resources/css/admin-style.css index 935ebc4..baaf5fd 100644 --- a/resources/css/admin-style.css +++ b/resources/css/admin-style.css @@ -5,32 +5,34 @@ body.post-type-artisans { } } -.iedit.type-artisans.status-pending.hentry { - /* @apply bg-rose-50; */ - - .column-title { +.iedit.type-artisans.hentry { + .column-title:has(strong > a) { color: transparent; - a { - /* @apply text-red-900; */ - } + .post-state { - /* @apply text-white bg-rose-700 px-3 py-1 rounded-2xl font-medium text-sm; */ - @apply text-rose-700 px-3 py-1 rounded-2xl font-medium text-sm border-2 border-rose-700 border-solid; + @apply px-3 py-1 rounded-2xl font-medium text-xs border border-solid; } } } -.iedit.type-artisans.status-draft.hentry { - /* @apply bg-rose-50; */ - .column-title { - color: transparent; - a { - /* @apply text-red-900; */ - } - .post-state { - /* @apply text-white bg-rose-700 px-3 py-1 rounded-2xl font-medium text-sm; */ - @apply text-sky-700 px-3 py-1 rounded-2xl font-medium text-sm border-2 border-sky-700 border-solid; - } +.iedit.type-artisans.status-pending.hentry { + .column-title .post-state { + @apply text-amber-700 border-amber-700; + } +} +.iedit.type-artisans.status-draft.hentry { + .column-title .post-state { + @apply text-sky-700 border-sky-700; + } +} +.iedit.type-artisans.status-offline.hentry { + .column-title .post-state { + @apply text-neutral-700 border-neutral-700; + } +} +.iedit.type-artisans.status-publish.hentry { + .column-title .post-state { + @apply text-green-700 border-green-700; } } #acf-group_672358433051b, @@ -42,6 +44,96 @@ body.post-type-artisans { } } +.subsubsub { + .all, + .publish, + .pending, + .trash, + .offline { + @apply text-transparent border-solid border rounded-full pl-2; + } + + .all { + @apply border-violet-700; + transition: all 0.6s; + a, + span { + @apply !text-violet-700; + } + &:hover, + &:has(a[aria-current='page']) { + @apply bg-violet-700; + a, + span { + @apply !text-white; + } + } + } + .offline { + @apply border-neutral-700; + transition: all 0.6s; + a, + span { + @apply !text-neutral-700; + } + &:hover, + &:has(a[aria-current='page']) { + @apply bg-neutral-700; + a, + span { + @apply !text-white; + } + } + } + .pending { + @apply border-amber-700; + transition: all 0.6s; + a, + span { + @apply !text-amber-700; + } + &:hover, + &:has(a[aria-current='page']) { + @apply bg-amber-700; + a, + span { + @apply !text-white; + } + } + } + .trash { + @apply border-rose-700; + transition: all 0.6s; + a, + span { + @apply !text-rose-700; + } + &:hover, + &:has(a[aria-current='page']) { + @apply bg-rose-700; + a, + span { + @apply !text-white; + } + } + } + .publish { + @apply border-green-700; + transition: all 0.6s; + a, + span { + @apply !text-green-700; + } + &:hover, + &:has(a[aria-current='page']) { + @apply bg-green-700; + a, + span { + @apply !text-white; + } + } + } +} .admin-artisan-title { @apply text-patrimoine-sante-securite !font-semibold !text-2xl; }