# gamipress/7.9.7/integrations/youtube/includes/functions.php

GamiPress – Gamification plugin to reward points, badges &amp; ranks in WordPress, now with AI, version 7.9.7. 69 lines.

- Page: https://pluginprobe.com/plugins/gamipress/7.9.7/code/integrations/youtube/includes/functions.php
- Raw: https://pluginprobe.com/plugins/gamipress/7.9.7/raw/integrations/youtube/includes/functions.php
- Modified: 2026-07-10T07:29:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gamipress/7.9.7/code/integrations/youtube/includes/functions.php#L10-L20`.

```php
<?php
/**
 * Admin
 *
 * @package GamiPress\Youtube\Admin
 * @since 1.0.0
 */
// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) exit;

/**
 * Extract the video ID from the given URL
 *
 * @since 1.0.0
 *
 * @param string $url
 *
 * @return string
 */
function gamipress_youtube_get_video_id_from_url( $url ) {

    // Support for the following valid URLs
    // youtube.com/v/{video_id}
    // youtube.com/vi/{video_id}
    // youtube.com/?v={video_id}
    // youtube.com/?vi={video_id}
    // youtube.com/watch?v={video_id}
    // youtube.com/watch?vi={video_id}
    // youtu.be/{video_id}
    // youtube.com/embed/{video_id}
    // http://youtube.com/v/{video_id}
    // http://www.youtube.com/v/{video_id}
    // https://www.youtube.com/v/{video_id}
    // youtube.com/watch?v={video_id}&wtv=wtv
    // http://www.youtube.com/watch?dev=inprogress&v={video_id}&feature=related
    // https://m.youtube.com/watch?v={video_id}
    preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);

    $video_id = (isset( $matches[1] ) ? $matches[1] : $url );

    return $video_id;

}

/**
 * Check the video ID format
 *
 * @since 1.0.0
 *
 * @param string $video_id
 *
 * @return string
 */
function gamipress_youtube_check_video_id_format( $video_id ) {

    if ( ! is_string( $video_id ) ) {
        return false;
    }

    $video_id = trim( $video_id );

    // Check if video ID has 11 characters
    if ( preg_match( '/^[a-zA-Z0-9_-]{11}$/', $video_id ) ) {
        return true;
    }

    return false;

}
```
