Skip to content

Instantly share code, notes, and snippets.

@mawiswiss
Last active May 6, 2022 18:36
Show Gist options
  • Select an option

  • Save mawiswiss/61074b488aae12460a17882aeb3e0fd8 to your computer and use it in GitHub Desktop.

Select an option

Save mawiswiss/61074b488aae12460a17882aeb3e0fd8 to your computer and use it in GitHub Desktop.
WordPress oEmbed handler to integrate video and audio players from SRG (including SRF, RSI, RTS and RTR)
wp_embed_register_handler('srg', '#https?:\/\/(?:www\.|player\.)?(srf|rsi|rts|rtr)\.ch\/.+(detail|video|audio).((?:.{8}-.{4}-.{4}-.{4}-.{12})|\d*)(?:.startTime=(\d*)|.*)#i', 'srgEmbedHandler');
function srgEmbedHandler($matches, $attr, $url, $rawattr)
{
return sprintf(
'<iframe width="560" height="315" src="https://%1$s.ch/play/embed?urn=urn:%1$s:%2$s:%3$s%4$s" allowfullscreen allow="encrypted-media"></iframe>',
esc_attr($matches[1]),
esc_attr($matches[2]) === 'audio' ? 'audio' : 'video',
esc_attr($matches[3]),
array_key_exists(4, $matches) ? esc_attr('&startTime=' . $matches[4]) : '',
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment