PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.4.4
Jetpack – WP Security, Backup, Speed, & Growth v6.4.4
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / functions.compat.php

functions.compat.php in Jetpack – WP Security, Backup, Speed, & Growth 6.4.4, at functions.compat.php

91 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Required for class.media-extractor.php to match expected function naming convention.
5 *
6 * @param $url Can be just the $url or the whole $atts array
7 * @return bool|mixed The Youtube video ID via jetpack_get_youtube_id
8 */
9
10 function jetpack_shortcode_get_youtube_id( $url ) {
11 return jetpack_get_youtube_id( $url );
12 }
13
14 /**
15 * @param $url Can be just the $url or the whole $atts array
16 * @return bool|mixed The Youtube video ID
17 */
18 function jetpack_get_youtube_id( $url ) {
19 // Do we have an $atts array? Get first att
20 if ( is_array( $url ) ) {
21 $url = reset( $url );
22 }
23
24 $url = youtube_sanitize_url( $url );
25 $url = parse_url( $url );
26 $id = false;
27
28 if ( ! isset( $url['query'] ) )
29 return false;
30
31 parse_str( $url['query'], $qargs );
32
33 if ( ! isset( $qargs['v'] ) && ! isset( $qargs['list'] ) )
34 return false;
35
36 if ( isset( $qargs['list'] ) )
37 $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['list'] );
38
39 if ( empty( $id ) )
40 $id = preg_replace( '|[^_a-z0-9-]|i', '', $qargs['v'] );
41
42 return $id;
43 }
44
45 if ( !function_exists( 'youtube_sanitize_url' ) ) :
46 /**
47 * Normalizes a YouTube URL to include a v= parameter and a query string free of encoded ampersands.
48 *
49 * @param string $url
50 * @return string The normalized URL
51 */
52 function youtube_sanitize_url( $url ) {
53 $url = trim( $url, ' "' );
54 $url = trim( $url );
55 $url = str_replace( array( 'youtu.be/', '/v/', '#!v=', '&amp;', '&#038;', 'playlist' ), array( 'youtu.be/?v=', '/?v=', '?v=', '&', '&', 'videoseries' ), $url );
56
57 // Replace any extra question marks with ampersands - the result of a URL like "http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US" being passed in.
58 $query_string_start = strpos( $url, "?" );
59
60 if ( false !== $query_string_start ) {
61 $url = substr( $url, 0, $query_string_start + 1 ) . str_replace( "?", "&", substr( $url, $query_string_start + 1 ) );
62 }
63
64 return $url;
65 }
66 endif;
67
68 /**
69 * Merge in three string helper functions from WPCOM.
70 *
71 * @see WPCOM/wp-content/mu-plugins/string-helpers.php
72 */
73 if ( ! function_exists( 'wp_startswith' ) ) :
74 function wp_startswith( $haystack, $needle ) {
75 return 0 === strpos( $haystack, $needle );
76 }
77 endif;
78
79
80 if ( ! function_exists( 'wp_endswith' ) ) :
81 function wp_endswith( $haystack, $needle ) {
82 return $needle === substr( $haystack, -strlen( $needle ));
83 }
84 endif;
85
86 if ( ! function_exists( 'wp_in' ) ) :
87 function wp_in( $needle, $haystack ) {
88 return false !== strpos( $haystack, $needle );
89 }
90 endif;
91