From c807d342669287cf54782e013b7f6bc2afc2e24d Mon Sep 17 00:00:00 2001 From: Govind Kumar Date: Thu, 1 Jun 2017 16:20:39 +0530 Subject: [PATCH] =?UTF-8?q?Used=20=C2=96libxml=5Fget=5Ferrors()=20to=20cat?= =?UTF-8?q?ch=20xml=20error=20while=20loading=20the=20xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-syndication-wp-xml-client.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/class-syndication-wp-xml-client.php b/includes/class-syndication-wp-xml-client.php index 3e26bc8..d38ad7e 100644 --- a/includes/class-syndication-wp-xml-client.php +++ b/includes/class-syndication-wp-xml-client.php @@ -251,11 +251,25 @@ public function get_posts( $args = array() ) { do_action( 'push_syndication_event', 'pull_success', $this->site_ID ); } + // Enable libxml to retrieve xml errors. + libxml_use_internal_errors(true); + /** @var SimpleXMLElement $xml */ $xml = simplexml_load_string( $feed, null, 0, $namespace, false ); if ( false === $xml ) { - Syndication_Logger::log_post_error( $this->site_ID, $status = 'error', $message = sprintf( __( 'Failed to parse feed at: %s', 'push-syndication' ), $this->feed_url ), $log_time = $site_post->postmeta['is_update'], $extra = array() ); + + $xml_errors = ''; + + // Retrieve errors. + foreach( libxml_get_errors() as $error ) { + $xml_errors .= $error->message . '\n'; + } + + // Clear libxml error buffer. + libxml_clear_errors(); + + Syndication_Logger::log_post_error( $this->site_ID, $status = 'error', $message = sprintf( __( 'Failed to parse feed at: %s \nErrors: %s', 'push-syndication' ), $this->feed_url, $xml_errors ), $log_time = $site_post->postmeta['is_update'], $extra = array() ); // Track the event. do_action( 'push_syndication_event', 'pull_failure', $this->site_ID );