Action hooks fired during translation operations. These are essential for extending Lang Forge’s behavior.
lf_translation_created (action)
Fired when a new translation post is created and linked. This is the primary hook for extending translation behavior.
/**
* @param int $original_post_id Source post ID
* @param int $new_post_id Newly created translation post ID
* @param string $target_lang Target language code
*/This hook fires from multiple places: the admin metabox “Create Translation” button, the Visual Editor, WP-CLI translate command, and bulk actions. The Elementor, Divi, ACF, and WooCommerce integrations all hook into this action to copy their data.
add_action('lf_translation_created', function ($original_id, $new_id, $lang) {
// Copy SEO meta fields
$seo_fields = ['_yoast_wpseo_title', '_yoast_wpseo_metadesc', '_rank_math_title', '_rank_math_description'];
foreach ($seo_fields as $key) {
$value = get_post_meta($original_id, $key, true);
if ($value) {
update_post_meta($new_id, $key, $value);
}
}
// Copy a custom theme field
$custom_layout = get_post_meta($original_id, '_theme_page_layout', true);
if ($custom_layout) {
update_post_meta($new_id, '_theme_page_layout', $custom_layout);
}
}, 10, 3);add_action('lf_translation_created', function ($original_id, $new_id, $lang) {
$original = get_post($original_id);
$languages = lf_get_languages();
$lang_name = $languages[$lang]['name'] ?? $lang;
$translator_email = get_option('translation_team_email', get_option('admin_email'));
wp_mail(
$translator_email,
sprintf('New %s translation created: %s', $lang_name, $original->post_title),
sprintf(
"A new %s translation has been created for "%s".nn" .
"Edit the translation: %sn" .
"View the original: %sn",
$lang_name,
$original->post_title,
admin_url("post.php?post={$new_id}&action=edit"),
admin_url("post.php?post={$original_id}&action=edit")
)
);
}, 10, 3);add_action('lf_translation_created', function ($original_id, $new_id, $lang) {
$auto_publish_langs = ['en', 'de'];
if (in_array($lang, $auto_publish_langs)) {
wp_update_post([
'ID' => $new_id,
'post_status' => 'publish',
]);
}
}, 10, 3);—