Action hooks fired during translation operations. These are essential for extending Lang Forge’s behavior.
langforge_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 in these places: the “+ Create” button of the Language metabox (and the same button in the block editor sidebar and in the Key pages table of Translation Status), the create links such as +DE in the Language column of the post lists, the WP-CLI command wp langforge translate, the Visual Editor of Lang Forge Pro when its save has to create the translation post, and the One-Click Site Duplication card of Lang Forge Pro on Lang Forge > Tools: the Duplicate Only button, and the Duplicate + AI Translate button (in Fast mode once for each post after its text is translated; in Background mode once for each draft when the draft is created, before the queue translates the text). It also fires when another plugin hands a post over with the langforge/translate_post action: Lang Forge then creates a draft for each language that has no translation yet. Among the listeners are the Elementor, Divi, and WooCommerce integrations, which copy their data.
add_action('langforge_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('langforge_translation_created', function ($original_id, $new_id, $lang) {
$original = get_post($original_id);
$languages = langforge_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('langforge_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);—