PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.4.2
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.4.2
2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 2.7.1 All 27 releases
insert-php / includes / compat.php

compat.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.4.2, at includes/compat.php

203 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WORDPRESS
4 *
5 * @author Webcraftic <wordpress.webraftic@gmail.com>, Alexander Kovalev <alex.kovalevv@gmail.com>
6 * @copyright (c) 17.05.2019, Webcraftic
7 * @version 1.0
8 */
9
10 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
11
12 if ( ! function_exists( 'rest_get_url_prefix' ) ) :
13 /**
14 * Retrieves the URL prefix for any API resource.
15 *
16 * @since 4.4.0
17 *
18 * @return string Prefix.
19 */
20 function rest_get_url_prefix() {
21 /**
22 * Filters the REST URL prefix.
23 *
24 * @since 4.4.0
25 *
26 * @param string $prefix URL prefix. Default 'wp-json'.
27 */
28 return apply_filters( 'rest_url_prefix', 'wp-json' );
29 }
30 endif;
31
32 if ( ! function_exists( 'wp_parse_url' ) ) :
33 /**
34 * A wrapper for PHP's parse_url() function that handles consistency in the return
35 * values across PHP versions.
36 *
37 * PHP 5.4.7 expanded parse_url()'s ability to handle non-absolute url's, including
38 * schemeless and relative url's with :// in the path. This function works around
39 * those limitations providing a standard output on PHP 5.2~5.4+.
40 *
41 * Secondly, across various PHP versions, schemeless URLs starting containing a ":"
42 * in the query are being handled inconsistently. This function works around those
43 * differences as well.
44 *
45 * Error suppression is used as prior to PHP 5.3.3, an E_WARNING would be generated
46 * when URL parsing failed.
47 *
48 * @since 1.6.9
49 * @since WP 4.4.0
50 * @since WP 4.7.0 The $component parameter was added for parity with PHP's parse_url().
51 *
52 * @param (string) $url The URL to parse.
53 * @param (int) $component The specific component to retrieve. Use one of the PHP
54 * predefined constants to specify which one.
55 * Defaults to -1 (= return all parts as an array).
56 *
57 * @return (mixed) False on parse failure; Array of URL components on success;
58 * When a specific component has been requested: null if the component
59 * doesn't exist in the given URL; a sting or - in the case of
60 * PHP_URL_PORT - integer when it does. See parse_url()'s return values.
61 * @see http://php.net/manual/en/function.parse-url.php
62 *
63 */
64 function wp_parse_url( $url, $component = - 1 ) {
65 $to_unset = [];
66 $url = strval( $url );
67
68 if ( '//' === substr( $url, 0, 2 ) ) {
69 $to_unset[] = 'scheme';
70 $url = 'placeholder:' . $url;
71 } else if ( '/' === substr( $url, 0, 1 ) ) {
72 $to_unset[] = 'scheme';
73 $to_unset[] = 'host';
74 $url = 'placeholder://placeholder' . $url;
75 }
76
77 $parts = @parse_url( $url );
78
79 if ( false === $parts ) {
80 // Parsing failure.
81 return $parts;
82 }
83
84 // Remove the placeholder values.
85 if ( $to_unset ) {
86 foreach ( $to_unset as $key ) {
87 unset( $parts[ $key ] );
88 }
89 }
90
91 return _get_component_from_parsed_url_array( $parts, $component );
92 }
93 endif;
94
95 if ( ! function_exists( '_get_component_from_parsed_url_array' ) ) :
96 /**
97 * Retrieve a specific component from a parsed URL array.
98 *
99 * @since 1.6.9
100 * @since WP 4.7.0
101 *
102 * @param (array|false) $url_parts The parsed URL. Can be false if the URL failed to parse.
103 * @param (int) $component The specific component to retrieve. Use one of the PHP
104 * predefined constants to specify which one.
105 * Defaults to -1 (= return all parts as an array).
106 *
107 * @return (mixed) False on parse failure; Array of URL components on success;
108 * When a specific component has been requested: null if the component
109 * doesn't exist in the given URL; a sting or - in the case of
110 * PHP_URL_PORT - integer when it does. See parse_url()'s return values.
111 * @see http://php.net/manual/en/function.parse-url.php
112 *
113 */
114 function _get_component_from_parsed_url_array( $url_parts, $component = - 1 ) {
115 if ( - 1 === $component ) {
116 return $url_parts;
117 }
118
119 $key = _wp_translate_php_url_constant_to_key( $component );
120
121 if ( false !== $key && is_array( $url_parts ) && isset( $url_parts[ $key ] ) ) {
122 return $url_parts[ $key ];
123 } else {
124 return null;
125 }
126 }
127 endif;
128
129 if ( ! function_exists( '_wp_translate_php_url_constant_to_key' ) ) :
130 /**
131 * Translate a PHP_URL_* constant to the named array keys PHP uses.
132 *
133 * @since 1.6.9
134 * @since WP 4.7.0
135 *
136 * @param (int) $constant PHP_URL_* constant.
137 *
138 * @return (string|bool) The named key or false.
139 * @see http://php.net/manual/en/url.constants.php
140 *
141 */
142 function _wp_translate_php_url_constant_to_key( $constant ) {
143 $translation = [
144 PHP_URL_SCHEME => 'scheme',
145 PHP_URL_HOST => 'host',
146 PHP_URL_PORT => 'port',
147 PHP_URL_USER => 'user',
148 PHP_URL_PASS => 'pass',
149 PHP_URL_PATH => 'path',
150 PHP_URL_QUERY => 'query',
151 PHP_URL_FRAGMENT => 'fragment',
152 ];
153
154 if ( isset( $translation[ $constant ] ) ) {
155 return $translation[ $constant ];
156 } else {
157 return false;
158 }
159 }
160 endif;
161
162 if ( ! function_exists( 'wp_scripts' ) ) :
163 /**
164 * Initialize $wp_scripts if it has not been set.
165 *
166 * @since 1.6.11
167 * @since WP 4.2.0
168 *
169 * @return WP_Scripts WP_Scripts instance.
170 * @global WP_Scripts $wp_scripts
171 *
172 */
173 function wp_scripts() {
174 global $wp_scripts;
175 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
176 $wp_scripts = new WP_Scripts(); // WPCS: override ok.
177 }
178
179 return $wp_scripts;
180 }
181 endif;
182
183 if ( ! function_exists( 'wp_doing_ajax' ) ) :
184 /**
185 * Determines whether the current request is a WordPress Ajax request.
186 *
187 * @since 1.7
188 * @since WP 4.7.0
189 *
190 * @return bool True if it's a WordPress Ajax request, false otherwise.
191 */
192 function wp_doing_ajax() {
193 /**
194 * Filters whether the current request is a WordPress Ajax request.
195 *
196 * @since 1.7
197 * @since WP 4.7.0
198 *
199 * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
200 */
201 return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
202 }
203 endif;