Hello!
Will this work without causing any issues?
// --- WPML: Sync post status across all translations ---
// When a post/page/CPT in the default language changes status (publish, draft, trash, private, pending),
// all its translations are updated to match. Works for ALL post types with WPML translation enabled.
// Only syncs FROM the default language TO translations (not the reverse).
add_action('transition_post_status', function($new_status, $old_status, $post) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (wp_is_post_revision($post)) return;
static $syncing = false;
if ($syncing) return;
if ($new_status === $old_status) return;
if (!function_exists('apply_filters') || !has_filter('wpml_default_language')) return;
$default_lang = apply_filters('wpml_default_language', null);
$post_lang = apply_filters('wpml_post_language_details', null, $post->ID);
if (!$post_lang || $post_lang['language_code'] !== $default_lang) return;
$element_type = apply_filters('wpml_element_type', $post->post_type);
$trid = apply_filters('wpml_element_trid', null, $post->ID, $element_type);
if (!$trid) return;
$translations = apply_filters('wpml_get_element_translations', null, $trid, $element_type);
if (!$translations) return;
$syncing = true;
foreach ($translations as $lang => $translation) {
if ($lang === $default_lang) continue;
if (!isset($translation->element_id)) continue;
$trans_post = get_post($translation->element_id);
if (!$trans_post || $trans_post->post_status === $new_status) continue;
wp_update_post([
'ID' => $translation->element_id,
'post_status' => $new_status,
]);
}
$syncing = false;
}, 10, 3);