Make WordPress Core

Ticket #24712: ticket-24712.patch

File ticket-24712.patch, 2.1 KB (added by GunGeekATX, 10 years ago)

Proposed patch

  • src/wp-includes/class-oembed.php

     
    1919 */
    2020class WP_oEmbed {
    2121        public $providers = array();
     22        public $errors = array();
     23        public $xml_errors = null;
     24        public $response_body = '';
    2225        public static $early_providers = array();
    2326
    2427        private $compat_methods = array( '_fetch_with_format', '_parse_json', '_parse_xml', '_parse_body' );
     
    421424                /** This filter is documented in wp-includes/class-oembed.php */
    422425                $args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args );
    423426
     427                /*** Reset any previous errors */
     428                $this->errors = array();
     429                $this->xml_errors = null;
     430
    424431                $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';
    426434                        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';
    428438                        return false;
     439                }
    429440                $parse_method = "_parse_$format";
     441                $this->response_body = $body;
    430442                return $this->$parse_method( $body );
    431443        }
    432444
     
    437449         * @access private
    438450         */
    439451        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;
    441457        }
    442458
    443459        /**
     
    455471
    456472                $return = $this->_parse_xml_body( $response_body );
    457473
     474                $xml_errors = libxml_get_errors();
     475
    458476                libxml_use_internal_errors( $errors );
    459477                libxml_disable_entity_loader( $loader );
    460478
     479                if ( empty( $return ) ) {
     480                        $this->errors[] = 'parse-xml-failed';
     481                        $this->xml_errors = $xml_errors;
     482                }
     483
    461484                return $return;
    462485        }
    463486