| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Required for class.media-extractor.php to match expected function naming convention. |
| 12 | 12 | * |
| 13 | - * @param $url Can be just the $url or the whole $atts array. | |
| 13 | + * @param string|array $url Can be just the $url or the whole $atts array. | |
| 14 | 14 | * @return bool|mixed The Youtube video ID via jetpack_get_youtube_id |
| 15 | 15 | */ |
| 16 | 16 | function jetpack_shortcode_get_youtube_id( $url ) { |
| 17 | 17 | return jetpack_get_youtube_id( $url ); |
| @@ -28,9 +28,9 @@ | ||
| 28 | 28 | if ( is_array( $url ) ) { |
| 29 | 29 | $url = reset( $url ); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - $url = youtube_sanitize_url( $url ); | |
| 32 | + $url = jetpack_youtube_sanitize_url( $url ); | |
| 33 | 33 | $url = wp_parse_url( $url ); |
| 34 | 34 | $id = false; |
| 35 | 35 | |
| 36 | 36 | if ( ! isset( $url['query'] ) ) { |
| @@ -53,16 +53,16 @@ | ||
| 53 | 53 | |
| 54 | 54 | return $id; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | -if ( ! function_exists( 'youtube_sanitize_url' ) ) : | |
| 57 | +if ( ! function_exists( 'jetpack_youtube_sanitize_url' ) ) : | |
| 58 | 58 | /** |
| 59 | 59 | * Normalizes a YouTube URL to include a v= parameter and a query string free of encoded ampersands. |
| 60 | 60 | * |
| 61 | 61 | * @param string|array $url YouTube URL. |
| 62 | - * @return string|array The normalized URL or false if input is invalid. | |
| 62 | + * @return string|false The normalized URL or false if input is invalid. | |
| 63 | 63 | */ |
| 64 | - function youtube_sanitize_url( $url ) { | |
| 64 | + function jetpack_youtube_sanitize_url( $url ) { | |
| 65 | 65 | if ( is_array( $url ) && isset( $url['url'] ) ) { |
| 66 | 66 | $url = $url['url']; |
| 67 | 67 | } |
| 68 | 68 | if ( ! is_string( $url ) ) { |
| @@ -70,11 +70,11 @@ | ||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $url = trim( $url, ' "' ); |
| 73 | 73 | $url = trim( $url ); |
| 74 | - $url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&', '&', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url ); | |
| 74 | + $url = str_replace( array( 'youtu.be/', '/v/', '/shorts/', '#!v=', '&', '&', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '/watch?v=', '?v=', '&', '&', 'videoseries' ), $url ); | |
| 75 | 75 | |
| 76 | - // Replace any extra question marks with ampersands - the result of a URL like "https://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US" being passed in. | |
| 76 | + // Replace any extra question marks with ampersands - the result of a URL like "https://www.youtube.com/v/dQw4w9WgXcQ?fs=1&hl=en_US" being passed in. | |
| 77 | 77 | $query_string_start = strpos( $url, '?' ); |
| 78 | 78 | |
| 79 | 79 | if ( false !== $query_string_start ) { |
| 80 | 80 | $url = substr( $url, 0, $query_string_start + 1 ) . str_replace( '?', '&', substr( $url, $query_string_start + 1 ) ); |