Support Log in

21. Translation Hooks

Developer Guide
Prefer video? Watch the Lang Forge tutorials 9 short guides covering every feature Watch

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.

php
/**
 * @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.

Example 1: Copy custom meta to the new translation
php
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);
Example 2: Send email notification when translation is created
php
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);
Example 3: Automatically set post status based on language
php
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);

Forge AI Assistant Online

Hi! I'm the Lang Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs