Skip to content

Commit

Permalink
Update data-param for amp-youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaval-parekh committed Jun 30, 2021
1 parent 5b9b801 commit cf81afa
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions includes/embeds/class-amp-youtube-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,35 +242,18 @@ public function prepare_attributes( $args, $url ) {
$attributes['title'] = $args['title'];
}

$allowed_data_params = [
'cc_lang_pref',
'cc_load_policy',
'color',
'controls',
'disablekb',
'enablejsapi',
'end',
'fs',
'hl',
'iv_load_policy',
'list',
'listType',
'modestbranding',
'origin',
'playlist',
'playsinline',
'rel',
'widget_referrer',
];

$query_vars = [];
$query_param = wp_parse_url( $url, PHP_URL_QUERY );
wp_parse_str( $query_param, $query_vars );
$query_vars = ( ! empty( $query_vars ) && is_array( $query_vars ) ) ? $query_vars : [];

foreach ( $allowed_data_params as $allowed_data_param ) {
if ( isset( $query_vars[ $allowed_data_param ] ) ) {
$attributes[ "data-param-$allowed_data_param" ] = $query_vars[ $allowed_data_param ];
foreach ( $query_vars as $key => $value ) {

if ( in_array( $key, [ 'autoplay', 'loop', 'start' ], true ) ) {
continue;
}

$attributes[ "data-param-$key" ] = sanitize_text_field( $value );
}

foreach ( [ 'autoplay', 'loop' ] as $param ) {
Expand Down

0 comments on commit cf81afa

Please sign in to comment.