Skip Navigation

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

Problem:
You are experiencing a significant slowdown when saving content in French on your WordPress site using WPML with French as the secondary language and ACFML for managing custom fields translations. The issue disappears when the ACF Multilingual plugin is deactivated.

Solution:
We recommend modifying specific methods in the WPML plugin files to potentially resolve the performance issue. Here are the steps:

1. Navigate to

\wp-content\plugins\sitepress-multilingual-cms\sitepress.class.php

and modify the

copy_custom_fields

method as follows:

function copy_custom_fields( $post_id_from, $post_id_to ) {<br />    $custom_fields_to_copy = $this->get_custom_fields_translation_settings( WPML_COPY_CUSTOM_FIELD );<br />    $custom_fields_from    = get_post_meta( $post_id_from );<br />    $custom_fields_to      = get_post_meta( $post_id_to );<br /><br />    foreach ( $custom_fields_to_copy as $meta_key ) {<br />        if ( array_key_exists( $meta_key, $custom_fields_from ) ) {<br />            $meta_from = isset( $custom_fields_from[ $meta_key ] ) ? $custom_fields_from[ $meta_key ] : [];<br />            $meta_to   = isset( $custom_fields_to[ $meta_key ] ) ? $custom_fields_to[ $meta_key ] : [];<br /><br />            if ( $meta_from || $meta_to ) {<br />                $this->sync_custom_field( $post_id_from, $post_id_to, $meta_key );<br />            }<br />        }<br />    }<br /><br />    $sync_deleted_fields = false;<br />    if ( apply_filters( 'wpml_sync_deleted_custom_fields', $sync_deleted_fields ) && $custom_fields_from && $custom_fields_to ) {<br />        $if_deleted_in_source_and_still_in_target = Logic::allPass([<br />            Obj::prop( Fns::__, $custom_fields_to ),<br />            pipe( Obj::prop( Fns::__, $custom_fields_from ), Logic::not() ),<br />        ]);<br /><br />        wpml_collect( $this->get_custom_fields_translation_settings( WPML_TRANSLATE_CUSTOM_FIELD ) )<br />            ->filter( $if_deleted_in_source_and_still_in_target )<br />            ->map(function ( $meta_key ) use ( $post_id_from, $post_id_to ) {<br />                $this->sync_custom_field( $post_id_from, $post_id_to, $meta_key );<br />            });<br />    }<br />}

2. Navigate to

\wp-content\plugins\sitepress-multilingual-cms\classes\custom-field-translation\class-wpml-copy-once-custom-field.php

and modify the

copy

method as follows:

public function copy( $post_id ) {<br />    $custom_fields_to_copy = $this->sitepress->get_custom_fields_translation_settings( WPML_COPY_ONCE_CUSTOM_FIELD );<br />    if ( empty( $custom_fields_to_copy ) ) {<br />        return;<br />    }<br /><br />    $source_element_id = $this->wpml_post_translation->get_original_element( $post_id );<br />    $custom_fields     = get_post_meta( $post_id );<br /><br />    foreach ( $custom_fields_to_copy as $meta_key ) {<br />        if ( array_key_exists( $meta_key, $custom_fields ) ) {<br />            $values = isset( $custom_fields[ $meta_key ] )<br />                      && ! empty( $custom_fields[ $meta_key ] )<br />                ? [ $custom_fields[ $meta_key ] ]<br />                : [];<br /><br />            $values = apply_filters(<br />                'wpml_custom_field_values',<br />                $values,<br />                [<br />                    'post_id'                   => $post_id,<br />                    'meta_key'                  => $meta_key,<br />                    'custom_fields_translation' => WPML_COPY_ONCE_CUSTOM_FIELD,<br />                ]<br />            );<br /><br />            if ( empty( $values ) && $source_element_id ) {<br />                $this->sitepress->sync_custom_field( $source_element_id, $post_id, $meta_key );<br />            }<br />        }<br />    }<br />}

If this solution does not resolve your issue or seems irrelevant due to updates or different circumstances, please check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. If the problem persists, we highly recommend opening a new support ticket at WPML support forum.

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.

No supporters are available to work today on this forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Dražen Duvnjak 1 month, 3 weeks ago.

Assisted by: Dražen Duvnjak.

Author Posts
September 12, 2024 at 8:15 pm #16173405

yannP

Background of the issue:
I am experiencing a significant slowdown when saving content in French on my WordPress site, which uses WPML with French as the secondary language and ACFML for managing custom fields translations. When I deactivate the ACF Multilingual plugin, the issue disappears, and saving content becomes fast again. All plugins, including ACF, ACFML, and WPML, are up to date. My server resources (CPU, RAM, etc.) are sufficient, and no other performance issues are present. The slowdown only occurs when saving content in French. The performance is normal when saving content in the primary language (English). I have already tried disabling other plugins and switching to a default WordPress theme, but the issue persists when ACFML is active.

Symptoms:
Significant slowdown when saving content in French with ACFML active.

You can see here a small video to check the loading time in the backend hidden link

