Ticket #24712: ticket-24712.2.patch
File ticket-24712.2.patch, 2.0 KB (added by , 9 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 = ''; 25 22 26 /** 23 27 * @static 24 28 * @var array … … 427 431 /** This filter is documented in wp-includes/class-oembed.php */ 428 432 $args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args ); 429 433 434 /*** Reset any previous errors */ 435 $this->errors = array(); 436 $this->xml_errors = null; 437 430 438 $response = wp_safe_remote_get( $provider_url_with_args, $args ); 431 if ( 501 == wp_remote_retrieve_response_code( $response ) ) 439 if ( 501 == wp_remote_retrieve_response_code( $response ) ) { 440 $this->errors[] = 'not-implemented'; 432 441 return new WP_Error( 'not-implemented' ); 433 if ( ! $body = wp_remote_retrieve_body( $response ) ) 442 } 443 if ( ! $body = wp_remote_retrieve_body( $response ) ) { 444 $this->errors[] = 'empty-response-body'; 434 445 return false; 446 } 435 447 $parse_method = "_parse_$format"; 448 $this->response_body = $body; 436 449 return $this->$parse_method( $body ); 437 450 } 438 451 … … 446 459 * @return object|false 447 460 */ 448 461 private function _parse_json( $response_body ) { 449 $data = json_decode( trim( $response_body ) ); 450 return ( $data && is_object( $data ) ) ? $data : false; 462 $parse_results = ( ( $data = json_decode( trim( $response_body ) ) ) && is_object( $data ) ) ? $data : false; 463 if ( empty( $parse_results ) ) { 464 $this->errors[] = 'parse-json-failed'; 465 } 466 return $parse_results; 451 467 } 452 468 453 469 /** … … 468 484 469 485 $return = $this->_parse_xml_body( $response_body ); 470 486 487 $xml_errors = libxml_get_errors(); 488 471 489 libxml_use_internal_errors( $errors ); 472 490 libxml_disable_entity_loader( $loader ); 473 491 492 if ( empty( $return ) ) { 493 $this->errors[] = 'parse-xml-failed'; 494 $this->xml_errors = $xml_errors; 495 } 496 474 497 return $return; 475 498 } 476 499