jetpack_get_youtube_id

The Jetpack by WordPress.com jetpack get youtube id function.

Description

(bool|mixed) jetpack_get_youtube_id( $url ); 

Returns (bool|mixed)

The Youtube video ID

Parameters (1)

0. $url
Can be just the $url or the whole $atts array

Usage

  1. if ( !function_exists( 'jetpack_get_youtube_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/functions.compat.php'; 
  3.  
  4. // Can be just the $url or the whole $atts array 
  5. $url = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_get_youtube_id($url); 
  9.  

Defined (1)

The function is defined in the following location(s).

/functions.compat.php  
  1. function jetpack_get_youtube_id( $url ) { 
  2. // Do we have an $atts array? Get first att 
  3. if ( is_array( $url ) ) 
  4. $url = $url[0]; 
  5.  
  6. $url = youtube_sanitize_url( $url ); 
  7. $url = parse_url( $url ); 
  8. $id = false; 
  9.  
  10. if ( ! isset( $url['query'] ) ) 
  11. return false; 
  12.  
  13. parse_str( $url['query'], $qargs ); 
  14.  
  15. if ( ! isset( $qargs['v'] ) && ! isset( $qargs['list'] ) ) 
  16. return false; 
  17.  
  18. if ( isset( $qargs['list'] ) ) 
  19. $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['list'] ); 
  20.  
  21. if ( empty( $id ) ) 
  22. $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['v'] ); 
  23.  
  24. return $id;