Questions:
How can I resolve the performance issue when saving French content with ACFML and WPML?
Are there any optimizations for using ACFML in combination with WPML?

September 12, 2024 at 8:45 pm #16173525

yannP

We are trying this thread : https://wpml.org/forums/topic/syncing-custom-fields-performance-issues/

What will happen on the next update if it's working ?

September 13, 2024 at 3:38 pm #16176680

yannP

Hello, could you please help us ?

September 16, 2024 at 6:02 am #16181308

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

If the mentioned workaround from Bruno helps, then you can use this workaround until a permanent fix is released. When fix is included in our full versions it should work fine, until then you can use this as a workaround and add to the plugin if it is being overwritten on update.

Regards,
Drazen

September 17, 2024 at 2:49 pm #16189458

yannP

Hello Drazen,

The fix is not working, that's why we are asking for your help. Could we send you access to the website ?

September 18, 2024 at 6:28 am #16191130

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

1) in the last topic you said the shared workaround helps, what has changed in the meantime?

2) Since you also had other performance issue, please try again next errata: https://wpml.org/errata/wpml-causing-backend-slowness-and-duplicated-queries/

let me know how it goes.

Regards,
Drazen

September 24, 2024 at 2:55 pm #16215721

yannP

Hello,

Nothing is working unfortunately.

Could we send you access to our backend to have your help ?

It's been a long time that we have that issue 🙁

Thank you

September 25, 2024 at 5:59 am #16218125

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

Please try next, also while using only WPML and ACF; all others are disabled and using the WP default theme.

in \SitePress::copy_custom_fields in \wp-content\plugins\sitepress-multilingual-cms\sitepress.class.php
change the method to:

	function copy_custom_fields( $post_id_from, $post_id_to ) {
		$custom_fields_to_copy = $this->get_custom_fields_translation_settings( WPML_COPY_CUSTOM_FIELD );
		$custom_fields_from    = get_post_meta( $post_id_from );
		$custom_fields_to      = get_post_meta( $post_id_to );

		foreach ( $custom_fields_to_copy as $meta_key ) {
			if ( array_key_exists( $meta_key, $custom_fields_from ) ) {
				$meta_from = isset( $custom_fields_from[ $meta_key ] ) ? $custom_fields_from[ $meta_key ] : [];
				$meta_to   = isset( $custom_fields_to[ $meta_key ] ) ? $custom_fields_to[ $meta_key ] : [];

				if ( $meta_from || $meta_to ) {
					$this->sync_custom_field( $post_id_from, $post_id_to, $meta_key );
				}
			}
		}

		$sync_deleted_fields = false;
		/**
		 * This filter hook determines whether we should sync deleted custom
		 * fields to translations.
		 *
		 * @since 4.4.9
		 *
		 * @param bool $sync_deleted_fields True if we should sync deleted custom fields (the default is false).
		 *
		 * @return bool
		 */
		if ( apply_filters( 'wpml_sync_deleted_custom_fields', $sync_deleted_fields ) && $custom_fields_from && $custom_fields_to ) {
			$if_deleted_in_source_and_still_in_target = Logic::allPass(
				[
					Obj::prop( Fns::__, $custom_fields_to ),
					pipe( Obj::prop( Fns::__, $custom_fields_from ), Logic::not() ),
				]
			);

			wpml_collect( $this->get_custom_fields_translation_settings( WPML_TRANSLATE_CUSTOM_FIELD ) )
				->filter( $if_deleted_in_source_and_still_in_target )
				->map(
					function ( $meta_key ) use ( $post_id_from, $post_id_to ) {
						$this->sync_custom_field( $post_id_from, $post_id_to, $meta_key );
					}
				);
		}

	}

in \WPML_Copy_Once_Custom_Field::copy in \wp-content\plugins\sitepress-multilingual-cms\classes\custom-field-translation\class-wpml-copy-once-custom-field.php
change the method to:

	public function copy( $post_id ) {
		$custom_fields_to_copy = $this->sitepress->get_custom_fields_translation_settings( WPML_COPY_ONCE_CUSTOM_FIELD );
		if ( empty( $custom_fields_to_copy ) ) {
			return;
		}

		$source_element_id = $this->wpml_post_translation->get_original_element( $post_id );
		$custom_fields     = get_post_meta( $post_id );

		foreach ( $custom_fields_to_copy as $meta_key ) {
			if ( array_key_exists( $meta_key, $custom_fields ) ) {
				$values = isset( $custom_fields[ $meta_key ] )
				          && ! empty( $custom_fields[ $meta_key ] )
					? [ $custom_fields[ $meta_key ] ]
					: [];

				/**
				 * Custom fields values for given post obtained directly from database
				 *
				 * @param array<mixed> $values Custom fields values as they are in the database
				 * @param array<int|string> $args {
				 *
				 * @type int $post_id ID of post associated with custom field
				 * @type string $meta_key custom fields meta key
				 * @type int $custom_fields_translation field translation option
				 *
				 * }
				 * @since 4.1
				 *
				 */
				$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 );
				}
			}
		}
	}