From 1773c5787113d4aec18ab9c44d5aaceb473d0ea4 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Mon, 7 Apr 2025 12:16:51 +0200 Subject: [PATCH] FEAT Developping a custom save post button on top of the page --- includes/artisans.php | 50 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/includes/artisans.php b/includes/artisans.php index 0f3f5a6..6c995bb 100644 --- a/includes/artisans.php +++ b/includes/artisans.php @@ -25,6 +25,38 @@ function metiers_patrimoine_artisans_post_updater($post_id) } add_action('acf/save_post', 'metiers_patrimoine_artisans_post_updater', 20); +/* ----------------------------------------------- +AUTOMATIZE POST STATUS DEPENDING ON MDP STATUS +--------------------------------------------------*/ +function update_post_status_based_on_mdp_status($post_id) +{ + if (get_post_type($post_id) !== 'artisans') return; + + $mdp_status = get_field('mdp_status', $post_id); + $post_update = array( + 'ID' => $post_id + ); + // Définir le statut en fonction de la valeur du statut de travail mdp_status + if ($mdp_status && isset($mdp_status['value'])) { + switch ($mdp_status['value']) { + case 'ok': + case 'to_actualize': + $post_update['post_status'] = 'publish'; + break; + case 'to_contact': + case 'deleted': + case 'rejected': + case 'none': + $post_update['post_status'] = 'offline'; + break; + default: + return; + } + + wp_update_post($post_update); + } +} +add_action('acf/save_post', 'update_post_status_based_on_mdp_status', 20); /* --------------------------------------- CUSTOM CONTENT AFTER POST TYPE TITLE @@ -55,8 +87,9 @@ add_action('edit_form_after_title', function () { - - + +