diff --git a/includes/artisans.php b/includes/artisans.php index 5b71217..be60582 100644 --- a/includes/artisans.php +++ b/includes/artisans.php @@ -384,3 +384,32 @@ add_action('admin_enqueue_scripts', function () { }); "); }); + + + + +add_action('save_post', 'update_artisan_nl_status_on_post_save'); + +function update_artisan_nl_status_on_post_save($post_id) +{ + if (get_post_type($post_id) !== 'artisans') return; + + // Éviter les sauvegardes en boucle + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; + if (defined('DOING_AJAX') && DOING_AJAX) return; + if (wp_is_post_revision($post_id)) return; + + // Récupérer la langue du post actuel + $current_language = apply_filters('wpml_post_language_details', null, $post_id); + // Si c'est un post français, synchroniser avec le post néerlandais + if (isset($current_language['language_code']) && $current_language['language_code'] === 'fr') { + + // Récupérer l'ID du post correspondant en néerlandais + $nl_post_id = apply_filters('wpml_object_id', $post_id, 'artisans', TRUE, 'nl'); + + wp_update_post(array( + 'ID' => $nl_post_id, + 'post_status' => get_post_status($post_id) + )); + } +}