Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
After installing WPML on a WordPress site using the Divi theme, the client is unable to use the translation management view to automatically translate content, as page created with Divi have a lot of content global_colors_info.

Solution:
We recommend the following workaround:
1. Backup the website or create a backup of the problematic page.
2. Add the following code to the

functions.php

file of your theme:

// WPML Workaround for compsupp-7144
function wpml_compsupp7144_clear_global_colors_info_attribute($post_id) {
    $post_content = get_post_field('post_content', $post_id);
    $pattern = '/(\[.*?global_colors_info=")([^\"]*)(\"[^\]]*\])/'
    $new_content = preg_replace_callback(
        $pattern,
        function ($matches) {
            return $matches[1] . '' . $matches[3];
        },
        $post_content
    );
    if ($new_content !== $post_content) {
        $updated_post = array(
            'ID'           => $post_id,
            'post_content' => $new_content,
        );
        wp_update_post($updated_post);
    }
}
wpml_compsupp7144_clear_global_colors_info_attribute(999999); // Replace 999999 with your post ID

3. Replace

999999

with the post ID of the page you're having issues with.
4. Visit the page on the front-end to execute the code.
5. Comment out the last line of the snippet after the code has run.
This will remove the content of all

global_colors_info

attributes from the page, allowing you to translate the page using the Classic Translation Editor (CTE) or Advanced Translation Editor (ATE).

If this solution doesn't seem relevant to your issue, please open a new support ticket with us.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 14 replies, has 2 voices.

Last updated by Dražen 1 year, 4 months ago.

Assisted by: Dražen.

Author Posts
January 19, 2024 at 7:04 am #15203050

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

great, thanks for letting us know.

I will update you if I have some news, but for now I think this needs to be solved/changed from Divi side so the pages do not contain that much unnecessary data.

Regards,
Drazen

January 22, 2024 at 7:40 am #15209591

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

we checked further, and we will contact Divi and suggest you do the same so they can fix generating big data in global colors.

In the meantime you can use next workaround for any future case:

Workaround

- Backup the website / create a backup of the page
- Add the following code to the functions.php file:

// WPML Workaround for compsupp-7144
function wpml_compsupp7144_clear_global_colors_info_attribute($post_id) {
    // Get the post content using the specified post ID
    $post_content = get_post_field('post_content', $post_id);

    // Define a regular expression pattern to match any shortcode with global_colors_info attribute
    $pattern = '/(\[.*?global_colors_info=")([^"]*)("[^\]]*\])/';

    // Use preg_replace_callback to modify the content
    $new_content = preg_replace_callback(
        $pattern,
        function ($matches) {
            return $matches[1] . '' . $matches[3];
        },
        $post_content
    );

    // Update the post content with the modified content
    if ($new_content !== $post_content) {
        $updated_post = array(
            'ID'           => $post_id,
            'post_content' => $new_content,
        );

        // Update the post
        wp_update_post($updated_post);
    }
}

// Usage: Call this function with the specific post ID to process
// Then visit any page on front-end to execute, then comment the line below
wpml_compsupp7144_clear_global_colors_info_attribute(999999); // Replace 999999 with your post ID

- Replace the 999999ID with the post ID of the page with the issue
- Visit the page on front-end, to execute the code
- Comment the last line of the snippet
- After that, it will remove the content of all global_colors_info attributes of the page, making possible to translate the page using CTE/ATE.

Regards,
Drazen