Skip Navigation

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 7 replies, has 2 voices.

Last updated by Stephen Merriman 1 year, 8 months ago.

Assisted by: Ahmed Mohammed.

Author Posts
May 1, 2023 at 12:48 am #13563611

Stephen Merriman

A long time ago the ACF developer provided support for using optgroups in select fields - not via the visible UI, but by using a filter to adjust the field's choices and provide a multidimensional array. See, for example:

hidden link

This has worked perfectly for the last 10 years and continues to work.

However, with WPML / ACFML active, a fatal error is thrown:

Uncaught TypeError: md5(): Argument #1 ($string) must be of type string, array given in .../wp-content/plugins/acfml/classes/Strings/Package.php:97

This is because it is not handling the case of the choices being a multidimensional array.

Can the plugin be changed to handle this use-case?

May 2, 2023 at 11:11 am #13569955

Ahmed Mohammed
Supporter

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

Hi there,

Thank you for contacting WPML support!

I understand you're receiving a fatal error from the ACFML plugin because of not handle the case of the choices being a multidimensional array.

We have received a similar report before, and it was caused by a conflict with a plugin "ACF-SVG-ICON," which does not exist on your website according to the debug information.

I would like to pass this on to our developers to check what is happening. I have created this sandbox website: hidden link - could you please reproduce the issue there after logging in with that quick login URL?

If you want to add code, you can use the Theme File Editor: hidden link

Looking forward to hearing back from you.

May 2, 2023 at 10:31 pm #13574311

Stephen Merriman

I ran the same code on your staging site and couldn't replicate the error. However, after I debugging, I discovered that this was because your staging server uses PHP 7.4, and the issue only occurs on PHP 8.0.

Are you able to update the staging server to PHP 8? (NB - in testing a few things in the theme editor, I accidentally resulted in a PHP error, so I can't access the staging site anymore 🙁 )

May 3, 2023 at 9:09 am #13576623

Ahmed Mohammed
Supporter

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

Hi there,

Are you able to update the staging server to PHP 8?

Unfortunately, it's not possible to update the sandbox environment to PHP 8.

Do you have a staging/testing area for your website?

If not, please create one where the issue is reproduced and I can clone it and pass it on to your devs.

I have enabled the private reply for you so that you can share the login details.

Looking forward to hearing back from you.

May 3, 2023 at 9:55 pm #13582177

Stephen Merriman

PS - I think in PHP 7 it just fails silently with a warning rather than a fatal error, so you can probably still trace the code there.

May 4, 2023 at 3:22 pm #13588017

Ahmed Mohammed
Supporter

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

Hi there,

Thank you for providing the staging area. I was able to replicate the issue, and I'm going to pass it on to our developers.

In the meantime, I was able to find a workaround that would work if you don't want to use String Translation to translate the group and field labels. You can go to /wp-content/plugins/acfml/classes/class-wpml-acf.php and comment this line:

\ACFML\Strings\HooksFactory::class             => true,

or replace it with

\ACFML\Strings\HooksFactory::class             => false,

I will keep you posted when I hear back from our developers.

Regards,

May 18, 2023 at 7:50 am #13669563

Ahmed Mohammed
Supporter

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

Hi there,

Our developers created the following workaround:

Edit classes/Strings/Traversable/Field.php and replace

protected function transform( Transformer $transformer, $value, $config ) {
		if ( is_array( $value ) ) {
			foreach ( $value as $key => $label ) {
				$value[ $key ] = $transformer->transform( $label, $config );
			}
		} else {
			$value = $transformer->transform( $value, $config );
		}

		return $value;
	}

with

protected function transform( Transformer $transformer, $value, $config ) {
		if ( is_array( $value ) ) {
			foreach ( $value as $key => $label ) {
        if ( is_string( $label ) ) {
    				$value[ $key ] = $transformer->transform( $label, $config );
        }
			}
		} else {
			$value = $transformer->transform( $value, $config );
		}

		return $value;
	}

And if you want to translate the strings, you need to update the code in the functions.php file to

add_filter('acf/load_field/key=field_6452d0242b965',function($field) {
	$field['choices'] = array(
		'group1'=>array('val1'=> __( 'Value 1', 'my_plugin' ), 'val2'=> __( 'Value 2', 'my_plugin' )),
		'group2'=>array('val3'=> __( 'Value 3', 'my_plugin' ), 'val4'=> __( 'Value 4', 'my_plugin' )),
	);
	return $field;
});

Could you please give that a try and let us know how it goes?

Looking forward to hearing back from you.

May 21, 2023 at 9:23 pm #13685509

Stephen Merriman

That should be enough of a workaround, thanks.