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

Last updated by Itamar 1 week, 5 days ago.

Assisted by: Itamar.

Author Posts
August 19, 2024 at 2:16 pm #16084242

desireeM

Background of the issue:
PHP notice Attempt to read property "source_language_code" on null
From file sitepress-multilingual-cmsmenudashboardwpml-tm-dashboard.class.php on line 275

when opening page /wp-admin/admin.php?page=tm/menu/main.php

WPML 4.6.12
WP 6.6.1

Symptoms:
PHP notice: Attempt to read property "source_language_code" on null

Questions:
Why am I seeing a PHP notice about 'source_language_code' being null?
How can I resolve the PHP notice in WPML?

August 20, 2024 at 6:55 am #16085763

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

Thanks for contacting us.

While you wait for my colleague to take over the ticket, let me try to help you with the issue quickly.

1)  In order to expedite handling your support requests, can you please share WPML support debug information from your site.

- To give debug information, login to your site and go to WPML → Support. From there click on the “debug information” link at the bottom of the page.
- Once on the “debug information” page, select the entire content of the text box and copy it.
- Now go back to our support forum, find debug information box and paste it.

More information on the link: https://wpml.org/faq/provide-debug-information-faster-support/

2)
Can you please try next:

- Make sure you have a backup.
- Disable all other plugins and leave active only WPML plugins
- Switch to WP default theme
- Check if the issue still happens.

Let me know how it goes.

Regards,
Drazen

August 20, 2024 at 9:03 am #16086226

desireeM

1) since the debug info json contains lots of data I'm not allowed to share, I can't do that.
If you let me know what specifically you need, I'm happy to provide that.

However the issue can be reproduced just using static analysis with WPML 4.6.12

2) yes.
This issue happens then too because it's obvious from the PHP types already

August 20, 2024 at 7:03 pm #16088125

Itamar
Supporter

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

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

Hi,

I'll continue to help you with this issue.

Today, we released WPML 4.6.13 and Strings Translation 3.2.14.

As a first step, can you please update our plugins to their latest versions and see if the error still shows?

I cannot replicate this issue on my test site with WPML 4.6.12, WordPress 6.6.1, and PHP 8.1.10.

Can you please tell me what is the PHP version on your server?

Also, can you please share with me the full error message that you get in the debug.log?

Thanks,
Itamar.

August 21, 2024 at 6:54 am #16088800

desireeM

Just updated both, the bug is still there when openiong /wp-admin/admin.php?page=tm/menu/main.php

PHP 8.3.9

The issue happens because sitepress.class.php line 1624

```
$details = $this->wpdb->get_row( $details_prepare );
```

returns null bc apparently this element loaded on this page doesn't exist

Which is also why you probably cannot reproduce it, since it's specific to a non-existing element.

You need to validate the `get_row` there

August 21, 2024 at 8:31 am #16089140

Itamar
Supporter

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

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

Thank you for the details you have provided.

I've escalated this issue to our second-tier supporters and will update you here when I have news about it.

I appreciate your patience.
Itamar.

August 21, 2024 at 8:44 am #16089241

christophe

Bonjour je viens de perdre le nom de domaine hidden link mais tu veux comtinuer d'utiliser le plugin et mon site donc j'ai créé/acheté un.fr et transformé mon ancien site en nouveau avec .FR pour pouvoir avoir mon site ci-dessous mais mais j'ai fait le passage surproduction en cliquant sur le fait que j'ai changé de nomaine et fait ensuite la mem chose sur le site de test (dev.) et ensuite sur le passage de développement je n'ai plus l'utilisation possible du plugin, maintenant je ne peux plus utiliser le plug-in sur le site de production. Comment faire pour te récupérer et pouvoir utiliser le plug-in merci. la demande de changement de site n'apparait plus

anciens production : hidden link / exercice :hidden link.
production : hidden link / exercice :hidden link.

le hidden link / est le plus important

merci

2024-08-21-Capture-écran-10.39.11.png
2024-08-21-Capture-écran-10.39.48.png
August 21, 2024 at 9:23 am #16089417

Itamar
Supporter

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

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

Hi, @christophe

This ticket has been escalated to our second-tier supporters. Please open a new ticket for your issue. You can open it here in our French forum.

https://wpml.org/fr/forums/forum/assistance-en-francais/

Regards,
Itamar.

August 22, 2024 at 2:46 pm #16095604

Itamar
Supporter

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

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

Hi,

Here are our conclusions. PHP 8.3.9 is a relatively newer version. According to WordPress, it is still in beta mode. You can check it here:

https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/

Probably it can be overcome by:

A. Go to WPML -> Support -> Troubleshooting (link) and click the 'Remove ghost entries from the translation tables' option.

B Or adding some NULL exception checks in wp-content/plugins/sitepress-multilingual-cms/menu/dashboard/wpml-tm-dashboard.class.php.
Change this:

$post_obj->is_translation = ( null === $language_details->source_language_code ) ? '0' : '1';

To this:

$has_source_language = !is_null($language_details->source_language_code);
$post_obj->is_translation = $has_source_language ? '1' : '0';

We were not able to reproduce this issue on our test site with PHP version 8.3.9, and since this version is still in beta mode for WordPress, we will not proceed with fixing it at this time.

We appreciate your report.

Regards,
Itamar.

August 29, 2024 at 9:47 am #16119123

desireeM

>PHP 8.3.9 is a relatively newer version. According to WordPress, it is still in beta mode.

This has nothing to do with PHP 8.3.
In e.g. PHP 7 you would get a notice here too with text:
Notice: Trying to get property of non-object

>B Or adding some NULL exception checks

Your fix doesn't work bc you and whoever wrote that code doesn't understand the absolute basics of PHP.
The issue is that $language_details is null.
You need to check that $language_details is not null, not the method access.

e.g. is_null( $language_details )

This means your code needs to change from:

```
$post_obj->is_translation = ( null === $language_details->source_language_code ) ? '0' : '1';
```

To:

```
$post_obj->is_translation = is_null( $language_details ) || ( null === $language_details->source_language_code ) ? '0' : '1';
```

However there are additional notices there for the other accesses - basically all places that use $language_details there need that is_null check there (e.g. the ->trid line for example)

August 29, 2024 at 5:47 pm #16121607

Itamar
Supporter

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

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

Thanks for elaborating on this.
I've passed it on to our second-tier supporter.

September 1, 2024 at 9:58 am #16128670

Itamar
Supporter

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

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

Hi,

Thank you for providing further input on this case.

So far, we have been unable to replicate this problem.

Can you please provide the steps to replicate this problem?
In other words, how can we trigger the following notice?

PHP notice Attempt to read property "source_language_code" on null

Thanks,
Itamar.

September 2, 2024 at 6:49 am #16130085

desireeM

By making
>$language_details = $this->sitepress->get_element_language_details( $post->ID, 'post_' . $post->post_type );

be null.

For basic reproduction you can just do:
$language_details = null;
there.

In a non-mock scenarion this happens bc get_element_language_details( returns null bc $this->wpdb->get_row() in this function returns null bc the query didn't find anything. This line:

>$details = $this->wpdb->get_row( $details_prepare );

September 2, 2024 at 8:22 am #16130503

Itamar
Supporter

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

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

Thanks!

I've shared this with our second-tier supporter.

Regards,
Itamar.

September 2, 2024 at 3:34 pm #16132721

Itamar
Supporter

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

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

Hi,

We'd be grateful if you could replicate this issue on a test site we created. You can access it here.

hidden link

Thanks,
Itamar.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.