Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Embed a Youtube video.
- *
- * You can use either the complete form of the URL provided by Youtube
- * or only the ID of the video.
- *
- * In the feed, the shortcode displays a poster frame of the video linked to the original post.
- *
- * The only necessary parameter is $id.
- *
- * @param string $id The ID of the video, that could be either the complete URL or only the ID.
- * @param string $width The width of the player.
- * @param string $height The height of the player.
- * @param string $hour The starting hour of the video
- * @param string $min The starting minute of the video
- * @param string $sec The starting second of the video
- * @param string $autoplay Specify if the player will autoplay the video.
- * @param string $class Specify the class for the container P HTML element
- *
- * @example [youtubesc id=Gf69cRh01Q0]
- * @example [youtubesc id=http://www.youtube.com/watch?v=Gf69cRh01Q0]
- * @example [youtubesc id=http://www.youtube.com/watch?v=Gf69cRh01Q0 sec=55]
- * @example [youtubesc id=http://www.youtube.com/watch?v=Gf69cRh01Q0 width=460 min=12]
- * @example [youtubesc id=http://www.youtube.com/watch?v=Gf69cRh01Q0 width=460 height=372 hour=1 min=5 sec=9 autoplay=1]
- *
- * @since 1.0
- */
- add_shortcode('youtubesc', 'ubnsc_youtube');
- function ubnsc_youtube( $atts ) {
- extract( shortcode_atts( array(
- 'id' => '',
- 'width' => '480',
- 'height' => '360',
- 'hour' => 0,
- 'min' => 0,
- 'sec' => 0,
- 'autoplay' => 0,
- 'class' => '',
- ), $atts ) );
- // Sanitize some options
- $width = absint( intval( $width ) );
- $height = absint( intval( $height ) );
- $hour = absint( intval( $hour ) );
- $min = absint( intval( $min ) );
- $sec = absint( intval( $sec ) );
- $autoplay = absint( intval( $autoplay ) );
- if ( $autoplay < 0 || $autoplay > 1 ) $autoplay = 0;
- // Figure out if the user is using the complete form of the URL or only the ID of the video
- $pos = strpos( $id, 'http://' );
- if ( $pos === false ) {
- $videoid = $id;
- } else {
- $videoid = substr( esc_url( $id ), 31, 11 );
- }
- if ( $class ) {
- $element = '<p class="' . $class . '">';
- } else {
- $element = '<p>';
- }
- if ( ! is_feed() ) {
- // Convert hours and minutes in seconds
- $start = ( ( $hour * 60 * 60 ) + ( $min * 60 ) + $sec );
- $output = $element . '<object style="display:block; margin:0 auto;" type="application/x-shockwave-flash" data="http://www.youtube.com/v/' . $videoid . '?fs=1&hl=en_US&start=' . $start . '&autoplay=' . $autoplay. '" width="' . $width . '" height="' . $height . '">
- <param name="movie" value="http://www.youtube.com/v/' . $videoid . '?fs=1&hl=en_US&start=' . $start . '" />
- <param name="FlashVars" value="playerMode=embedded" />
- <param name="allowFullScreen" value="true" />
- <param name="allowscriptaccess" value="always" />
- <param name="wmode" value="transparent" />
- </object></p>';
- } else {
- $output = $element . '<a href="' . get_permalink() . '" title="' . __( 'Click here to view the embedded video', 'domain' ) . '">
- <img src="http://i3.ytimg.com/vi/' . $videoid . '/0.jpg" alt="' . __( 'Video preview', 'domain' ) . '" />
- </a></p>';
- }
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement