Ticket #24712: ticket-24712.patch
File ticket-24712.patch, 2.1 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class-oembed.php
19 19 */ 20 20 class WP_oEmbed { 21 21 public $providers = array(); 22 public $errors = array(); 23 public $xml_errors = null; 24 public $response_body = ''; 22 25 public static $early_providers = array(); 23 26 24 27 private $compat_methods = array( '_fetch_with_format', '_parse_json', '_parse_xml', '_parse_body' ); … … 421 424 /** This filter is documented in wp-includes/class-oembed.php */ 422 425 $args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args ); 423 426 427 /*** Reset any previous errors */ 428 $this->errors = array(); 429 $this->xml_errors = null; 430 424 431 $response = wp_safe_remote_get( $provider_url_with_args, $args ); 425 if ( 501 == wp_remote_retrieve_response_code( $response ) ) 432 if ( 501 == wp_remote_retrieve_response_code( $response ) ) { 433 $this->errors[] = 'not-implemented'; 426 434 return new WP_Error( 'not-implemented' ); 427 if ( ! $body = wp_remote_retrieve_body( $response ) ) 435 } 436 if ( ! $body = wp_remote_retrieve_body( $response ) ) { 437 $this->errors[] = 'empty-response-body'; 428 438 return false; 439 } 429 440 $parse_method = "_parse_$format"; 441 $this->response_body = $body; 430 442 return $this->$parse_method( $body ); 431 443 } 432 444 … … 437 449 * @access private 438 450 */ 439 451 private function _parse_json( $response_body ) { 440 return ( ( $data = json_decode( trim( $response_body ) ) ) && is_object( $data ) ) ? $data : false; 452 $parse_results = ( ( $data = json_decode( trim( $response_body ) ) ) && is_object( $data ) ) ? $data : false; 453 if ( empty( $parse_results ) ) { 454 $this->errors[] = 'parse-json-failed'; 455 } 456 return $parse_results; 441 457 } 442 458 443 459 /** … … 455 471 456 472 $return = $this->_parse_xml_body( $response_body ); 457 473 474 $xml_errors = libxml_get_errors(); 475 458 476 libxml_use_internal_errors( $errors ); 459 477 libxml_disable_entity_loader( $loader ); 460 478 479 if ( empty( $return ) ) { 480 $this->errors[] = 'parse-xml-failed'; 481 $this->xml_errors = $xml_errors; 482 } 483 461 484 return $return; 462 485 } 463 486