From 771097dc2b1943a3095a9a34c586df85b4816a12 Mon Sep 17 00:00:00 2001 From: George Stephanis Date: Wed, 27 Apr 2016 15:01:29 -0400 Subject: [PATCH] An override for core Video shortcodes This lets us display legacy shortcodes as VideoPress videos as well. --- modules/videopress/shortcode.php | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/modules/videopress/shortcode.php b/modules/videopress/shortcode.php index 1fcb6fc0c4546..ab8d739170b02 100644 --- a/modules/videopress/shortcode.php +++ b/modules/videopress/shortcode.php @@ -138,3 +138,51 @@ function videopress_add_oembed_for_parameter( $oembed_provider ) { } add_filter( 'oembed_fetch_url', 'videopress_add_oembed_for_parameter' ); +/** + * An intermediary shortcode parser for the Core `[video]` shortcode. + * + * This lets us convert legacy video embeds over to VideoPress embeds, + * if the video files have been uploaded and transcoded. + * + * @param $attr + * + * @return string|void + */ +function videopress_shortcode_override_for_core_shortcode( $raw_attr ) { + $attr = $raw_attr; + $videopress_guid = false; + + if ( isset( $attr['videopress_guid'] ) ) { + $videopress_guid = $attr['videopress_guid']; + } + + // If we can find a local media item from the provided url… + $media_id = videopress_get_attachment_id_by_url( $attr['src'] ); + if ( $media_id ) { + // And that local media item has a VideoPress GUID attached to it… + $videopress_guid = get_post_meta( $media_id, 'videopress_guid', true ); + } + + if ( $videopress_guid ) { + $videopress_attr = array( $videopress_guid ); + if ( $attr['width'] ) { + $videopress_attr['w'] = (int) $attr['width']; + } + if ( $attr['autoplay'] ) { + $videopress_attr['autoplay'] = $attr['autoplay']; + } + if ( $attr['loop'] ) { + $videopress_attr['loop'] = $attr['loop']; + } + + // Then display the VideoPress version of the stored GUID! + return videopress_shortcode_callback( $videopress_attr ); + } + + // Nothing else caught, so fall back to the core shortcode. + return wp_video_shortcode( $raw_attr ); +} +/* +remove_shortcode( 'video' ); +add_shortcode( 'video', 'videopress_shortcode_override_for_core_shortcode' ); +*/