PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 All 46 releases
gamipress / integrations / youtube / includes / functions.php

functions.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at integrations/youtube/includes/functions.php

69 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin
4 *
5 * @package GamiPress\Youtube\Admin
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Extract the video ID from the given URL
13 *
14 * @since 1.0.0
15 *
16 * @param string $url
17 *
18 * @return string
19 */
20 function gamipress_youtube_get_video_id_from_url( $url ) {
21
22 // Support for the following valid URLs
23 // youtube.com/v/{video_id}
24 // youtube.com/vi/{video_id}
25 // youtube.com/?v={video_id}
26 // youtube.com/?vi={video_id}
27 // youtube.com/watch?v={video_id}
28 // youtube.com/watch?vi={video_id}
29 // youtu.be/{video_id}
30 // youtube.com/embed/{video_id}
31 // http://youtube.com/v/{video_id}
32 // http://www.youtube.com/v/{video_id}
33 // https://www.youtube.com/v/{video_id}
34 // youtube.com/watch?v={video_id}&wtv=wtv
35 // http://www.youtube.com/watch?dev=inprogress&v={video_id}&feature=related
36 // https://m.youtube.com/watch?v={video_id}
37 preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
38
39 $video_id = (isset( $matches[1] ) ? $matches[1] : $url );
40
41 return $video_id;
42
43 }
44
45 /**
46 * Check the video ID format
47 *
48 * @since 1.0.0
49 *
50 * @param string $video_id
51 *
52 * @return string
53 */
54 function gamipress_youtube_check_video_id_format( $video_id ) {
55
56 if ( ! is_string( $video_id ) ) {
57 return false;
58 }
59
60 $video_id = trim( $video_id );
61
62 // Check if video ID has 11 characters
63 if ( preg_match( '/^[a-zA-Z0-9_-]{11}$/', $video_id ) ) {
64 return true;
65 }
66
67 return false;
68
69 }