From d657b68a9d43dec9a16944312a92d22b7d2baf80 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Tue, 12 May 2026 16:08:56 +0200 Subject: [PATCH] FEATURE Disable editor for 'analyses-etudes' post type based on term condition --- mu-plugins/carhop-post-types.php | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mu-plugins/carhop-post-types.php b/mu-plugins/carhop-post-types.php index 6ad91b5..4f62873 100644 --- a/mu-plugins/carhop-post-types.php +++ b/mu-plugins/carhop-post-types.php @@ -329,3 +329,42 @@ add_action('admin_menu', function () { add_filter('menu_order', 'carhop_new_admin_menu_order'); add_filter('custom_menu_order', '__return_true'); }); + +/* ---------------------------------------------------------------------- + DESACTIVATE EDITOR FOR ANALYSES & ETUDES --> Analyse only + ------------------------------------------------------------------------*/ + +function carhop_analyses_etudes_maybe_remove_editor() +{ + if (get_current_blog_id() !== 1) { + return; + } + if (!post_type_exists('analyses-etudes')) { + return; + } + + $post_id = 0; + if (isset($_GET['post'])) { + $post_id = (int) $_GET['post']; + } + + if ($post_id > 0) { + $post = get_post($post_id); + if (!$post || $post->post_type !== 'analyses-etudes') { + return; + } + $is_analyse = has_term('analyse', 'type-analyse-etude', $post_id); + if ($is_analyse) { + remove_post_type_support('analyses-etudes', 'editor'); + } + return; + } + + if (isset($_GET['post_type']) && $_GET['post_type'] === 'analyses-etudes') { + remove_post_type_support('analyses-etudes', 'editor'); + } +} +add_action('load-post.php', 'carhop_analyses_etudes_maybe_remove_editor', 5); +add_action('load-post-new.php', 'carhop_analyses_etudes_maybe_remove_editor', 5); + +