1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<?php
class Penci_AMP_WP_Utils { /** * wp_parse_url in < WordPress 4.7 does not respect the component arg, so we're adding this helper so we can use it. * * This can be removed once 4.8 is out and we bump up our min supported WP version. */ public static function parse_url( $url, $component = -1 ) { $parsed = wp_parse_url( $url, $component );
// Because < 4.7 always returned a full array regardless of component if ( -1 !== $component && is_array( $parsed ) ) { return self::_get_component_from_parsed_url_array( $parsed, $component ); }
return $parsed; }
/** * Included for 4.6 back-compat * * Copied from https://developer.wordpress.org/reference/functions/_get_component_from_parsed_url_array/ */ protected static function _get_component_from_parsed_url_array( $url_parts, $component = -1 ) { if ( -1 === $component ) { return $url_parts; }
$key = self::_wp_translate_php_url_constant_to_key( $component ); if ( false !== $key && is_array( $url_parts ) && isset( $url_parts[ $key ] ) ) { return $url_parts[ $key ]; }
return null; }
/** * Included for 4.6 back-compat * * Copied from https://developer.wordpress.org/reference/functions/_wp_translate_php_url_constant_to_key/ */ protected static function _wp_translate_php_url_constant_to_key( $constant ) { $translation = array( PHP_URL_SCHEME => 'scheme', PHP_URL_HOST => 'host', PHP_URL_PORT => 'port', PHP_URL_USER => 'user', PHP_URL_PASS => 'pass', PHP_URL_PATH => 'path', PHP_URL_QUERY => 'query', PHP_URL_FRAGMENT => 'fragment', );
if ( isset( $translation[ $constant ] ) ) { return $translation[ $constant ]; }
return false; } }
|