possible fix to PHP error
-
I was getting the following php error every once-in-awhile which was not outputting any html after the twitter widget:
PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /path/to/wordpress/wp-content/plugins/multi-twitter-widget/widget.php:235\nStack trace:\n#0 /path/to/wordpress/wp-content/plugins/multi-twitter-widget/widget.php(235): SimpleXMLElement->__construct('')\n#1 /path/to/wordpress/wp-content/plugins/multi-twitter-widget/widget.php(431): multi_twitter(Array)\n#2 [internal function]: widget_multi_twitter(Array)\n#3 /path/to/wordpress/wp-includes/widgets.php(893): call_user_func_array('widget_multi_tw...', Array)\n#4 /path/to/wordpress/wp-content/themes/localconnect_20/footer.php(18): dynamic_sidebar('footer-sidebar')\n#5 /path/to/wordpress/wp-includes/template.php(407): require_once('/home/chicago/p...')\n#6 /h in /path/to/wordpress/wp-content/plugins/multi-twitter-widget/widget.php on line 235
I think I have a fix for this, although I know it’s not 100% because it could result in $feeds[] not being defined.
- I removed the === false on the “if ( $content === false )” because if you get a 400 error from Twitter, $xml still returns a string.
- I added an else to this if and moved the $xml and $feeds[] lines in the else. If you try to run SimpleXMLElement on a string that isn’t valid xml, you’ll get a php error.
if ( $content ) { // Content couldn't be retrieved... Do something.. $output .= '<li style="color: red;">Content could not be retrieved. Twitter API failed...</li>'; } else { // Createa an XML object from curl'ed content $xml = new SimpleXMLElement($content); $feeds[] = $xml; }
Hope this helps others.
https://www.ads-software.com/extend/plugins/multi-twitter-widget/
- The topic ‘possible fix to PHP error’ is closed to new replies.