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

9 thoughts on “Fix qTranslate with WordPress 3.9

  1. 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).

  2. 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 = '')

Leave a Reply

Only people in my network can comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.