Make WordPress Core

Ticket #24712: ticket-24712.2.patch

File ticket-24712.2.patch, 2.0 KB (added by eventualo, 9 years ago)

refreshed 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 = '';
     25
    2226        /**
    2327         * @static
    2428         * @var array
     
    427431                /** This filter is documented in wp-includes/class-oembed.php */
    428432                $args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args );
    429433
     434                /*** Reset any previous errors */
     435                $this->errors = array();
     436                $this->xml_errors = null;
     437
    430438                $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';
    432441                        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';
    434445                        return false;
     446                }
    435447                $parse_method = "_parse_$format";
     448                $this->response_body = $body;
    436449                return $this->$parse_method( $body );
    437450        }
    438451
     
    446459         * @return object|false
    447460         */
    448461        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;
    451467        }
    452468
    453469        /**
     
    468484
    469485                $return = $this->_parse_xml_body( $response_body );
    470486
     487                $xml_errors = libxml_get_errors();
     488
    471489                libxml_use_internal_errors( $errors );
    472490                libxml_disable_entity_loader( $loader );
    473491
     492                if ( empty( $return ) ) {
     493                        $this->errors[] = 'parse-xml-failed';
     494                        $this->xml_errors = $xml_errors;
     495                }
     496
    474497                return $return;
    475498        }
    476499