Skip to content

Commit b983137

Browse files
committed
deploy: a7cd640
1 parent 25fa73b commit b983137

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

ableplayer.php.html

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
),
307307
'youtube-id' => array(
308308
'default' => '',
309-
'description' => __( '11-character YouTube ID', 'ableplayer' ),
309+
'description' => __( '11-character YouTube ID or a URL to a YouTube video page.', 'ableplayer' ),
310310
),
311311
'youtube-desc-id' => array(
312312
'default' => '',
@@ -434,10 +434,12 @@
434434
$o .= ' data-skin="' . $all_atts['skin'] . '"';
435435
}
436436
if ( ! empty( $all_atts['youtube-id'] ) ) {
437-
$o .= ' data-youtube-id="' . $all_atts['youtube-id'] . '"';
437+
$youtube_url = ableplayer_parse_youtube( $all_atts['youtube-id'] );
438+
$o .= ' data-youtube-id="' . $all_atts['youtube-id'] . '"';
438439
}
439440
if ( ! empty( $all_atts['youtube-desc-id'] ) ) {
440-
$o .= ' data-youtube-desc-id="' . $all_atts['youtube-desc-id'] . '"';
441+
$youtube_desc_url = ableplayer_parse_youtube( $all_atts['youtube-id'] );
442+
$o .= ' data-youtube-desc-id="' . $all_atts['youtube-desc-id'] . '"';
441443
}
442444
if ( ! empty( $all_atts['youtube-nocookie'] ) ) {
443445
$o .= ' data-youtube-nocookie="' . $all_atts['youtube-nocookie'] . '"';
@@ -464,6 +466,28 @@
464466
}
465467
add_shortcode( 'ableplayer', 'ableplayer_shortcode' );
466468

469+
/**
470+
* Parse the value of a YouTube shortcode attribute to extract YouTube ID if necessary.
471+
*
472+
* @param string $attr Value of the attribute.
473+
*
474+
* @param string YouTube video ID.
475+
*/
476+
function ableplayer_parse_youtube( $attr ) {
477+
$query = parse_url( $attr );
478+
if ( ! isset( $query['query'] ) ) {
479+
$replace = array( 'http://youtu.be/', 'https://youtu.be/' );
480+
481+
return str_replace( $replace, '', $attr );
482+
} else {
483+
parse_str( $query['query'], $results );
484+
485+
return $results['v'];
486+
}
487+
488+
return $attr;
489+
}
490+
467491
/**
468492
* Get unique ID for a specific Ableplayer instance.
469493
*

0 commit comments

Comments
 (0)