Skip Navigation

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

Problem:

We are using WPML and ACF + the glue plugin ACFML. We initially set an image field's translation configuration to be "copy". Now we would like to be able to change the image in the translated languages, so we set it to CopyOnce. Yet the post-edit interface in the translation language post-edit screen is still locked for that image field.

Solution:

1- Deactivate all plugins except these (https://prnt.sc/B8JbDb-AdM8t)
2- Select "Different fields across languages" translation mode in the following field groups

  • Atom : Teaser Item
  • Page Builder
  • 3- Edit the (wp-content/plugins/sitepress-multilingual-cms/classes/custom-field-translation/class-wpml-copy-once-custom-field.php) file
    4- Replace the following code at line 66

    if ( empty( $values ) && $source_element_id ) {
        $this->sitepress->sync_custom_field( $source_element_id, $post_id, $meta_key );
    }
    

    With the following

    if ( ! get_post_meta( $post_id, 'copyoncedone' ) == 1 ) {
                add_post_meta($post_id, 'copyoncedone', 1 );
                foreach ( $custom_fields_to_copy as $meta_key ) {
                    $values = isset( $custom_fields[ $meta_key ] ) ? $custom_fields[ $meta_key ] : [];
                    if ( ! empty( $values ) ) {
                        $values = array( $values );
                    }
                    $values = apply_filters(
                        'wpml_custom_field_values',
                        $values,
                        [
                            'post_id'                   => $post_id,
                            'meta_key'                  => $meta_key,
                            'custom_fields_translation' => WPML_COPY_ONCE_CUSTOM_FIELD,
                        ]
                    );
     
                    if ( empty ( $values ) && $source_element_id ) {
                        $this->sitepress->sync_custom_field( $source_element_id, $post_id, $meta_key );
                    }
                }
    }
    

    5- Update the page in the default language

    Kindly check this video to see how it works on my local installation. (https://files.fm/u/wz4pg8jct)

    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 alexandreP-37 1 year, 8 months ago.

    Assisted by: Osama Mersal.

    Author Posts
    May 22, 2023 at 1:53 pm #13690699

    alexandreP-37

    Hello,

    We are using WPML and ACF + the glue plugin ACFML. We originally set an image field's translation configuration to be "copy". Now we would like to be able to change the image in the translated languages, so we set it to CopyOnce. Yet the post edit interface in the translation language post edit screen is still locked for that image field. What steps should be followed so that the change is taken into account?

    May 23, 2023 at 7:53 am #13695505

    Osama Mersal
    Supporter

    Languages: English (English ) Arabic (العربية )

    Timezone: Africa/Cairo (GMT+02:00)

    Hi,

    Thanks for contacting WPML forums support. I'll be glad to help you today.

    Please set the image field to translate and check if that would fix the issue. Also, please check our ACF guide. (https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/)

    Kindly let me know the result of the above test.

    Best regards,
    Osama

    May 23, 2023 at 8:02 am #13695587

    alexandreP-37

    Hello Osama,

    OK, I just did it. I then updated the English post to trigger a change, but the french post still does not allow me to edit the image field.
    Should i do something else to make sure the field change is applied ?

    May 23, 2023 at 8:07 am #13695611

    Osama Mersal
    Supporter

    Languages: English (English ) Arabic (العربية )

    Timezone: Africa/Cairo (GMT+02:00)

    Hi,

    Thanks for your update. Please let me know which field group contains this image field. Also, I would need to look closely at your site, so I would need to request temporary access (WP-Admin and FTP)
    – preferably to a test site where the problem has been replicated if possible –
    in order to be of better help and check if some configurations might need to be changed.

    Your next answer will be private, which means only you and I can access it.

    ❌ Please backup your database and website ❌

    ✙ I would need your permission to de-activate and re-activate the Plugins and the Theme and change configurations on the site. This is also a reason the backup is critical.

    ✙ I also need your permission to take a local copy of your site to debug the issue without affecting your live site.

    Best regards,
    Osama

    May 23, 2023 at 11:09 am #13697867

    Osama Mersal
    Supporter

    Languages: English (English ) Arabic (العربية )

    Timezone: Africa/Cairo (GMT+02:00)

    Hi,

    Thanks for the access details. Could you please install the Duplicator or All In One Migration plugins on your site, so I can take a local copy?

    I'll debug the issue further locally and escalate it to our 2nd tier support team if needed.

    Thanks for your cooperation

    Best regards,
    Osama

    May 23, 2023 at 11:40 am #13698313

    alexandreP-37

    Thanks for looking into it. You can do so using the already installed WP Migrate Pro hidden link

    choose "export" then set the parameters you want for your local copy.

    wpmigrate.png
    May 23, 2023 at 11:51 am #13698549

    Osama Mersal
    Supporter

    Languages: English (English ) Arabic (العربية )

    Timezone: Africa/Cairo (GMT+02:00)

    Hi,

    Thanks for your suggestion. I tried the WP Migrate plugin, but I faced an error. (An unknown error occurred. Please check your PHP error log or contact support.)

    Is it possible to install one of the plugins mentioned in my previous reply?

    Thanks,
    Osama

    May 23, 2023 at 12:54 pm #13699519

    alexandreP-37

    ah, sorry about the issue.
    I added Duplicator: hidden link

    May 23, 2023 at 1:43 pm #13700025

    Osama Mersal
    Supporter

    Languages: English (English ) Arabic (العربية )

    Timezone: Africa/Cairo (GMT+02:00)

    Hi,

    Thanks for your cooperation. Your site is bigger than what Duplicator Lite can handle, so I need to use the Duplicator Pro plugin. Would you please grant me access to install plugins to install the Duplicator Pro? The current provided account can't install plugins.

    Thanks,
    Osama

    May 23, 2023 at 2:51 pm #13700627

    alexandreP-37

    Done!

    May 24, 2023 at 5:51 am #13704101

    Osama Mersal
    Supporter

    Languages: English (English ) Arabic (العربية )

    Timezone: Africa/Cairo (GMT+02:00)

    Hi,

    Thanks for your cooperation. I tried Duplicator Pro and All in one migration plugins, but both didn't work because of server restrictions, so please provide a copy of your site's files and database.

    Kindly upload the package to one of the file transfer services like WeTransfer or Google Drive. I'll enable the private tab, so you can share the package link safely.

    Thanks,
    Osama

    May 24, 2023 at 11:06 am #13706391

    Osama Mersal
    Supporter

    Languages: English (English ) Arabic (العربية )

    Timezone: Africa/Cairo (GMT+02:00)

    Hi,

    Thanks for the package. I installed a local copy of your site and was able to fix the issue by the following steps:

    1- Deactivate all plugins except these (hidden link)
    2- Select "Different fields across languages" translation mode in the following field groups

  • Atom : Teaser Item
  • Page Builder
  • 3- Edit the (wp-content/plugins/sitepress-multilingual-cms/classes/custom-field-translation/class-wpml-copy-once-custom-field.php) file
    4- Replace the following code at line 66

    if ( empty( $values ) && $source_element_id ) {
        $this->sitepress->sync_custom_field( $source_element_id, $post_id, $meta_key );
    }
    

    With the following

    if ( ! get_post_meta( $post_id, 'copyoncedone' ) == 1 ) {
                add_post_meta($post_id, 'copyoncedone', 1 );
                foreach ( $custom_fields_to_copy as $meta_key ) {
                    $values = isset( $custom_fields[ $meta_key ] ) ? $custom_fields[ $meta_key ] : [];
                    if ( ! empty( $values ) ) {
                        $values = array( $values );
                    }
                    $values = apply_filters(
                        'wpml_custom_field_values',
                        $values,
                        [
                            'post_id'                   => $post_id,
                            'meta_key'                  => $meta_key,
                            'custom_fields_translation' => WPML_COPY_ONCE_CUSTOM_FIELD,
                        ]
                    );
     
                    if ( empty ( $values ) && $source_element_id ) {
                        $this->sitepress->sync_custom_field( $source_element_id, $post_id, $meta_key );
                    }
                }
    }
    

    5- Update the page in the default language

    Kindly check this video to see how it works on my local installation. (hidden link)

    I've applied the above steps to your staging site, except for the first step. Would you please deactivate the plugins and activate the WordPress default theme (Twenty Twenty-One)? After that, please update the page in the default language and check the issue.

    Best regards,
    Osama

    May 24, 2023 at 11:17 am #13706461

    alexandreP-37

    Thank you very much for this super helpful answer, Osama.
    Question: if i modify this file, it will be erased at the next WPML plugin update. Do you plan to port this change to the core plugin ?

    May 24, 2023 at 11:20 am #13706493

    Osama Mersal
    Supporter

    Languages: English (English ) Arabic (العربية )

    Timezone: Africa/Cairo (GMT+02:00)

    Hi,

    I'm not sure if this snippet will be added in the next release or not, but our dev team is working on this.

    Best regards,
    Osama

    May 24, 2023 at 11:30 am #13706525

    alexandreP-37

    My issue is resolved now. Thank you Osama!