author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* These functions are needed to load WordPress. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
* Return the HTTP protocol sent by the server. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* @return string The HTTP protocol. Default: HTTP/1.0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
function wp_get_server_protocol() { |
16 | 16 |
$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : ''; |
17 |
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ), true ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
$protocol = 'HTTP/1.0'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
return $protocol; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
/** |
5 | 24 |
* Fix `$_SERVER` variables for various setups. |
0 | 25 |
* |
5 | 26 |
* @since 3.0.0 |
0 | 27 |
* @access private |
5 | 28 |
* |
29 |
* @global string $PHP_SELF The filename of the currently executing script, |
|
30 |
* relative to the document root. |
|
0 | 31 |
*/ |
32 |
function wp_fix_server_vars() { |
|
33 |
global $PHP_SELF; |
|
34 |
||
35 |
$default_server_values = array( |
|
36 |
'SERVER_SOFTWARE' => '', |
|
9 | 37 |
'REQUEST_URI' => '', |
0 | 38 |
); |
39 |
||
40 |
$_SERVER = array_merge( $default_server_values, $_SERVER ); |
|
41 |
||
16 | 42 |
// Fix for IIS when running with PHP ISAPI. |
43 |
if ( empty( $_SERVER['REQUEST_URI'] ) || ( 'cgi-fcgi' !== PHP_SAPI && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) { |
|
0 | 44 |
|
45 |
if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { |
|
16 | 46 |
// IIS Mod-Rewrite. |
0 | 47 |
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; |
9 | 48 |
} elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) { |
16 | 49 |
// IIS Isapi_Rewrite. |
0 | 50 |
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; |
51 |
} else { |
|
16 | 52 |
// Use ORIG_PATH_INFO if there is no PATH_INFO. |
9 | 53 |
if ( ! isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) { |
0 | 54 |
$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; |
9 | 55 |
} |
0 | 56 |
|
16 | 57 |
// Some IIS + PHP configurations put the script-name in the path-info (no need to append it twice). |
0 | 58 |
if ( isset( $_SERVER['PATH_INFO'] ) ) { |
9 | 59 |
if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) { |
0 | 60 |
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; |
9 | 61 |
} else { |
0 | 62 |
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; |
9 | 63 |
} |
0 | 64 |
} |
65 |
||
16 | 66 |
// Append the query string if it exists and isn't null. |
0 | 67 |
if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { |
68 |
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
||
16 | 73 |
// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests. |
9 | 74 |
if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) { |
0 | 75 |
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; |
9 | 76 |
} |
0 | 77 |
|
16 | 78 |
// Fix for Dreamhost and other PHP as CGI hosts. |
9 | 79 |
if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) { |
0 | 80 |
unset( $_SERVER['PATH_INFO'] ); |
9 | 81 |
} |
0 | 82 |
|
16 | 83 |
// Fix empty PHP_SELF. |
0 | 84 |
$PHP_SELF = $_SERVER['PHP_SELF']; |
9 | 85 |
if ( empty( $PHP_SELF ) ) { |
16 | 86 |
$_SERVER['PHP_SELF'] = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] ); |
87 |
$PHP_SELF = $_SERVER['PHP_SELF']; |
|
9 | 88 |
} |
18 | 89 |
|
90 |
wp_populate_basic_auth_from_authorization_header(); |
|
91 |
} |
|
92 |
||
93 |
/** |
|
94 |
* Populates the Basic Auth server details from the Authorization header. |
|
95 |
* |
|
96 |
* Some servers running in CGI or FastCGI mode don't pass the Authorization |
|
97 |
* header on to WordPress. If it's been rewritten to the `HTTP_AUTHORIZATION` header, |
|
98 |
* fill in the proper $_SERVER variables instead. |
|
99 |
* |
|
100 |
* @since 5.6.0 |
|
101 |
*/ |
|
102 |
function wp_populate_basic_auth_from_authorization_header() { |
|
103 |
// If we don't have anything to pull from, return early. |
|
104 |
if ( ! isset( $_SERVER['HTTP_AUTHORIZATION'] ) && ! isset( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ) ) { |
|
105 |
return; |
|
106 |
} |
|
107 |
||
108 |
// If either PHP_AUTH key is already set, do nothing. |
|
109 |
if ( isset( $_SERVER['PHP_AUTH_USER'] ) || isset( $_SERVER['PHP_AUTH_PW'] ) ) { |
|
110 |
return; |
|
111 |
} |
|
112 |
||
113 |
// From our prior conditional, one of these must be set. |
|
114 |
$header = isset( $_SERVER['HTTP_AUTHORIZATION'] ) ? $_SERVER['HTTP_AUTHORIZATION'] : $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; |
|
115 |
||
116 |
// Test to make sure the pattern matches expected. |
|
117 |
if ( ! preg_match( '%^Basic [a-z\d/+]*={0,2}$%i', $header ) ) { |
|
118 |
return; |
|
119 |
} |
|
120 |
||
121 |
// Removing `Basic ` the token would start six characters in. |
|
122 |
$token = substr( $header, 6 ); |
|
123 |
$userpass = base64_decode( $token ); |
|
124 |
||
125 |
list( $user, $pass ) = explode( ':', $userpass ); |
|
126 |
||
127 |
// Now shove them in the proper keys where we're expecting later on. |
|
128 |
$_SERVER['PHP_AUTH_USER'] = $user; |
|
129 |
$_SERVER['PHP_AUTH_PW'] = $pass; |
|
0 | 130 |
} |
131 |
||
132 |
/** |
|
5 | 133 |
* Check for the required PHP version, and the MySQL extension or |
134 |
* a database drop-in. |
|
0 | 135 |
* |
136 |
* Dies if requirements are not met. |
|
137 |
* |
|
5 | 138 |
* @since 3.0.0 |
0 | 139 |
* @access private |
5 | 140 |
* |
141 |
* @global string $required_php_version The required PHP version string. |
|
142 |
* @global string $wp_version The WordPress version string. |
|
0 | 143 |
*/ |
144 |
function wp_check_php_mysql_versions() { |
|
145 |
global $required_php_version, $wp_version; |
|
146 |
$php_version = phpversion(); |
|
5 | 147 |
|
0 | 148 |
if ( version_compare( $required_php_version, $php_version, '>' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
$protocol = wp_get_server_protocol(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); |
5 | 151 |
header( 'Content-Type: text/html; charset=utf-8' ); |
16 | 152 |
printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version ); |
9 | 153 |
exit( 1 ); |
0 | 154 |
} |
155 |
||
18 | 156 |
if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) |
157 |
// This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet. |
|
158 |
&& ( defined( 'WP_CONTENT_DIR' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) |
|
159 |
|| ! file_exists( ABSPATH . 'wp-content/db.php' ) ) |
|
160 |
) { |
|
16 | 161 |
require_once ABSPATH . WPINC . '/functions.php'; |
0 | 162 |
wp_load_translations_early(); |
9 | 163 |
$args = array( |
164 |
'exit' => false, |
|
165 |
'code' => 'mysql_not_found', |
|
166 |
); |
|
167 |
wp_die( |
|
168 |
__( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ), |
|
16 | 169 |
__( 'Requirements Not Met' ), |
9 | 170 |
$args |
171 |
); |
|
172 |
exit( 1 ); |
|
0 | 173 |
} |
174 |
} |
|
175 |
||
176 |
/** |
|
16 | 177 |
* Retrieves the current environment type. |
178 |
* |
|
179 |
* The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable, |
|
180 |
* or a constant of the same name. |
|
181 |
* |
|
18 | 182 |
* Possible values are 'local', 'development', 'staging', and 'production'. |
16 | 183 |
* If not set, the type defaults to 'production'. |
184 |
* |
|
185 |
* @since 5.5.0 |
|
186 |
* @since 5.5.1 Added the 'local' type. |
|
187 |
* @since 5.5.1 Removed the ability to alter the list of types. |
|
188 |
* |
|
189 |
* @return string The current environment type. |
|
190 |
*/ |
|
191 |
function wp_get_environment_type() { |
|
192 |
static $current_env = ''; |
|
193 |
||
194 |
if ( $current_env ) { |
|
195 |
return $current_env; |
|
196 |
} |
|
197 |
||
198 |
$wp_environments = array( |
|
199 |
'local', |
|
200 |
'development', |
|
201 |
'staging', |
|
202 |
'production', |
|
203 |
); |
|
204 |
||
205 |
// Add a note about the deprecated WP_ENVIRONMENT_TYPES constant. |
|
206 |
if ( defined( 'WP_ENVIRONMENT_TYPES' ) && function_exists( '_deprecated_argument' ) ) { |
|
207 |
if ( function_exists( '__' ) ) { |
|
208 |
/* translators: %s: WP_ENVIRONMENT_TYPES */ |
|
209 |
$message = sprintf( __( 'The %s constant is no longer supported.' ), 'WP_ENVIRONMENT_TYPES' ); |
|
210 |
} else { |
|
211 |
$message = sprintf( 'The %s constant is no longer supported.', 'WP_ENVIRONMENT_TYPES' ); |
|
212 |
} |
|
213 |
||
214 |
_deprecated_argument( |
|
215 |
'define()', |
|
216 |
'5.5.1', |
|
217 |
$message |
|
218 |
); |
|
219 |
} |
|
220 |
||
221 |
// Check if the environment variable has been set, if `getenv` is available on the system. |
|
222 |
if ( function_exists( 'getenv' ) ) { |
|
223 |
$has_env = getenv( 'WP_ENVIRONMENT_TYPE' ); |
|
224 |
if ( false !== $has_env ) { |
|
225 |
$current_env = $has_env; |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
// Fetch the environment from a constant, this overrides the global system variable. |
|
230 |
if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) { |
|
231 |
$current_env = WP_ENVIRONMENT_TYPE; |
|
232 |
} |
|
233 |
||
234 |
// Make sure the environment is an allowed one, and not accidentally set to an invalid value. |
|
235 |
if ( ! in_array( $current_env, $wp_environments, true ) ) { |
|
236 |
$current_env = 'production'; |
|
237 |
} |
|
238 |
||
239 |
return $current_env; |
|
240 |
} |
|
241 |
||
242 |
/** |
|
0 | 243 |
* Don't load all of WordPress when handling a favicon.ico request. |
5 | 244 |
* |
0 | 245 |
* Instead, send the headers for a zero-length favicon and bail. |
246 |
* |
|
247 |
* @since 3.0.0 |
|
16 | 248 |
* @deprecated 5.4.0 Deprecated in favor of do_favicon(). |
0 | 249 |
*/ |
250 |
function wp_favicon_request() { |
|
16 | 251 |
if ( '/favicon.ico' === $_SERVER['REQUEST_URI'] ) { |
9 | 252 |
header( 'Content-Type: image/vnd.microsoft.icon' ); |
0 | 253 |
exit; |
254 |
} |
|
255 |
} |
|
256 |
||
257 |
/** |
|
5 | 258 |
* Die with a maintenance message when conditions are met. |
0 | 259 |
* |
260 |
* The default message can be replaced by using a drop-in (maintenance.php in |
|
261 |
* the wp-content directory). |
|
262 |
* |
|
5 | 263 |
* @since 3.0.0 |
0 | 264 |
* @access private |
265 |
*/ |
|
266 |
function wp_maintenance() { |
|
16 | 267 |
// Return if maintenance mode is disabled. |
268 |
if ( ! wp_is_maintenance_mode() ) { |
|
0 | 269 |
return; |
9 | 270 |
} |
0 | 271 |
|
16 | 272 |
if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { |
273 |
require_once WP_CONTENT_DIR . '/maintenance.php'; |
|
274 |
die(); |
|
275 |
} |
|
276 |
||
277 |
require_once ABSPATH . WPINC . '/functions.php'; |
|
278 |
wp_load_translations_early(); |
|
279 |
||
280 |
header( 'Retry-After: 600' ); |
|
281 |
||
282 |
wp_die( |
|
283 |
__( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ), |
|
284 |
__( 'Maintenance' ), |
|
285 |
503 |
|
286 |
); |
|
287 |
} |
|
288 |
||
289 |
/** |
|
290 |
* Check if maintenance mode is enabled. |
|
291 |
* |
|
292 |
* Checks for a file in the WordPress root directory named ".maintenance". |
|
293 |
* This file will contain the variable $upgrading, set to the time the file |
|
294 |
* was created. If the file was created less than 10 minutes ago, WordPress |
|
295 |
* is in maintenance mode. |
|
296 |
* |
|
297 |
* @since 5.5.0 |
|
298 |
* |
|
299 |
* @global int $upgrading The Unix timestamp marking when upgrading WordPress began. |
|
300 |
* |
|
301 |
* @return bool True if maintenance mode is enabled, false otherwise. |
|
302 |
*/ |
|
303 |
function wp_is_maintenance_mode() { |
|
0 | 304 |
global $upgrading; |
305 |
||
16 | 306 |
if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) { |
307 |
return false; |
|
308 |
} |
|
309 |
||
310 |
require ABSPATH . '.maintenance'; |
|
311 |
// If the $upgrading timestamp is older than 10 minutes, consider maintenance over. |
|
312 |
if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) { |
|
313 |
return false; |
|
9 | 314 |
} |
0 | 315 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
* Filters whether to enable maintenance mode. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
* This filter runs before it can be used by plugins. It is designed for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
* non-web runtimes. If this filter returns true, maintenance mode will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* active and the request will end. If false, the request will be allowed to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* continue processing even if maintenance mode should be active. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* @param bool $enable_checks Whether to enable maintenance mode. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
* @param int $upgrading The timestamp set in the .maintenance file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) { |
16 | 330 |
return false; |
0 | 331 |
} |
332 |
||
16 | 333 |
return true; |
0 | 334 |
} |
335 |
||
336 |
/** |
|
18 | 337 |
* Get the time elapsed so far during this PHP script. |
338 |
* |
|
339 |
* Uses REQUEST_TIME_FLOAT that appeared in PHP 5.4.0. |
|
340 |
* |
|
341 |
* @since 5.8.0 |
|
342 |
* |
|
343 |
* @return float Seconds since the PHP script started. |
|
344 |
*/ |
|
345 |
function timer_float() { |
|
346 |
return microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT']; |
|
347 |
} |
|
348 |
||
349 |
/** |
|
5 | 350 |
* Start the WordPress micro-timer. |
0 | 351 |
* |
5 | 352 |
* @since 0.71 |
0 | 353 |
* @access private |
5 | 354 |
* |
355 |
* @global float $timestart Unix timestamp set at the beginning of the page load. |
|
356 |
* @see timer_stop() |
|
357 |
* |
|
0 | 358 |
* @return bool Always returns true. |
359 |
*/ |
|
360 |
function timer_start() { |
|
361 |
global $timestart; |
|
362 |
$timestart = microtime( true ); |
|
363 |
return true; |
|
364 |
} |
|
365 |
||
366 |
/** |
|
5 | 367 |
* Retrieve or display the time from the page start to when function is called. |
0 | 368 |
* |
369 |
* @since 0.71 |
|
5 | 370 |
* |
371 |
* @global float $timestart Seconds from when timer_start() is called. |
|
372 |
* @global float $timeend Seconds from when function is called. |
|
0 | 373 |
* |
5 | 374 |
* @param int|bool $display Whether to echo or return the results. Accepts 0|false for return, |
375 |
* 1|true for echo. Default 0|false. |
|
376 |
* @param int $precision The number of digits from the right of the decimal to display. |
|
377 |
* Default 3. |
|
378 |
* @return string The "second.microsecond" finished time calculation. The number is formatted |
|
379 |
* for human consumption, both localized and rounded. |
|
0 | 380 |
*/ |
5 | 381 |
function timer_stop( $display = 0, $precision = 3 ) { |
0 | 382 |
global $timestart, $timeend; |
9 | 383 |
$timeend = microtime( true ); |
0 | 384 |
$timetotal = $timeend - $timestart; |
9 | 385 |
$r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision ); |
386 |
if ( $display ) { |
|
0 | 387 |
echo $r; |
9 | 388 |
} |
0 | 389 |
return $r; |
390 |
} |
|
391 |
||
392 |
/** |
|
5 | 393 |
* Set PHP error reporting based on WordPress debug settings. |
394 |
* |
|
395 |
* Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
* All three can be defined in wp-config.php. By default, `WP_DEBUG` and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true. |
0 | 398 |
* |
5 | 399 |
* When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also |
400 |
* display internal notices: when a deprecated WordPress function, function |
|
401 |
* argument, or file is used. Deprecated code may be removed from a later |
|
402 |
* version. |
|
0 | 403 |
* |
5 | 404 |
* It is strongly recommended that plugin and theme developers use `WP_DEBUG` |
405 |
* in their development environments. |
|
0 | 406 |
* |
5 | 407 |
* `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG` |
408 |
* is true. |
|
0 | 409 |
* |
5 | 410 |
* When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed. |
411 |
* `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress |
|
412 |
* from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY` |
|
413 |
* as false will force errors to be hidden. |
|
0 | 414 |
* |
9 | 415 |
* When `WP_DEBUG_LOG` is true, errors will be logged to `wp-content/debug.log`. |
416 |
* When `WP_DEBUG_LOG` is a valid path, errors will be logged to the specified file. |
|
0 | 417 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
* Errors are never displayed for XML-RPC, REST, and Ajax requests. |
0 | 419 |
* |
5 | 420 |
* @since 3.0.0 |
9 | 421 |
* @since 5.1.0 `WP_DEBUG_LOG` can be a file path. |
0 | 422 |
* @access private |
423 |
*/ |
|
424 |
function wp_debug_mode() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* Filters whether to allow the debug mode check to occur. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* This filter runs before it can be used by plugins. It is designed for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
* non-web run-times. Returning false causes the `WP_DEBUG` and related |
16 | 430 |
* constants to not be checked and the default PHP values for errors |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
* will be used unless you take care to update them yourself. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* |
18 | 433 |
* To use this filter you must define a `$wp_filter` global before |
434 |
* WordPress loads, usually in `wp-config.php`. |
|
435 |
* |
|
436 |
* Example: |
|
437 |
* |
|
438 |
* $GLOBALS['wp_filter'] = array( |
|
439 |
* 'enable_wp_debug_mode_checks' => array( |
|
440 |
* 10 => array( |
|
441 |
* array( |
|
442 |
* 'accepted_args' => 0, |
|
443 |
* 'function' => function() { |
|
444 |
* return false; |
|
445 |
* }, |
|
446 |
* ), |
|
447 |
* ), |
|
448 |
* ), |
|
449 |
* ); |
|
450 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
* @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
*/ |
9 | 455 |
if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
|
0 | 459 |
if ( WP_DEBUG ) { |
460 |
error_reporting( E_ALL ); |
|
461 |
||
9 | 462 |
if ( WP_DEBUG_DISPLAY ) { |
0 | 463 |
ini_set( 'display_errors', 1 ); |
9 | 464 |
} elseif ( null !== WP_DEBUG_DISPLAY ) { |
0 | 465 |
ini_set( 'display_errors', 0 ); |
9 | 466 |
} |
0 | 467 |
|
9 | 468 |
if ( in_array( strtolower( (string) WP_DEBUG_LOG ), array( 'true', '1' ), true ) ) { |
469 |
$log_path = WP_CONTENT_DIR . '/debug.log'; |
|
470 |
} elseif ( is_string( WP_DEBUG_LOG ) ) { |
|
471 |
$log_path = WP_DEBUG_LOG; |
|
472 |
} else { |
|
473 |
$log_path = false; |
|
474 |
} |
|
475 |
||
476 |
if ( $log_path ) { |
|
0 | 477 |
ini_set( 'log_errors', 1 ); |
9 | 478 |
ini_set( 'error_log', $log_path ); |
0 | 479 |
} |
480 |
} else { |
|
481 |
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR ); |
|
482 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
|
9 | 484 |
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) { |
16 | 485 |
ini_set( 'display_errors', 0 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
} |
0 | 487 |
} |
488 |
||
489 |
/** |
|
5 | 490 |
* Set the location of the language directory. |
0 | 491 |
* |
5 | 492 |
* To set directory manually, define the `WP_LANG_DIR` constant |
493 |
* in wp-config.php. |
|
0 | 494 |
* |
5 | 495 |
* If the language directory exists within `WP_CONTENT_DIR`, it |
496 |
* is used. Otherwise the language directory is assumed to live |
|
497 |
* in `WPINC`. |
|
0 | 498 |
* |
5 | 499 |
* @since 3.0.0 |
0 | 500 |
* @access private |
501 |
*/ |
|
502 |
function wp_set_lang_dir() { |
|
9 | 503 |
if ( ! defined( 'WP_LANG_DIR' ) ) { |
504 |
if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || ! @is_dir( ABSPATH . WPINC . '/languages' ) ) { |
|
5 | 505 |
/** |
506 |
* Server path of the language directory. |
|
507 |
* |
|
508 |
* No leading slash, no trailing slash, full path, not relative to ABSPATH |
|
509 |
* |
|
510 |
* @since 2.1.0 |
|
511 |
*/ |
|
512 |
define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); |
|
9 | 513 |
if ( ! defined( 'LANGDIR' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
// Old static relative path maintained for limited backward compatibility - won't work in some cases. |
0 | 515 |
define( 'LANGDIR', 'wp-content/languages' ); |
516 |
} |
|
517 |
} else { |
|
5 | 518 |
/** |
519 |
* Server path of the language directory. |
|
520 |
* |
|
521 |
* No leading slash, no trailing slash, full path, not relative to `ABSPATH`. |
|
522 |
* |
|
523 |
* @since 2.1.0 |
|
524 |
*/ |
|
525 |
define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); |
|
9 | 526 |
if ( ! defined( 'LANGDIR' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
// Old relative path maintained for backward compatibility. |
0 | 528 |
define( 'LANGDIR', WPINC . '/languages' ); |
529 |
} |
|
530 |
} |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
/** |
|
5 | 535 |
* Load the database class file and instantiate the `$wpdb` global. |
0 | 536 |
* |
537 |
* @since 2.5.0 |
|
5 | 538 |
* |
16 | 539 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 540 |
*/ |
541 |
function require_wp_db() { |
|
542 |
global $wpdb; |
|
543 |
||
16 | 544 |
require_once ABSPATH . WPINC . '/wp-db.php'; |
9 | 545 |
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
16 | 546 |
require_once WP_CONTENT_DIR . '/db.php'; |
9 | 547 |
} |
0 | 548 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
if ( isset( $wpdb ) ) { |
0 | 550 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
} |
0 | 552 |
|
9 | 553 |
$dbuser = defined( 'DB_USER' ) ? DB_USER : ''; |
554 |
$dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : ''; |
|
555 |
$dbname = defined( 'DB_NAME' ) ? DB_NAME : ''; |
|
556 |
$dbhost = defined( 'DB_HOST' ) ? DB_HOST : ''; |
|
557 |
||
558 |
$wpdb = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost ); |
|
0 | 559 |
} |
560 |
||
561 |
/** |
|
5 | 562 |
* Set the database table prefix and the format specifiers for database |
563 |
* table columns. |
|
0 | 564 |
* |
5 | 565 |
* Columns not listed here default to `%s`. |
0 | 566 |
* |
5 | 567 |
* @since 3.0.0 |
568 |
* @access private |
|
0 | 569 |
* |
16 | 570 |
* @global wpdb $wpdb WordPress database abstraction object. |
5 | 571 |
* @global string $table_prefix The database table prefix. |
0 | 572 |
*/ |
573 |
function wp_set_wpdb_vars() { |
|
574 |
global $wpdb, $table_prefix; |
|
9 | 575 |
if ( ! empty( $wpdb->error ) ) { |
0 | 576 |
dead_db(); |
9 | 577 |
} |
0 | 578 |
|
9 | 579 |
$wpdb->field_types = array( |
580 |
'post_author' => '%d', |
|
581 |
'post_parent' => '%d', |
|
582 |
'menu_order' => '%d', |
|
583 |
'term_id' => '%d', |
|
584 |
'term_group' => '%d', |
|
585 |
'term_taxonomy_id' => '%d', |
|
586 |
'parent' => '%d', |
|
587 |
'count' => '%d', |
|
588 |
'object_id' => '%d', |
|
589 |
'term_order' => '%d', |
|
590 |
'ID' => '%d', |
|
591 |
'comment_ID' => '%d', |
|
592 |
'comment_post_ID' => '%d', |
|
593 |
'comment_parent' => '%d', |
|
594 |
'user_id' => '%d', |
|
595 |
'link_id' => '%d', |
|
596 |
'link_owner' => '%d', |
|
597 |
'link_rating' => '%d', |
|
598 |
'option_id' => '%d', |
|
599 |
'blog_id' => '%d', |
|
600 |
'meta_id' => '%d', |
|
601 |
'post_id' => '%d', |
|
602 |
'user_status' => '%d', |
|
603 |
'umeta_id' => '%d', |
|
604 |
'comment_karma' => '%d', |
|
605 |
'comment_count' => '%d', |
|
16 | 606 |
// Multisite: |
9 | 607 |
'active' => '%d', |
608 |
'cat_id' => '%d', |
|
609 |
'deleted' => '%d', |
|
610 |
'lang_id' => '%d', |
|
611 |
'mature' => '%d', |
|
612 |
'public' => '%d', |
|
613 |
'site_id' => '%d', |
|
614 |
'spam' => '%d', |
|
0 | 615 |
); |
616 |
||
617 |
$prefix = $wpdb->set_prefix( $table_prefix ); |
|
618 |
||
619 |
if ( is_wp_error( $prefix ) ) { |
|
620 |
wp_load_translations_early(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
wp_die( |
9 | 622 |
sprintf( |
16 | 623 |
/* translators: 1: $table_prefix, 2: wp-config.php */ |
624 |
__( '<strong>Error</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
'<code>$table_prefix</code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
'<code>wp-config.php</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
); |
0 | 629 |
} |
630 |
} |
|
631 |
||
632 |
/** |
|
5 | 633 |
* Toggle `$_wp_using_ext_object_cache` on and off without directly |
634 |
* touching global. |
|
0 | 635 |
* |
636 |
* @since 3.7.0 |
|
637 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* @global bool $_wp_using_ext_object_cache |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
* |
5 | 640 |
* @param bool $using Whether external object cache is being used. |
641 |
* @return bool The current 'using' setting. |
|
0 | 642 |
*/ |
643 |
function wp_using_ext_object_cache( $using = null ) { |
|
644 |
global $_wp_using_ext_object_cache; |
|
645 |
$current_using = $_wp_using_ext_object_cache; |
|
9 | 646 |
if ( null !== $using ) { |
0 | 647 |
$_wp_using_ext_object_cache = $using; |
9 | 648 |
} |
0 | 649 |
return $current_using; |
650 |
} |
|
651 |
||
652 |
/** |
|
5 | 653 |
* Start the WordPress object cache. |
0 | 654 |
* |
655 |
* If an object-cache.php file exists in the wp-content directory, |
|
656 |
* it uses that drop-in as an external object cache. |
|
657 |
* |
|
5 | 658 |
* @since 3.0.0 |
0 | 659 |
* @access private |
5 | 660 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
* @global array $wp_filter Stores all of the filters. |
0 | 662 |
*/ |
663 |
function wp_start_object_cache() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
global $wp_filter; |
9 | 665 |
static $first_init = true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
|
9 | 667 |
// Only perform the following checks once. |
18 | 668 |
|
669 |
/** |
|
670 |
* Filters whether to enable loading of the object-cache.php drop-in. |
|
671 |
* |
|
672 |
* This filter runs before it can be used by plugins. It is designed for non-web |
|
673 |
* run-times. If false is returned, object-cache.php will never be loaded. |
|
674 |
* |
|
675 |
* @since 5.8.0 |
|
676 |
* |
|
677 |
* @param bool $enable_object_cache Whether to enable loading object-cache.php (if present). |
|
678 |
* Default true. |
|
679 |
*/ |
|
680 |
if ( $first_init && apply_filters( 'enable_loading_object_cache_dropin', true ) ) { |
|
9 | 681 |
if ( ! function_exists( 'wp_cache_init' ) ) { |
682 |
/* |
|
683 |
* This is the normal situation. First-run of this function. No |
|
684 |
* caching backend has been loaded. |
|
685 |
* |
|
686 |
* We try to load a custom caching backend, and then, if it |
|
687 |
* results in a wp_cache_init() function existing, we note |
|
688 |
* that an external object cache is being used. |
|
689 |
*/ |
|
690 |
if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
|
16 | 691 |
require_once WP_CONTENT_DIR . '/object-cache.php'; |
9 | 692 |
if ( function_exists( 'wp_cache_init' ) ) { |
693 |
wp_using_ext_object_cache( true ); |
|
694 |
} |
|
0 | 695 |
|
16 | 696 |
// Re-initialize any hooks added manually by object-cache.php. |
9 | 697 |
if ( $wp_filter ) { |
698 |
$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); |
|
699 |
} |
|
700 |
} |
|
701 |
} elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
|
702 |
/* |
|
703 |
* Sometimes advanced-cache.php can load object-cache.php before |
|
704 |
* this function is run. This breaks the function_exists() check |
|
705 |
* above and can result in wp_using_ext_object_cache() returning |
|
706 |
* false when actually an external cache is in use. |
|
707 |
*/ |
|
708 |
wp_using_ext_object_cache( true ); |
|
709 |
} |
|
0 | 710 |
} |
711 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
if ( ! wp_using_ext_object_cache() ) { |
16 | 713 |
require_once ABSPATH . WPINC . '/cache.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
} |
0 | 715 |
|
16 | 716 |
require_once ABSPATH . WPINC . '/cache-compat.php'; |
717 |
||
5 | 718 |
/* |
719 |
* If cache supports reset, reset instead of init if already |
|
720 |
* initialized. Reset signals to the cache that global IDs |
|
721 |
* have changed and it may need to update keys and cleanup caches. |
|
722 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
wp_cache_switch_to_blog( get_current_blog_id() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
} elseif ( function_exists( 'wp_cache_init' ) ) { |
0 | 726 |
wp_cache_init(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
} |
0 | 728 |
|
729 |
if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
9 | 730 |
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
0 | 732 |
} |
9 | 733 |
|
734 |
$first_init = false; |
|
0 | 735 |
} |
736 |
||
737 |
/** |
|
5 | 738 |
* Redirect to the installer if WordPress is not installed. |
0 | 739 |
* |
5 | 740 |
* Dies with an error message when Multisite is enabled. |
0 | 741 |
* |
5 | 742 |
* @since 3.0.0 |
0 | 743 |
* @access private |
744 |
*/ |
|
745 |
function wp_not_installed() { |
|
746 |
if ( is_multisite() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
if ( ! is_blog_installed() && ! wp_installing() ) { |
5 | 748 |
nocache_headers(); |
749 |
||
0 | 750 |
wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); |
5 | 751 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
} elseif ( ! is_blog_installed() && ! wp_installing() ) { |
5 | 753 |
nocache_headers(); |
754 |
||
16 | 755 |
require ABSPATH . WPINC . '/kses.php'; |
756 |
require ABSPATH . WPINC . '/pluggable.php'; |
|
0 | 757 |
|
758 |
$link = wp_guess_url() . '/wp-admin/install.php'; |
|
759 |
||
760 |
wp_redirect( $link ); |
|
761 |
die(); |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
/** |
|
5 | 766 |
* Retrieve an array of must-use plugin files. |
0 | 767 |
* |
5 | 768 |
* The default directory is wp-content/mu-plugins. To change the default |
769 |
* directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL` |
|
0 | 770 |
* in wp-config.php. |
771 |
* |
|
5 | 772 |
* @since 3.0.0 |
0 | 773 |
* @access private |
5 | 774 |
* |
16 | 775 |
* @return string[] Array of absolute paths of files to include. |
0 | 776 |
*/ |
777 |
function wp_get_mu_plugins() { |
|
778 |
$mu_plugins = array(); |
|
9 | 779 |
if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { |
0 | 780 |
return $mu_plugins; |
9 | 781 |
} |
16 | 782 |
$dh = opendir( WPMU_PLUGIN_DIR ); |
783 |
if ( ! $dh ) { |
|
0 | 784 |
return $mu_plugins; |
9 | 785 |
} |
0 | 786 |
while ( ( $plugin = readdir( $dh ) ) !== false ) { |
16 | 787 |
if ( '.php' === substr( $plugin, -4 ) ) { |
0 | 788 |
$mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin; |
9 | 789 |
} |
0 | 790 |
} |
791 |
closedir( $dh ); |
|
792 |
sort( $mu_plugins ); |
|
793 |
||
794 |
return $mu_plugins; |
|
795 |
} |
|
796 |
||
797 |
/** |
|
5 | 798 |
* Retrieve an array of active and valid plugin files. |
0 | 799 |
* |
5 | 800 |
* While upgrading or installing WordPress, no plugins are returned. |
801 |
* |
|
9 | 802 |
* The default directory is `wp-content/plugins`. To change the default |
5 | 803 |
* directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` |
9 | 804 |
* in `wp-config.php`. |
0 | 805 |
* |
5 | 806 |
* @since 3.0.0 |
0 | 807 |
* @access private |
5 | 808 |
* |
16 | 809 |
* @return string[] Array of paths to plugin files relative to the plugins directory. |
0 | 810 |
*/ |
811 |
function wp_get_active_and_valid_plugins() { |
|
9 | 812 |
$plugins = array(); |
0 | 813 |
$active_plugins = (array) get_option( 'active_plugins', array() ); |
814 |
||
16 | 815 |
// Check for hacks file if the option is enabled. |
0 | 816 |
if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
_deprecated_file( 'my-hacks.php', '1.5.0' ); |
0 | 818 |
array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); |
819 |
} |
|
820 |
||
9 | 821 |
if ( empty( $active_plugins ) || wp_installing() ) { |
0 | 822 |
return $plugins; |
9 | 823 |
} |
0 | 824 |
|
825 |
$network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; |
|
826 |
||
827 |
foreach ( $active_plugins as $plugin ) { |
|
16 | 828 |
if ( ! validate_file( $plugin ) // $plugin must validate as file. |
829 |
&& '.php' === substr( $plugin, -4 ) // $plugin must end with '.php'. |
|
830 |
&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist. |
|
831 |
// Not already included as a network plugin. |
|
832 |
&& ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) ) |
|
9 | 833 |
) { |
834 |
$plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
835 |
} |
|
836 |
} |
|
837 |
||
838 |
/* |
|
839 |
* Remove plugins from the list of active plugins when we're on an endpoint |
|
840 |
* that should be protected against WSODs and the plugin is paused. |
|
841 |
*/ |
|
842 |
if ( wp_is_recovery_mode() ) { |
|
843 |
$plugins = wp_skip_paused_plugins( $plugins ); |
|
844 |
} |
|
845 |
||
846 |
return $plugins; |
|
847 |
} |
|
848 |
||
849 |
/** |
|
850 |
* Filters a given list of plugins, removing any paused plugins from it. |
|
851 |
* |
|
852 |
* @since 5.2.0 |
|
853 |
* |
|
16 | 854 |
* @param string[] $plugins Array of absolute plugin main file paths. |
855 |
* @return string[] Filtered array of plugins, without any paused plugins. |
|
9 | 856 |
*/ |
857 |
function wp_skip_paused_plugins( array $plugins ) { |
|
858 |
$paused_plugins = wp_paused_plugins()->get_all(); |
|
859 |
||
860 |
if ( empty( $paused_plugins ) ) { |
|
861 |
return $plugins; |
|
862 |
} |
|
863 |
||
864 |
foreach ( $plugins as $index => $plugin ) { |
|
865 |
list( $plugin ) = explode( '/', plugin_basename( $plugin ) ); |
|
866 |
||
867 |
if ( array_key_exists( $plugin, $paused_plugins ) ) { |
|
868 |
unset( $plugins[ $index ] ); |
|
869 |
||
870 |
// Store list of paused plugins for displaying an admin notice. |
|
871 |
$GLOBALS['_paused_plugins'][ $plugin ] = $paused_plugins[ $plugin ]; |
|
872 |
} |
|
873 |
} |
|
874 |
||
875 |
return $plugins; |
|
876 |
} |
|
877 |
||
878 |
/** |
|
879 |
* Retrieves an array of active and valid themes. |
|
880 |
* |
|
881 |
* While upgrading or installing WordPress, no themes are returned. |
|
882 |
* |
|
883 |
* @since 5.1.0 |
|
884 |
* @access private |
|
885 |
* |
|
16 | 886 |
* @return string[] Array of absolute paths to theme directories. |
9 | 887 |
*/ |
888 |
function wp_get_active_and_valid_themes() { |
|
889 |
global $pagenow; |
|
890 |
||
891 |
$themes = array(); |
|
892 |
||
893 |
if ( wp_installing() && 'wp-activate.php' !== $pagenow ) { |
|
894 |
return $themes; |
|
895 |
} |
|
896 |
||
897 |
if ( TEMPLATEPATH !== STYLESHEETPATH ) { |
|
898 |
$themes[] = STYLESHEETPATH; |
|
899 |
} |
|
900 |
||
901 |
$themes[] = TEMPLATEPATH; |
|
902 |
||
903 |
/* |
|
904 |
* Remove themes from the list of active themes when we're on an endpoint |
|
905 |
* that should be protected against WSODs and the theme is paused. |
|
906 |
*/ |
|
907 |
if ( wp_is_recovery_mode() ) { |
|
908 |
$themes = wp_skip_paused_themes( $themes ); |
|
909 |
||
910 |
// If no active and valid themes exist, skip loading themes. |
|
911 |
if ( empty( $themes ) ) { |
|
912 |
add_filter( 'wp_using_themes', '__return_false' ); |
|
913 |
} |
|
914 |
} |
|
915 |
||
916 |
return $themes; |
|
917 |
} |
|
918 |
||
919 |
/** |
|
920 |
* Filters a given list of themes, removing any paused themes from it. |
|
921 |
* |
|
922 |
* @since 5.2.0 |
|
923 |
* |
|
16 | 924 |
* @param string[] $themes Array of absolute theme directory paths. |
925 |
* @return string[] Filtered array of absolute paths to themes, without any paused themes. |
|
9 | 926 |
*/ |
927 |
function wp_skip_paused_themes( array $themes ) { |
|
928 |
$paused_themes = wp_paused_themes()->get_all(); |
|
929 |
||
930 |
if ( empty( $paused_themes ) ) { |
|
931 |
return $themes; |
|
0 | 932 |
} |
9 | 933 |
|
934 |
foreach ( $themes as $index => $theme ) { |
|
935 |
$theme = basename( $theme ); |
|
936 |
||
937 |
if ( array_key_exists( $theme, $paused_themes ) ) { |
|
938 |
unset( $themes[ $index ] ); |
|
939 |
||
940 |
// Store list of paused themes for displaying an admin notice. |
|
941 |
$GLOBALS['_paused_themes'][ $theme ] = $paused_themes[ $theme ]; |
|
942 |
} |
|
943 |
} |
|
944 |
||
945 |
return $themes; |
|
946 |
} |
|
947 |
||
948 |
/** |
|
949 |
* Is WordPress in Recovery Mode. |
|
950 |
* |
|
951 |
* In this mode, plugins or themes that cause WSODs will be paused. |
|
952 |
* |
|
953 |
* @since 5.2.0 |
|
954 |
* |
|
955 |
* @return bool |
|
956 |
*/ |
|
957 |
function wp_is_recovery_mode() { |
|
958 |
return wp_recovery_mode()->is_active(); |
|
959 |
} |
|
960 |
||
961 |
/** |
|
962 |
* Determines whether we are currently on an endpoint that should be protected against WSODs. |
|
963 |
* |
|
964 |
* @since 5.2.0 |
|
965 |
* |
|
18 | 966 |
* @global string $pagenow |
967 |
* |
|
9 | 968 |
* @return bool True if the current endpoint should be protected. |
969 |
*/ |
|
970 |
function is_protected_endpoint() { |
|
971 |
// Protect login pages. |
|
972 |
if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { |
|
973 |
return true; |
|
974 |
} |
|
975 |
||
976 |
// Protect the admin backend. |
|
977 |
if ( is_admin() && ! wp_doing_ajax() ) { |
|
978 |
return true; |
|
979 |
} |
|
980 |
||
16 | 981 |
// Protect Ajax actions that could help resolve a fatal error should be available. |
9 | 982 |
if ( is_protected_ajax_action() ) { |
983 |
return true; |
|
984 |
} |
|
985 |
||
986 |
/** |
|
987 |
* Filters whether the current request is against a protected endpoint. |
|
988 |
* |
|
989 |
* This filter is only fired when an endpoint is requested which is not already protected by |
|
990 |
* WordPress core. As such, it exclusively allows providing further protected endpoints in |
|
16 | 991 |
* addition to the admin backend, login pages and protected Ajax actions. |
9 | 992 |
* |
993 |
* @since 5.2.0 |
|
994 |
* |
|
16 | 995 |
* @param bool $is_protected_endpoint Whether the currently requested endpoint is protected. |
996 |
* Default false. |
|
9 | 997 |
*/ |
998 |
return (bool) apply_filters( 'is_protected_endpoint', false ); |
|
999 |
} |
|
1000 |
||
1001 |
/** |
|
16 | 1002 |
* Determines whether we are currently handling an Ajax action that should be protected against WSODs. |
9 | 1003 |
* |
1004 |
* @since 5.2.0 |
|
1005 |
* |
|
16 | 1006 |
* @return bool True if the current Ajax action should be protected. |
9 | 1007 |
*/ |
1008 |
function is_protected_ajax_action() { |
|
1009 |
if ( ! wp_doing_ajax() ) { |
|
1010 |
return false; |
|
1011 |
} |
|
1012 |
||
1013 |
if ( ! isset( $_REQUEST['action'] ) ) { |
|
1014 |
return false; |
|
1015 |
} |
|
1016 |
||
1017 |
$actions_to_protect = array( |
|
1018 |
'edit-theme-plugin-file', // Saving changes in the core code editor. |
|
1019 |
'heartbeat', // Keep the heart beating. |
|
1020 |
'install-plugin', // Installing a new plugin. |
|
1021 |
'install-theme', // Installing a new theme. |
|
1022 |
'search-plugins', // Searching in the list of plugins. |
|
1023 |
'search-install-plugins', // Searching for a plugin in the plugin install screen. |
|
1024 |
'update-plugin', // Update an existing plugin. |
|
1025 |
'update-theme', // Update an existing theme. |
|
1026 |
); |
|
1027 |
||
1028 |
/** |
|
16 | 1029 |
* Filters the array of protected Ajax actions. |
9 | 1030 |
* |
16 | 1031 |
* This filter is only fired when doing Ajax and the Ajax request has an 'action' property. |
9 | 1032 |
* |
1033 |
* @since 5.2.0 |
|
1034 |
* |
|
16 | 1035 |
* @param string[] $actions_to_protect Array of strings with Ajax actions to protect. |
9 | 1036 |
*/ |
1037 |
$actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect ); |
|
1038 |
||
1039 |
if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) { |
|
1040 |
return false; |
|
1041 |
} |
|
1042 |
||
1043 |
return true; |
|
0 | 1044 |
} |
1045 |
||
1046 |
/** |
|
5 | 1047 |
* Set internal encoding. |
0 | 1048 |
* |
5 | 1049 |
* In most cases the default internal encoding is latin1, which is |
1050 |
* of no use, since we want to use the `mb_` functions for `utf-8` strings. |
|
0 | 1051 |
* |
5 | 1052 |
* @since 3.0.0 |
0 | 1053 |
* @access private |
1054 |
*/ |
|
1055 |
function wp_set_internal_encoding() { |
|
1056 |
if ( function_exists( 'mb_internal_encoding' ) ) { |
|
1057 |
$charset = get_option( 'blog_charset' ); |
|
16 | 1058 |
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
9 | 1059 |
if ( ! $charset || ! @mb_internal_encoding( $charset ) ) { |
0 | 1060 |
mb_internal_encoding( 'UTF-8' ); |
9 | 1061 |
} |
0 | 1062 |
} |
1063 |
} |
|
1064 |
||
1065 |
/** |
|
5 | 1066 |
* Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`. |
0 | 1067 |
* |
5 | 1068 |
* Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`, |
1069 |
* `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly. |
|
0 | 1070 |
* |
5 | 1071 |
* @since 3.0.0 |
0 | 1072 |
* @access private |
1073 |
*/ |
|
1074 |
function wp_magic_quotes() { |
|
1075 |
// Escape with wpdb. |
|
9 | 1076 |
$_GET = add_magic_quotes( $_GET ); |
1077 |
$_POST = add_magic_quotes( $_POST ); |
|
0 | 1078 |
$_COOKIE = add_magic_quotes( $_COOKIE ); |
1079 |
$_SERVER = add_magic_quotes( $_SERVER ); |
|
1080 |
||
1081 |
// Force REQUEST to be GET + POST. |
|
1082 |
$_REQUEST = array_merge( $_GET, $_POST ); |
|
1083 |
} |
|
1084 |
||
1085 |
/** |
|
1086 |
* Runs just before PHP shuts down execution. |
|
1087 |
* |
|
5 | 1088 |
* @since 1.2.0 |
0 | 1089 |
* @access private |
1090 |
*/ |
|
1091 |
function shutdown_action_hook() { |
|
1092 |
/** |
|
1093 |
* Fires just before PHP shuts down execution. |
|
1094 |
* |
|
1095 |
* @since 1.2.0 |
|
1096 |
*/ |
|
1097 |
do_action( 'shutdown' ); |
|
5 | 1098 |
|
0 | 1099 |
wp_cache_close(); |
1100 |
} |
|
1101 |
||
1102 |
/** |
|
1103 |
* Copy an object. |
|
1104 |
* |
|
1105 |
* @since 2.7.0 |
|
5 | 1106 |
* @deprecated 3.2.0 |
0 | 1107 |
* |
5 | 1108 |
* @param object $object The object to clone. |
1109 |
* @return object The cloned object. |
|
0 | 1110 |
*/ |
1111 |
function wp_clone( $object ) { |
|
16 | 1112 |
// Use parens for clone to accommodate PHP 4. See #17880. |
0 | 1113 |
return clone( $object ); |
1114 |
} |
|
1115 |
||
1116 |
/** |
|
9 | 1117 |
* Determines whether the current request is for an administrative interface page. |
0 | 1118 |
* |
9 | 1119 |
* Does not check if the user is an administrator; use current_user_can() |
5 | 1120 |
* for checking roles and capabilities. |
0 | 1121 |
* |
9 | 1122 |
* For more information on this and similar theme functions, check out |
1123 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1124 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
1125 |
* |
|
0 | 1126 |
* @since 1.5.1 |
1127 |
* |
|
16 | 1128 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
* |
5 | 1130 |
* @return bool True if inside WordPress administration interface, false otherwise. |
0 | 1131 |
*/ |
1132 |
function is_admin() { |
|
9 | 1133 |
if ( isset( $GLOBALS['current_screen'] ) ) { |
0 | 1134 |
return $GLOBALS['current_screen']->in_admin(); |
9 | 1135 |
} elseif ( defined( 'WP_ADMIN' ) ) { |
0 | 1136 |
return WP_ADMIN; |
9 | 1137 |
} |
0 | 1138 |
|
1139 |
return false; |
|
1140 |
} |
|
1141 |
||
1142 |
/** |
|
16 | 1143 |
* Whether the current request is for a site's administrative interface. |
0 | 1144 |
* |
5 | 1145 |
* e.g. `/wp-admin/` |
1146 |
* |
|
9 | 1147 |
* Does not check if the user is an administrator; use current_user_can() |
5 | 1148 |
* for checking roles and capabilities. |
0 | 1149 |
* |
1150 |
* @since 3.1.0 |
|
1151 |
* |
|
16 | 1152 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
* |
5 | 1154 |
* @return bool True if inside WordPress blog administration pages. |
0 | 1155 |
*/ |
1156 |
function is_blog_admin() { |
|
9 | 1157 |
if ( isset( $GLOBALS['current_screen'] ) ) { |
0 | 1158 |
return $GLOBALS['current_screen']->in_admin( 'site' ); |
9 | 1159 |
} elseif ( defined( 'WP_BLOG_ADMIN' ) ) { |
0 | 1160 |
return WP_BLOG_ADMIN; |
9 | 1161 |
} |
0 | 1162 |
|
1163 |
return false; |
|
1164 |
} |
|
1165 |
||
1166 |
/** |
|
5 | 1167 |
* Whether the current request is for the network administrative interface. |
0 | 1168 |
* |
5 | 1169 |
* e.g. `/wp-admin/network/` |
1170 |
* |
|
9 | 1171 |
* Does not check if the user is an administrator; use current_user_can() |
5 | 1172 |
* for checking roles and capabilities. |
0 | 1173 |
* |
16 | 1174 |
* Does not check if the site is a Multisite network; use is_multisite() |
1175 |
* for checking if Multisite is enabled. |
|
1176 |
* |
|
0 | 1177 |
* @since 3.1.0 |
1178 |
* |
|
16 | 1179 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
* |
0 | 1181 |
* @return bool True if inside WordPress network administration pages. |
1182 |
*/ |
|
1183 |
function is_network_admin() { |
|
9 | 1184 |
if ( isset( $GLOBALS['current_screen'] ) ) { |
0 | 1185 |
return $GLOBALS['current_screen']->in_admin( 'network' ); |
9 | 1186 |
} elseif ( defined( 'WP_NETWORK_ADMIN' ) ) { |
0 | 1187 |
return WP_NETWORK_ADMIN; |
9 | 1188 |
} |
0 | 1189 |
|
1190 |
return false; |
|
1191 |
} |
|
1192 |
||
1193 |
/** |
|
5 | 1194 |
* Whether the current request is for a user admin screen. |
1195 |
* |
|
1196 |
* e.g. `/wp-admin/user/` |
|
0 | 1197 |
* |
9 | 1198 |
* Does not check if the user is an administrator; use current_user_can() |
1199 |
* for checking roles and capabilities. |
|
0 | 1200 |
* |
1201 |
* @since 3.1.0 |
|
1202 |
* |
|
16 | 1203 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
* |
0 | 1205 |
* @return bool True if inside WordPress user administration pages. |
1206 |
*/ |
|
1207 |
function is_user_admin() { |
|
9 | 1208 |
if ( isset( $GLOBALS['current_screen'] ) ) { |
0 | 1209 |
return $GLOBALS['current_screen']->in_admin( 'user' ); |
9 | 1210 |
} elseif ( defined( 'WP_USER_ADMIN' ) ) { |
0 | 1211 |
return WP_USER_ADMIN; |
9 | 1212 |
} |
0 | 1213 |
|
1214 |
return false; |
|
1215 |
} |
|
1216 |
||
1217 |
/** |
|
5 | 1218 |
* If Multisite is enabled. |
0 | 1219 |
* |
1220 |
* @since 3.0.0 |
|
1221 |
* |
|
5 | 1222 |
* @return bool True if Multisite is enabled, false otherwise. |
0 | 1223 |
*/ |
1224 |
function is_multisite() { |
|
9 | 1225 |
if ( defined( 'MULTISITE' ) ) { |
0 | 1226 |
return MULTISITE; |
9 | 1227 |
} |
0 | 1228 |
|
9 | 1229 |
if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) { |
0 | 1230 |
return true; |
9 | 1231 |
} |
0 | 1232 |
|
1233 |
return false; |
|
1234 |
} |
|
1235 |
||
1236 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
* Retrieve the current site ID. |
0 | 1238 |
* |
1239 |
* @since 3.1.0 |
|
1240 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
* @global int $blog_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
* @return int Site ID. |
0 | 1244 |
*/ |
1245 |
function get_current_blog_id() { |
|
1246 |
global $blog_id; |
|
9 | 1247 |
return absint( $blog_id ); |
0 | 1248 |
} |
1249 |
||
1250 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
* Retrieves the current network ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
* @return int The ID of the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
function get_current_network_id() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
return 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
$current_network = get_network(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
if ( ! isset( $current_network->id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1265 |
return get_main_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1267 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
return absint( $current_network->id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1270 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1271 |
/** |
5 | 1272 |
* Attempt an early load of translations. |
0 | 1273 |
* |
5 | 1274 |
* Used for errors encountered during the initial loading process, before |
1275 |
* the locale has been properly detected and loaded. |
|
0 | 1276 |
* |
5 | 1277 |
* Designed for unusual load sequences (like setup-config.php) or for when |
1278 |
* the script will then terminate with an error, otherwise there is a risk |
|
1279 |
* that a file can be double-included. |
|
0 | 1280 |
* |
1281 |
* @since 3.4.0 |
|
1282 |
* @access private |
|
5 | 1283 |
* |
16 | 1284 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
0 | 1285 |
*/ |
1286 |
function wp_load_translations_early() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
global $wp_locale; |
0 | 1288 |
|
1289 |
static $loaded = false; |
|
9 | 1290 |
if ( $loaded ) { |
0 | 1291 |
return; |
9 | 1292 |
} |
0 | 1293 |
$loaded = true; |
1294 |
||
9 | 1295 |
if ( function_exists( 'did_action' ) && did_action( 'init' ) ) { |
0 | 1296 |
return; |
9 | 1297 |
} |
0 | 1298 |
|
16 | 1299 |
// We need $wp_local_package. |
0 | 1300 |
require ABSPATH . WPINC . '/version.php'; |
1301 |
||
16 | 1302 |
// Translation and localization. |
0 | 1303 |
require_once ABSPATH . WPINC . '/pomo/mo.php'; |
1304 |
require_once ABSPATH . WPINC . '/l10n.php'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
require_once ABSPATH . WPINC . '/class-wp-locale.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; |
0 | 1307 |
|
16 | 1308 |
// General libraries. |
0 | 1309 |
require_once ABSPATH . WPINC . '/plugin.php'; |
1310 |
||
16 | 1311 |
$locales = array(); |
1312 |
$locations = array(); |
|
0 | 1313 |
|
1314 |
while ( true ) { |
|
1315 |
if ( defined( 'WPLANG' ) ) { |
|
16 | 1316 |
if ( '' === WPLANG ) { |
0 | 1317 |
break; |
9 | 1318 |
} |
0 | 1319 |
$locales[] = WPLANG; |
1320 |
} |
|
1321 |
||
9 | 1322 |
if ( isset( $wp_local_package ) ) { |
0 | 1323 |
$locales[] = $wp_local_package; |
9 | 1324 |
} |
0 | 1325 |
|
9 | 1326 |
if ( ! $locales ) { |
0 | 1327 |
break; |
9 | 1328 |
} |
0 | 1329 |
|
9 | 1330 |
if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) { |
0 | 1331 |
$locations[] = WP_LANG_DIR; |
9 | 1332 |
} |
0 | 1333 |
|
9 | 1334 |
if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) { |
0 | 1335 |
$locations[] = WP_CONTENT_DIR . '/languages'; |
9 | 1336 |
} |
0 | 1337 |
|
9 | 1338 |
if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) { |
0 | 1339 |
$locations[] = ABSPATH . 'wp-content/languages'; |
9 | 1340 |
} |
0 | 1341 |
|
9 | 1342 |
if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) { |
0 | 1343 |
$locations[] = ABSPATH . WPINC . '/languages'; |
9 | 1344 |
} |
0 | 1345 |
|
9 | 1346 |
if ( ! $locations ) { |
0 | 1347 |
break; |
9 | 1348 |
} |
0 | 1349 |
|
1350 |
$locations = array_unique( $locations ); |
|
1351 |
||
1352 |
foreach ( $locales as $locale ) { |
|
1353 |
foreach ( $locations as $location ) { |
|
1354 |
if ( file_exists( $location . '/' . $locale . '.mo' ) ) { |
|
1355 |
load_textdomain( 'default', $location . '/' . $locale . '.mo' ); |
|
9 | 1356 |
if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) { |
0 | 1357 |
load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' ); |
9 | 1358 |
} |
0 | 1359 |
break 2; |
1360 |
} |
|
1361 |
} |
|
1362 |
} |
|
1363 |
||
1364 |
break; |
|
1365 |
} |
|
1366 |
||
1367 |
$wp_locale = new WP_Locale(); |
|
1368 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
* Check or set whether WordPress is in "installation" mode. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
* If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
* @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
* Omit this parameter if you only want to fetch the current status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
* @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
* report whether WP was in installing mode prior to the change to `$is_installing`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
function wp_installing( $is_installing = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
static $installing = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
// Support for the `WP_INSTALLING` constant, defined before WP is loaded. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
if ( is_null( $installing ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
$installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
if ( ! is_null( $is_installing ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
$old_installing = $installing; |
9 | 1392 |
$installing = $is_installing; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1393 |
return (bool) $old_installing; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
return (bool) $installing; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
* Determines if SSL is used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
* @since 2.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
* @since 4.6.0 Moved from functions.php to load.php. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
* @return bool True if SSL, otherwise false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
function is_ssl() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
if ( isset( $_SERVER['HTTPS'] ) ) { |
16 | 1409 |
if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
if ( '1' == $_SERVER['HTTPS'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
} |
9 | 1416 |
} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
* Converts a shorthand byte value to an integer byte value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
* @since 2.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
* @since 4.6.0 Moved from media.php to load.php. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
* |
16 | 1428 |
* @link https://www.php.net/manual/en/function.ini-get.php |
1429 |
* @link https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1430 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
* @param string $value A (PHP ini) byte value, either shorthand or ordinary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
* @return int An integer byte value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
function wp_convert_hr_to_bytes( $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
$value = strtolower( trim( $value ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
$bytes = (int) $value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
if ( false !== strpos( $value, 'g' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1439 |
$bytes *= GB_IN_BYTES; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
} elseif ( false !== strpos( $value, 'm' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
$bytes *= MB_IN_BYTES; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
} elseif ( false !== strpos( $value, 'k' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
$bytes *= KB_IN_BYTES; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1444 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1445 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1446 |
// Deal with large (float) values which run into the maximum integer size. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1447 |
return min( $bytes, PHP_INT_MAX ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1448 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1451 |
* Determines whether a PHP ini value is changeable at runtime. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1452 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1453 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
* |
16 | 1455 |
* @link https://www.php.net/manual/en/function.ini-get-all.php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1457 |
* @param string $setting The name of the ini setting to check. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
* @return bool True if the value is changeable at runtime. False otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1460 |
function wp_is_ini_value_changeable( $setting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1461 |
static $ini_all; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1462 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1463 |
if ( ! isset( $ini_all ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
$ini_all = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
// Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes". |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1466 |
if ( function_exists( 'ini_get_all' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
$ini_all = ini_get_all(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
} |
9 | 1469 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
// Bit operator to workaround https://bugs.php.net/bug.php?id=44936 which changes access level to 63 in PHP 5.2.6 - 5.2.17. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1475 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
// If we were unable to retrieve the details, fail gracefully to assume it's changeable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
if ( ! is_array( $ini_all ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1482 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
* Determines whether the current request is a WordPress Ajax request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
* @return bool True if it's a WordPress Ajax request, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
function wp_doing_ajax() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
* Filters whether the current request is a WordPress Ajax request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1497 |
* @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1502 |
/** |
9 | 1503 |
* Determines whether the current request should use themes. |
1504 |
* |
|
1505 |
* @since 5.1.0 |
|
1506 |
* |
|
1507 |
* @return bool True if themes should be used, false otherwise. |
|
1508 |
*/ |
|
1509 |
function wp_using_themes() { |
|
1510 |
/** |
|
1511 |
* Filters whether the current request should use themes. |
|
1512 |
* |
|
1513 |
* @since 5.1.0 |
|
1514 |
* |
|
1515 |
* @param bool $wp_using_themes Whether the current request should use themes. |
|
1516 |
*/ |
|
1517 |
return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ); |
|
1518 |
} |
|
1519 |
||
1520 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1521 |
* Determines whether the current request is a WordPress cron request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1523 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1525 |
* @return bool True if it's a WordPress cron request, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
function wp_doing_cron() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1528 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1529 |
* Filters whether the current request is a WordPress cron request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1530 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1531 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1532 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1533 |
* @param bool $wp_doing_cron Whether the current request is a WordPress cron request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1537 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1538 |
/** |
18 | 1539 |
* Checks whether the given variable is a WordPress Error. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1540 |
* |
18 | 1541 |
* Returns whether `$thing` is an instance of the `WP_Error` class. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1542 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1543 |
* @since 2.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1544 |
* |
18 | 1545 |
* @param mixed $thing The variable to check. |
1546 |
* @return bool Whether the variable is an instance of WP_Error. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1547 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
function is_wp_error( $thing ) { |
18 | 1549 |
$is_wp_error = ( $thing instanceof WP_Error ); |
1550 |
||
1551 |
if ( $is_wp_error ) { |
|
1552 |
/** |
|
1553 |
* Fires when `is_wp_error()` is called and its parameter is an instance of `WP_Error`. |
|
1554 |
* |
|
1555 |
* @since 5.6.0 |
|
1556 |
* |
|
1557 |
* @param WP_Error $thing The error object passed to `is_wp_error()`. |
|
1558 |
*/ |
|
1559 |
do_action( 'is_wp_error_instance', $thing ); |
|
1560 |
} |
|
1561 |
||
1562 |
return $is_wp_error; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1564 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1565 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1566 |
* Determines whether file modifications are allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1567 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1570 |
* @param string $context The usage context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
* @return bool True if file modification is allowed, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1573 |
function wp_is_file_mod_allowed( $context ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
* Filters whether file modifications are allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1578 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
* @param bool $file_mod_allowed Whether file modifications are allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
* @param string $context The usage context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1584 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
* Start scraping edited file errors. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1587 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
function wp_start_scraping_edited_file_errors() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1592 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1593 |
} |
9 | 1594 |
$key = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
$nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1598 |
echo "###### wp_scraping_result_start:$key ######"; |
9 | 1599 |
echo wp_json_encode( |
1600 |
array( |
|
1601 |
'code' => 'scrape_nonce_failure', |
|
18 | 1602 |
'message' => __( 'Scrape key check failed. Please try again.' ), |
9 | 1603 |
) |
1604 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1605 |
echo "###### wp_scraping_result_end:$key ######"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1606 |
die(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1607 |
} |
9 | 1608 |
if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { |
1609 |
define( 'WP_SANDBOX_SCRAPING', true ); |
|
1610 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1611 |
register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1612 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1613 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1614 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1615 |
* Finalize scraping for edited file errors. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1616 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1617 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1618 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1619 |
* @param string $scrape_key Scrape key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1620 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1621 |
function wp_finalize_scraping_edited_file_errors( $scrape_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1622 |
$error = error_get_last(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1623 |
echo "\n###### wp_scraping_result_start:$scrape_key ######\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1624 |
if ( ! empty( $error ) && in_array( $error['type'], array( E_CORE_ERROR, E_COMPILE_ERROR, E_ERROR, E_PARSE, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1625 |
$error = str_replace( ABSPATH, '', $error ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1626 |
echo wp_json_encode( $error ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1627 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1628 |
echo wp_json_encode( true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1630 |
echo "\n###### wp_scraping_result_end:$scrape_key ######\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
} |
9 | 1632 |
|
1633 |
/** |
|
1634 |
* Checks whether current request is a JSON request, or is expecting a JSON response. |
|
1635 |
* |
|
1636 |
* @since 5.0.0 |
|
1637 |
* |
|
16 | 1638 |
* @return bool True if `Accepts` or `Content-Type` headers contain `application/json`. |
1639 |
* False otherwise. |
|
9 | 1640 |
*/ |
1641 |
function wp_is_json_request() { |
|
1642 |
||
18 | 1643 |
if ( isset( $_SERVER['HTTP_ACCEPT'] ) && wp_is_json_media_type( $_SERVER['HTTP_ACCEPT'] ) ) { |
9 | 1644 |
return true; |
1645 |
} |
|
1646 |
||
18 | 1647 |
if ( isset( $_SERVER['CONTENT_TYPE'] ) && wp_is_json_media_type( $_SERVER['CONTENT_TYPE'] ) ) { |
9 | 1648 |
return true; |
1649 |
} |
|
1650 |
||
1651 |
return false; |
|
1652 |
||
1653 |
} |
|
1654 |
||
1655 |
/** |
|
1656 |
* Checks whether current request is a JSONP request, or is expecting a JSONP response. |
|
1657 |
* |
|
1658 |
* @since 5.2.0 |
|
1659 |
* |
|
1660 |
* @return bool True if JSONP request, false otherwise. |
|
1661 |
*/ |
|
1662 |
function wp_is_jsonp_request() { |
|
1663 |
if ( ! isset( $_GET['_jsonp'] ) ) { |
|
1664 |
return false; |
|
1665 |
} |
|
1666 |
||
1667 |
if ( ! function_exists( 'wp_check_jsonp_callback' ) ) { |
|
1668 |
require_once ABSPATH . WPINC . '/functions.php'; |
|
1669 |
} |
|
1670 |
||
1671 |
$jsonp_callback = $_GET['_jsonp']; |
|
1672 |
if ( ! wp_check_jsonp_callback( $jsonp_callback ) ) { |
|
1673 |
return false; |
|
1674 |
} |
|
1675 |
||
1676 |
/** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */ |
|
1677 |
$jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true ); |
|
1678 |
||
1679 |
return $jsonp_enabled; |
|
1680 |
||
1681 |
} |
|
1682 |
||
1683 |
/** |
|
18 | 1684 |
* Checks whether a string is a valid JSON Media Type. |
1685 |
* |
|
1686 |
* @since 5.6.0 |
|
1687 |
* |
|
1688 |
* @param string $media_type A Media Type string to check. |
|
1689 |
* @return bool True if string is a valid JSON Media Type. |
|
1690 |
*/ |
|
1691 |
function wp_is_json_media_type( $media_type ) { |
|
1692 |
static $cache = array(); |
|
1693 |
||
1694 |
if ( ! isset( $cache[ $media_type ] ) ) { |
|
1695 |
$cache[ $media_type ] = (bool) preg_match( '/(^|\s|,)application\/([\w!#\$&-\^\.\+]+\+)?json(\+oembed)?($|\s|;|,)/i', $media_type ); |
|
1696 |
} |
|
1697 |
||
1698 |
return $cache[ $media_type ]; |
|
1699 |
} |
|
1700 |
||
1701 |
/** |
|
9 | 1702 |
* Checks whether current request is an XML request, or is expecting an XML response. |
1703 |
* |
|
1704 |
* @since 5.2.0 |
|
1705 |
* |
|
16 | 1706 |
* @return bool True if `Accepts` or `Content-Type` headers contain `text/xml` |
1707 |
* or one of the related MIME types. False otherwise. |
|
9 | 1708 |
*/ |
1709 |
function wp_is_xml_request() { |
|
1710 |
$accepted = array( |
|
1711 |
'text/xml', |
|
1712 |
'application/rss+xml', |
|
1713 |
'application/atom+xml', |
|
1714 |
'application/rdf+xml', |
|
1715 |
'text/xml+oembed', |
|
1716 |
'application/xml+oembed', |
|
1717 |
); |
|
1718 |
||
1719 |
if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) { |
|
1720 |
foreach ( $accepted as $type ) { |
|
1721 |
if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) { |
|
1722 |
return true; |
|
1723 |
} |
|
1724 |
} |
|
1725 |
} |
|
1726 |
||
1727 |
if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) { |
|
1728 |
return true; |
|
1729 |
} |
|
1730 |
||
1731 |
return false; |
|
1732 |
} |
|
18 | 1733 |
|
1734 |
/** |
|
1735 |
* Checks if this site is protected by HTTP Basic Auth. |
|
1736 |
* |
|
1737 |
* At the moment, this merely checks for the present of Basic Auth credentials. Therefore, calling |
|
1738 |
* this function with a context different from the current context may give inaccurate results. |
|
1739 |
* In a future release, this evaluation may be made more robust. |
|
1740 |
* |
|
1741 |
* Currently, this is only used by Application Passwords to prevent a conflict since it also utilizes |
|
1742 |
* Basic Auth. |
|
1743 |
* |
|
1744 |
* @since 5.6.1 |
|
1745 |
* |
|
1746 |
* @global string $pagenow The current page. |
|
1747 |
* |
|
1748 |
* @param string $context The context to check for protection. Accepts 'login', 'admin', and 'front'. |
|
1749 |
* Defaults to the current context. |
|
1750 |
* @return bool Whether the site is protected by Basic Auth. |
|
1751 |
*/ |
|
1752 |
function wp_is_site_protected_by_basic_auth( $context = '' ) { |
|
1753 |
global $pagenow; |
|
1754 |
||
1755 |
if ( ! $context ) { |
|
1756 |
if ( 'wp-login.php' === $pagenow ) { |
|
1757 |
$context = 'login'; |
|
1758 |
} elseif ( is_admin() ) { |
|
1759 |
$context = 'admin'; |
|
1760 |
} else { |
|
1761 |
$context = 'front'; |
|
1762 |
} |
|
1763 |
} |
|
1764 |
||
1765 |
$is_protected = ! empty( $_SERVER['PHP_AUTH_USER'] ) || ! empty( $_SERVER['PHP_AUTH_PW'] ); |
|
1766 |
||
1767 |
/** |
|
1768 |
* Filters whether a site is protected by HTTP Basic Auth. |
|
1769 |
* |
|
1770 |
* @since 5.6.1 |
|
1771 |
* |
|
1772 |
* @param bool $is_protected Whether the site is protected by Basic Auth. |
|
1773 |
* @param string $context The context to check for protection. One of 'login', 'admin', or 'front'. |
|
1774 |
*/ |
|
1775 |
return apply_filters( 'wp_is_site_protected_by_basic_auth', $is_protected, $context ); |
|
1776 |
} |