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

Last updated by Laura 10 months, 1 week ago.

Assisted by: Eran Helzer.

Author Posts
June 13, 2023 at 5:06 pm #13819593

Chauncey McAskill

Hello WPML,

I noticed the following PHP warning recently polluting my error logs:

```
Attempt to read property "post_content" on null in plugins/wpml-acfml/classes/class-wpml-acf-repeater-shuffle.php on line 249
```

The issue is the `isChildOfRepeaterField()` method makes two assumptions:

1. That `get_post()` will always return a post.
2. That the field's 'parent' is an 'acf-field' post ID.

An ACF field can be defined programmatically (local JSON/PHP) in such case the local ACF field's 'parent' will often be a field key. It's only ever a post ID if it's synced back into the database.

I've patched it like so in our project:

private function isChildOfRepeaterField( $key, $postId ) {
	$acfFieldObject = get_field_object( $key, $postId );
	if ( isset( $acfFieldObject['parent'] ) ) {
		if ( is_numeric( $acfFieldObject['parent'] ) && $acfFieldObject['parent'] > 0 ) {
			$fieldParent = get_post( $acfFieldObject['parent'], $postId );
			if ( $fieldParent ) {
				$fieldParentContent = maybe_unserialize( $fieldParent->post_content );
				if ( isset( $fieldParentContent['type'] ) && 'repeater' === $fieldParentContent['type'] ) {
					return true;
				}
			}
		} elseif ( is_string( $acfFieldObject['parent'] ) ) {
			$fieldParent = get_field_object( $acfFieldObject['parent'], $postId );
			if ( isset( $fieldParent['type'] ) && 'repeater' === $fieldParent['type'] ) {
				return true;
			}
		}
	}
	return false;
}

I won't be able unable to provide a trace, nor access to our installation, nor a copy of it.

I hope this helps you and others.

Take care,

June 14, 2023 at 12:25 pm #13825063

Eran Helzer
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hello,

Thank you very much for bringing this to our attention.

I have escalated this to our development team, with your fix for reference.
I will keep you updated on it's development so you know when you can remove your own fix.

Again thank you,
Take care

August 1, 2024 at 11:19 am #16029182

Laura
WPML Supporter since 05/2018

Languages: English (English ) Italian (Italiano )

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

For further development please follow this errata