wpsight / wpcasa

WPCasa WordPress Real Estate
https://wpcasa.com
GNU General Public License v2.0
42 stars 23 forks source link

Object of class WP_Error could not be converted to string in `class-wpsight-helpers.php` #95

Open Vaelor opened 5 years ago

Vaelor commented 5 years ago

Hi! First of all - not much PHP experience, nor WordPress. Itried to fix a page, where the plugin threw an error:

Catchable fatal error: Object of class WP_Error could not be converted to string in https://github.com/wpsight/wpcasa/blob/master/wpcasa/includes/class-wpsight-helpers.php#L680

There is a function call to get_term_link which throws. I am googled a bit, found it is a WordPress function and it has a note attached

PHP may halt if you attempt to print an error result ("Catchable fatal error: Object of class WP_Error could not be converted to string"). You should always use is_wp_error() to check the result of this function, in case the term does not exist.

https://developer.wordpress.org/reference/functions/get_term_link/#more-information

Did that.

+               if ( $linked === true && !is_wp_error(get_term_link( $term->slug, $taxonomy)) ) {
-               if ( $linked === true ) {

Not sure if I 'fixed' it or what potential side effects there could be, the page seems to be (mostly) working again.

Setup: WordPress 5.2.1 PHP 7.2.18 MySQL 5.5.60 WPCasa 1.0.6.1 If you need any more Input, please let me know. I have no clue what could be important for you.

florianrusch commented 5 years ago

@Vaelor thank you for supporting this issue.

Could you describe in which case this error appears? If I'm reading the code of the get_term_link method correct, then it returns an WP_Error if the $term is not an object. The message indicates that the term is empty. Is this the case if you have assigned a post entry to a term and after that you are deleting this term in the term list view?

Vaelor commented 5 years ago

@florianrusch $term has a value (at least $term->slug printed 'balcony'). There is a plug-in for wpcasa 'extendable fields' or something like that - sorry for the vagueness - which allows to add tag like properties.

But, currently the main reason that this happened at all seems to be a small database corruption, which happened from upgrading WP 5.1 to 5.2. I am not yet completely sure. I will try to update you with further information, but maybe this is a rare occurrence and normally wouldn't happen.

Not sure if the check for wperror should still be made or if it's better to throw since this should never happen?

Vaelor commented 5 years ago

So, thanks for your time on this. The reason this happened at all, was a plugin called wp-optimize - which it seems was run on the database - and corrupted a part of it. I believe the error I described here probably never happens under normal circumstances - at least if no database corruption occurs.

I would leave it up to you, to close this issue, since I do not know if catching that error is something one would/should do or if throwing it is better. Sorry for bothering you :-)

florianrusch commented 5 years ago

No problem. @JoeHana is currently working on a new version of WPCasa. I don't know if he'll consider that.