Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Convert YouTube Embed Code
- * Will convert an embed code for a YouTube video
- * to be used with the myCRED Points for viewing videos hook.
- * Will use your default payout logic set in your hook.
- * @version 1.0.2
- */
- function mycred_pro_parse_video_embed( $code = '' ) {
- preg_match( '/width="(\d*)" height="(\d*)" src="(.*?)"/i', $code, $sizes );
- if ( $sizes ) {
- // First we check if the video is a YouTube video
- preg_match( "#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=embed/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $sizes[3], $matches );
- if ( $matches ) {
- return mycred_render_shortcode_video( array(
- 'width' => $sizes[1],
- 'height' => $sizes[2],
- 'id' => str_replace( '?rel=0', '', $matches[0] )
- ) );
- }
- // Not a YouTube video, maybe it's a Vimeo Video? (requires myCRED Video Add-on)
- else {
- preg_match( '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/', $sizes[3], $matches );
- if ( $matches ) {
- return mycred_render_shortcode_video( array(
- 'width' => $sizes[1],
- 'height' => $sizes[2],
- 'id' => str_replace( '?rel=0', '', $matches[0] )
- ) );
- }
- }
- }
- return $code;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement