Catchable fatal error: Object of class WP_Error could not be converted to string
-
Hi,
I had this problem when the plugin is enabled and I get this error:
Catchable fatal error: Object of class WP_Error could not be converted to string in /PATH/wp-includes/formatting.php on line 1381
Set up:
- Permalinks post name
- Front page static front page set (posts page not set)
- Synchronization (the following are checked)
- Page order
- Custom fields
- Page parent
- Featured image
- Comment status
- Published date
- Page template
I’ve exported pages from dev location and imported them to the test WP location, activated the plugin and the above problem appeared. Then while bug hunting I came to this lines:
931:
$link = get_term_link($language, 'language'); // add a trailing slash as done by WP on homepage (otherwise could break the search form when the permalink structure does not include one) // only for pretty permalinks return $this->home_urls[$language->slug][$is_search] = $GLOBALS['wp_rewrite']->using_permalinks() ? trailingslashit($link) : $link;
It appears that sometimes the $language is empty and the get_term_link returns WP_Error array instead of the string. And that is the reason for the above error. You might want to insert a check here before the return line is $link is array or string and if array, do something about it. As when the above error happens, $link is array and trailingslashit expects string and not array.
Right now I’ve deleted the imported pages and created a new page and the plugin doesn’t throw the above error anymore. But still the check should be there.
- The topic ‘Catchable fatal error: Object of class WP_Error could not be converted to string’ is closed to new replies.