Fix qTranslate with WordPress 3.9

When updating a blog of mine to WordPress 3.9 the page wouldn't load anymore because of qTranslate not able to cope with the update. In the error log it says:

PHP Catchable fatal error: Object of class WP_Post could not be converted to string in ../wp-content/plugins/qtranslate/qtranslate_core.php on line 455

The error is caused by this change: get_the_date() to accept optional $post argument

There is a proposed quick fix by Saverio Proto, but it doesn't take the problem at its root:

qTranslate registers the function qtrans_dateFromPostForCurrentLanguage($old_date, $format ='', $before = '', $after = '') for the hook get_the_date but it actually only accepts one parameter. With the new update it accepts a second parameter $post, which now wrongly fills the variable $before that is in the process being converted to a string.

So the solution simply is to delete the two parameters that were assigned the wrong meaning and have defaults anyway.

Posted in web

12 thoughts on “Fix qTranslate with WordPress 3.9

  1. Nothing spectacular, just ahead of the line with the error message I added a var_dump($before); to see that the content of the variable is an object instead of a string, then I checked the Codex to see the parameters of the function being called.

  2. Hi there! I´m pretty new to WordPress and especially to working with github. So my question is: Is it correct to download the gist code you offered, then extract the file in it and upload it on my FTP to the qtranslate folder? This is what I did, but I still get the error message on my website like before: CATCHABLE FATAL ERROR: OBJECT OF CLASS WP_POST COULD NOT BE CONVERTED TO STRING IN /HOME/.SITES/698/SITE8704257/WEB/WP-CONTENT/PLUGINS/QTRANSLATE/QTRANSLATE_CORE.PHP ON LINE 455

    What am I doing wrong?

    1. The file shows what needs to be changed. Either you can use the program called patch or, as this is a quite simple change, simply do what is shown using a text editor: remove the red line and add the green line (or just modify the line so that it looks like the green line afterwards).

  3. To the point! A good quick fix for the problem. Good that you also explained the root cause. I'm still wondering why the $before and $after are added to the function parameters and not outside of it?

  4. What do you mean? The function qtrans_dateFromPostForCurrentLanguage provides a $before and $after parameter when the WordPress API doesn't ask it to provide it. When WordPress changed their API by adding parameters, the $before variable now gets some unexpected content (which previously always was an empty string, because of the default value $before = '')

  5. Works fine except two little detail. It's breaking my nextgen gallery plugin.

    Now it's telling me : Invalid Displayed Gallery Works fine if I disable qtranslate plugin.

    And the editor still not properly working.

Comments are closed.