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.

This topic contains 11 replies, has 5 voices.

Last updated by Carlos Rojas 9 months ago.

Assigned support staff: Carlos Rojas.

Author Posts
October 28, 2017 at 5:35 pm #1414806

Oliver

As stated in

https://wpml.org/documentation/translating-your-contents/displaying-untranslated-content-using-content-duplication/

when copying the contents from the original post via the "Copy content from ..." button, custom fields are not being included, unlike when the page is being duplicated, or when using the "Overwrite with ... content" button.

This is a little inconvenient, because the copy content feature is the least intrusive, as it doesn't overwrite the permalink. I've noticed the undocumented wpml_copy_from_original_custom_fields filter in /inc/wpml-post-edit-ajax.class.php, which could be leveraged to add custom fields, but unfortunately the post object is not being passed to it, which makes rertrieving (advanced) custom fields content impossible.

I'd like to suggest to either add native support for (advanced) custom fields, and/or to pass the post object to the filter:

$fields_contents['customfields'] =
	apply_filters(
		'wpml_copy_from_original_custom_fields',
		self::copy_from_original_custom_fields($post),
		$post
	);

that way developers could easily add simple (advanced) custom fields, like:

add_filter(
    'wpml_copy_from_original_custom_fields',
    function (array $fields, \WP_Post $post) {
        $subtitle = get_field('subtitle', $post->ID);
        if ($subtitle) {
            $fields['acf-field-subtitle'] = [
                'editor_name' => 'acf-field-subtitle',
                'editor_type' => 'text',
                'value'       => $subtitle
            ];
        }

        return $fields;
    },
    10, 2
);

For more advanced fields a JavaScript callback that would be handled in icl_copy_from_original in /res/js/scripts.js might be useful, something along the lines of:

function icl_copy_from_original(lang, trid) {
	// ...
	
	for (var element in msg.customfields) {
		if (msg.customfields.hasOwnProperty(element) && msg.customfields[element].editor_type === 'editor') {
			// ...
		} else if (msg.customfields[element].editor_type === 'callback') {
			msg.customfields[element].callback(msg.customfields[element]);
		} else {
			// ...
		}
	}

	// ...
}
$fields['acf-field-subtitle'] = [
	'editor_name' => 'acf-field-subtitle',
	'editor_type' => 'callback',
	'callback'    => 'callback_function_name'
	'value'       => $subtitle
];

Then one could handle populating more complex advanced custom fields manually.

Regards,
Oliver

October 30, 2017 at 5:48 pm #1416047

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hello,

Thank you very much for contacting our support service and for suggest this changes. I have escalated this ticket to our development team and they will analyze it. We will get back to in case we need more information.

Kind regards,
Carlos

November 3, 2017 at 1:48 pm #1420167

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hello Oliver,

This is the answer from our development team:
"As the title of the button suggests, it is only meant to copy the content from original post. Copying custom fields in similar manner would be altogether new functionality also it will conflict with the Multilingual Content Setup settings of custom fields in Translation Management.

If client wants to copy custom fields, he can set those fields to "copy" in Multilingual Content Setup."

Regards,
Carlos

November 3, 2017 at 3:00 pm #1420276

Oliver

Hello Carlos,

thanks for the response.

I know that I can set the fields to be copied, but the fields are only being copied after the post/page is being saved, and it will then of course always override the fields on every save, ie possible translations are being lost unless choosing "copy once", but then the workflow still would be, "edit", "save", "edit egain", "save again", which isn't overly nice.

When done only for fields that are set to "translate", this shouldn't conflict with the multilingual content settings. I don't think it's a stretch to say that for such configurations people would expect the custom fields to be copied just like everything else, as they obviously want to translate them.

Surely this would be a change in behavior, which is something that should only be intruduced in a new major release (at least if WPML follows SemVer or similar), so even if this would be considered, I wouldn't expect any changes anytime soon. Giving the developers more control over this via hooks/filters however is something different, implementing this in a backwards compatible manner should be very possible, so I'd like to put a little more emphasis on this feature suggestion 🙂

Regards,
Oliver

November 6, 2017 at 1:06 pm #1421839

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hi Oliver,

One of our specialists will talk about this suggestion with the development team in their next meeting.

However, it's important to take in consideration that these fields are considered even by WordPress as something separate from the post and are updated separately.

I will get back to you as soon as I have an answer.

Thanks for your understading.
Regards,
Carlos

November 8, 2017 at 2:26 pm #1424649

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hi Oliver,

This ticket has been escalated to our development team. Our development team will work on this, unfortunately I can't give you an estimated time because they have their own priority list. However they will work on this.

Thank you very much for your suggestion.

Kind regards,
Carlos

September 26, 2018 at 10:37 pm #2768847

ludovicH-2

Hi, i wanted to know if you have made any progress on this issue ? Because i agree with @olivern-10 on this point, when users see a "Copy content" button, they expect to see all the data to be copied, including ACF fields. The problem with "duplicate" is that for a taxonomy for example, it will create a taxonomy especially for the translated language and tell it's been translated. ("angleterre" in french will become "angleterre-en" whereas it should be "england" and tell you it's been translated). "Copy content" with all the fields including ACF ones would allow to see quickly what is to be translated and serve as a good start to begin the translation work.
Thanks

November 7, 2018 at 2:18 pm #2885751

jeffH-13

I also agree with @olivern-10 and @ludovich-2. Just curious of there has been any additional progress on this issue.

January 9, 2019 at 9:52 pm #3073831

kevinL-36

It's been 2 years since we've been waiting for a response to this.

January 10, 2019 at 4:33 pm #3077091

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hi there,

This issue was solved over a year ago. If the issue persists on your side I kindly ask you to share a fresh new install with the issue happening so I can escalated to our developers.

Best regards,
Carlos

January 14, 2019 at 10:53 am #3086919

Oliver

How exactly has this been fixed? There's no explanation in this thread, and I'm seeing the exact same behavior as reported initially, the ACF content is not being copied when using the "Copy content from ..." button.

Regards,
Oliver

January 14, 2019 at 4:44 pm #3088871

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hi Oliver,

Wat I meant in my previous message is that this ticket was closed over a year ago. Our specialists determined that "As the title of the button suggests, it is only meant to copy the content from original post. Copying custom fields in similar manner would be altogether new functionality also it will conflict with the options in WPML -> Settings -> Custom fields section."

Thank you very much for your understanding.
Best regards,
Carlos