Make WordPress Core


Ignore:
Timestamp:
05/11/2017 06:18:00 PM (9 years ago)
Author:
jnylen0
Message:

REST API: Add endpoint for proxying requests to external oEmbed providers.

This endpoint is a prerequisite for the media widgets work (see ​https://github.com/xwp/wp-core-media-widgets).

Also use the new endpoint in the media modal instead of the parse-embed AJAX action.

Props westonruter, timmydcrawford, swissspidy, jnylen0.
Fixes #40450.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-oembed.php

    r40574 r40628  
    320320
    321321        /**
     322         * Takes a URL and attempts to return the oEmbed data.
     323         *
     324         * @see WP_oEmbed::fetch()
     325         *
     326         * @since 4.8.0
     327         * @access public
     328         *
     329         * @param string       $url  The URL to the content that should be attempted to be embedded.
     330         * @param array|string $args Optional. Arguments, usually passed from a shortcode. Default empty.
     331         * @return false|object False on failure, otherwise the result in the form of an object.
     332         */
     333        public function get_data( $url, $args = '' ) {
     334                $args = wp_parse_args( $args );
     335
     336                $provider = $this->get_provider( $url, $args );
     337
     338                if ( ! $provider ) {
     339                        return false;
     340                }
     341
     342                $data = $this->fetch( $provider, $url, $args );
     343
     344                if ( false === $data ) {
     345                        return false;
     346                }
     347
     348                return $data;
     349        }
     350
     351        /**
    322352         * The do-it-all function that takes a URL and attempts to return the HTML.
    323353         *
    … …  
    333363         */
    334364        public function get_html( $url, $args = '' ) {
    335                 $args = wp_parse_args( $args );
    336 
    337365                /**
    338366                 * Filters the oEmbed result before any HTTP requests are made.
    … …  
    356384                }
    357385
    358                 $provider = $this->get_provider( $url, $args );
    359 
    360                 if ( ! $provider || false === $data = $this->fetch( $provider, $url, $args ) ) {
     386                $data = $this->get_data( $url, $args );
     387
     388                if ( false === $data ) {
    361389                        return false;
    362390                }
Note: See TracChangeset for help on using the changeset viewer.