From f54bb586c80aac17379bb61bbc968e1d1e342a9c Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 10 Jun 2014 18:13:43 +0000 Subject: [PATCH] A little more abstraction in the `WP_oEmbed` class. Fixes #24381. git-svn-id: https://develop.svn.wordpress.org/trunk@28728 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-oembed.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/class-oembed.php b/src/wp-includes/class-oembed.php index db12c5fe1a..c0daaaddea 100644 --- a/src/wp-includes/class-oembed.php +++ b/src/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;