@@ -280,7 +280,7 @@ function able_player_parameters() {
280280 ),
281281 'youtube-id ' => array (
282282 'default ' => '' ,
283- 'description ' => __ ( '11-character YouTube ID ' , 'ableplayer ' ),
283+ 'description ' => __ ( '11-character YouTube ID or a URL to a YouTube video page. ' , 'ableplayer ' ),
284284 ),
285285 'youtube-desc-id ' => array (
286286 'default ' => '' ,
@@ -408,10 +408,12 @@ function ableplayer_shortcode( $atts, $content = null ) {
408408 $ o .= ' data-skin=" ' . $ all_atts ['skin ' ] . '" ' ;
409409 }
410410 if ( ! empty ( $ all_atts ['youtube-id ' ] ) ) {
411- $ o .= ' data-youtube-id=" ' . $ all_atts ['youtube-id ' ] . '" ' ;
411+ $ youtube_url = ableplayer_parse_youtube ( $ all_atts ['youtube-id ' ] );
412+ $ o .= ' data-youtube-id=" ' . $ all_atts ['youtube-id ' ] . '" ' ;
412413 }
413414 if ( ! empty ( $ all_atts ['youtube-desc-id ' ] ) ) {
414- $ o .= ' data-youtube-desc-id=" ' . $ all_atts ['youtube-desc-id ' ] . '" ' ;
415+ $ youtube_desc_url = ableplayer_parse_youtube ( $ all_atts ['youtube-id ' ] );
416+ $ o .= ' data-youtube-desc-id=" ' . $ all_atts ['youtube-desc-id ' ] . '" ' ;
415417 }
416418 if ( ! empty ( $ all_atts ['youtube-nocookie ' ] ) ) {
417419 $ o .= ' data-youtube-nocookie=" ' . $ all_atts ['youtube-nocookie ' ] . '" ' ;
@@ -438,6 +440,28 @@ function ableplayer_shortcode( $atts, $content = null ) {
438440}
439441add_shortcode ( 'ableplayer ' , 'ableplayer_shortcode ' );
440442
443+ /**
444+ * Parse the value of a YouTube shortcode attribute to extract YouTube ID if necessary.
445+ *
446+ * @param string $attr Value of the attribute.
447+ *
448+ * @param string YouTube video ID.
449+ */
450+ function ableplayer_parse_youtube ( $ attr ) {
451+ $ query = parse_url ( $ attr );
452+ if ( ! isset ( $ query ['query ' ] ) ) {
453+ $ replace = array ( 'http://youtu.be/ ' , 'https://youtu.be/ ' );
454+
455+ return str_replace ( $ replace , '' , $ attr );
456+ } else {
457+ parse_str ( $ query ['query ' ], $ results );
458+
459+ return $ results ['v ' ];
460+ }
461+
462+ return $ attr ;
463+ }
464+
441465/**
442466 * Get unique ID for a specific Ableplayer instance.
443467 *
0 commit comments