Skip to content

Commit

Permalink
Namespaced and refactored get_youtube_id()
Browse files Browse the repository at this point in the history
Prepended 'jetpack_' to the function to add a namespacing to prevent other plugins
from conflicting. Related #126
  • Loading branch information
blobaugh authored and enejb committed Jun 12, 2014
1 parent 6368137 commit f97b892
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion class.media-summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static function get( $post_id, $blog_id = 0, $args = array() ) {
$return['video'] = 'http://' . $embed;
$return['secure']['video'] = self::https( $return['video'] );
if ( strstr( $embed, 'youtube' ) ) {
$return['image'] = self::get_video_poster( 'youtube', get_youtube_id( $return['video'] ) );
$return['image'] = self::get_video_poster( 'youtube', jetpack_get_youtube_id( $return['video'] ) );
$return['secure']['image'] = self::https( $return['image'] );
} else if ( strstr( $embed, 'vimeo' ) ) {
$poster_image = get_post_meta( $post_id, 'vimeo_poster_image', true );
Expand Down
6 changes: 2 additions & 4 deletions functions.compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ function rawurlencode_deep( $value ) {
}
endif;

if ( !function_exists( 'get_youtube_id' ) ) :
/**
* @param $url Can be just the $url or the whole $atts array
* @return bool|mixed The Youtube video ID
*/
function get_youtube_id( $url ) {
function jetpack_get_youtube_id( $url ) {
// Do we have an $atts array? Get first att
if ( is_array( $url ) )
$url = $url[0];
Expand All @@ -44,7 +43,6 @@ function get_youtube_id( $url ) {

return $id;
}
endif;

if ( !function_exists( 'youtube_sanitize_url' ) ) :
/**
Expand All @@ -67,4 +65,4 @@ function youtube_sanitize_url( $url ) {

return $url;
}
endif;
endif;
4 changes: 2 additions & 2 deletions modules/publicize/enhanced-open-graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function enhanced_og_video( $tags ) {

if ( preg_match( '/((youtube|vimeo)\.com|youtu.be)/', $video_url ) ) {
if ( strstr( $video_url, 'youtube' ) ) {
$id = get_youtube_id( $video_url );
$id = jetpack_get_youtube_id( $video_url );
$video_url = 'http://www.youtube.com/v/' . $id . '?version=3&autohide=1';
$secure_video_url = 'https://www.youtube.com/v/' . $id . '?version=3&autohide=1';
} else if ( strstr( $video_url, 'vimeo' ) ) {
Expand All @@ -116,4 +116,4 @@ function enhanced_og_has_featured_image( $post_id ) {
if ( !empty( $featured ) && count( $featured ) > 0 )
return true;
return false;
}
}
9 changes: 1 addition & 8 deletions modules/shortcodes/youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,14 @@ function youtube_sanitize_url( $url ) {
* http://youtu.be/Rrohlqeir5E
*/

/**
* Same as get_youtube_id(), but with the prefix that function should've had.
*/
function jetpack_shortcode_get_youtube_id( $url ) {
return get_youtube_id( $url );
}

/**
* Converts a YouTube URL into an embedded YouTube video.
*/
function youtube_id( $url ) {
if ( apply_filters( 'jetpack_bail_on_shortcode', false, 'youtube' ) )
return '';

if ( ! $id = get_youtube_id( $url ) )
if ( ! $id = jetpack_get_youtube_id( $url ) )
return '<!--YouTube Error: bad URL entered-->';

$url = youtube_sanitize_url( $url );
Expand Down

0 comments on commit f97b892

Please sign in to comment.