From 2d23c8fea7e6ef818c5f451277f473c3f83b5d62 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 10 Jun 2014 18:14:15 +0000 Subject: [PATCH] A little more abstraction in the `WP_oEmbed` class. Fixes #24381. Built from https://develop.svn.wordpress.org/trunk@28728 git-svn-id: http://core.svn.wordpress.org/trunk@28542 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-oembed.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/wp-includes/class-oembed.php b/wp-includes/class-oembed.php index db12c5fe1a..c0daaaddea 100644 --- a/wp-includes/class-oembed.php +++ b/wp-includes/class-oembed.php @@ -95,17 +95,17 @@ class WP_oEmbed { } /** - * The do-it-all function that takes a URL and attempts to return the HTML. + * Takes a URL and returns the corresponding oEmbed provider's URL, if there is one. * * @see WP_oEmbed::discover() - * @see WP_oEmbed::fetch() - * @see WP_oEmbed::data2html() * - * @param string $url The URL to the content that should be attempted to be embedded. - * @param array $args Optional arguments. Usually passed from a shortcode. - * @return bool|string False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed. + * @param string $url The URL to the content. + * @param array $args Optional arguments. + * @return bool|string False on failure, otherwise the oEmbed provider URL. + * @since 4.0.0 */ - public function get_html( $url, $args = '' ) { + public function get_provider( $url, $args = '' ) { + $provider = false; if ( !isset($args['discover']) ) @@ -129,6 +129,22 @@ class WP_oEmbed { if ( !$provider && $args['discover'] ) $provider = $this->discover( $url ); + return $provider; + } + + /** + * The do-it-all function that takes a URL and attempts to return the HTML. + * + * @see WP_oEmbed::fetch() + * @see WP_oEmbed::data2html() + * + * @param string $url The URL to the content that should be attempted to be embedded. + * @param array $args Optional arguments. Usually passed from a shortcode. + * @return bool|string False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed. + */ + function get_html( $url, $args = '' ) { + $provider = $this->get_provider( $url, $args ); + if ( !$provider || false === $data = $this->fetch( $provider, $url, $args ) ) return false;