*/
class WP_oEmbed {
public $providers = array();
+ /**
+ * @static
+ * @var array
+ */
public static $early_providers = array();
private $compat_methods = array( '_fetch_with_format', '_parse_json', '_parse_xml', '_parse_body' );
*/
public function __construct() {
$providers = array(
- '#http://(www\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed', true ),
- '#https://(www\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed?scheme=https', true ),
- '#http://(www\.)?youtube\.com/playlist.*#i' => array( 'http://www.youtube.com/oembed', true ),
- '#https://(www\.)?youtube\.com/playlist.*#i' => array( 'http://www.youtube.com/oembed?scheme=https', true ),
+ '#http://((m|www)\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed', true ),
+ '#https://((m|www)\.)?youtube\.com/watch.*#i' => array( 'http://www.youtube.com/oembed?scheme=https', true ),
+ '#http://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'http://www.youtube.com/oembed', true ),
+ '#https://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'http://www.youtube.com/oembed?scheme=https', true ),
'#http://youtu\.be/.*#i' => array( 'http://www.youtube.com/oembed', true ),
'#https://youtu\.be/.*#i' => array( 'http://www.youtube.com/oembed?scheme=https', true ),
'http://blip.tv/*' => array( 'http://blip.tv/oembed/', false ),
'#https?://(.+)\.tumblr\.com/post/.*#i' => array( 'https://www.tumblr.com/oembed/1.0', true ),
'#https?://(www\.)?kickstarter\.com/projects/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ),
'#https?://kck\.st/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ),
+ '#https?://cloudup\.com/.*#i' => array( 'https://cloudup.com/oembed', true ),
);
if ( ! empty( self::$early_providers['add'] ) ) {
*
* @param string $url The URL to the content.
* @param string|array $args Optional provider arguments.
- * @return bool|string False on failure, otherwise the oEmbed provider URL.
+ * @return false|string False on failure, otherwise the oEmbed provider URL.
*/
public function get_provider( $url, $args = '' ) {
* Attempts to discover link tags at the given URL for an oEmbed provider.
*
* @param string $url The URL that should be inspected for discovery `<link>` tags.
- * @return bool|string False on failure, otherwise the oEmbed provider URL.
+ * @return false|string False on failure, otherwise the oEmbed provider URL.
*/
public function discover( $url ) {
$providers = array();
* @param string $provider The URL to the oEmbed provider.
* @param string $url The URL to the content that is desired to be embedded.
* @param array $args Optional arguments. Usually passed from a shortcode.
- * @return bool|object False on failure, otherwise the result in the form of an object.
+ * @return false|object False on failure, otherwise the result in the form of an object.
*/
public function fetch( $provider, $url, $args = '' ) {
$args = wp_parse_args( $args, wp_embed_defaults( $url ) );
* @access private
* @param string $provider_url_with_args URL to the provider with full arguments list (url, maxheight, etc.)
* @param string $format Format to use
- * @return bool|object False on failure, otherwise the result in the form of an object.
+ * @return false|object|WP_Error False on failure, otherwise the result in the form of an object.
*/
private function _fetch_with_format( $provider_url_with_args, $format ) {
$provider_url_with_args = add_query_arg( 'format', $format, $provider_url_with_args );
*
* @since 3.0.0
* @access private
+ *
+ * @param string $response_body
+ * @return object|false
*/
private function _parse_json( $response_body ) {
- return ( ( $data = json_decode( trim( $response_body ) ) ) && is_object( $data ) ) ? $data : false;
+ $data = json_decode( trim( $response_body ) );
+ return ( $data && is_object( $data ) ) ? $data : false;
}
/**
*
* @since 3.0.0
* @access private
+ *
+ * @param string $response_body
+ * @return object|false
*/
private function _parse_xml( $response_body ) {
if ( ! function_exists( 'libxml_disable_entity_loader' ) )
*
* @since 3.6.0
* @access private
+ *
+ * @param string $response_body
+ * @return object|false
*/
private function _parse_xml_body( $response_body ) {
if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument' ) )
* @since 2.9.0
* @access private
*
- * @see WP_oEmbed
+ * @staticvar WP_oEmbed $wp_oembed
*
* @return WP_oEmbed object.
*/
function _wp_oembed_get_object() {
- static $wp_oembed;
+ static $wp_oembed = null;
- if ( is_null($wp_oembed) )
+ if ( is_null( $wp_oembed ) ) {
$wp_oembed = new WP_oEmbed();
-
+ }
return $wp_oembed;
}