84 $PHP_SELF = $_SERVER['PHP_SELF']; |
84 $PHP_SELF = $_SERVER['PHP_SELF']; |
85 if ( empty( $PHP_SELF ) ) { |
85 if ( empty( $PHP_SELF ) ) { |
86 $_SERVER['PHP_SELF'] = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] ); |
86 $_SERVER['PHP_SELF'] = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] ); |
87 $PHP_SELF = $_SERVER['PHP_SELF']; |
87 $PHP_SELF = $_SERVER['PHP_SELF']; |
88 } |
88 } |
|
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; |
89 } |
130 } |
90 |
131 |
91 /** |
132 /** |
92 * Check for the required PHP version, and the MySQL extension or |
133 * Check for the required PHP version, and the MySQL extension or |
93 * a database drop-in. |
134 * a database drop-in. |
110 header( 'Content-Type: text/html; charset=utf-8' ); |
151 header( 'Content-Type: text/html; charset=utf-8' ); |
111 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 ); |
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 ); |
112 exit( 1 ); |
153 exit( 1 ); |
113 } |
154 } |
114 |
155 |
115 if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
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 ) { |
116 require_once ABSPATH . WPINC . '/functions.php'; |
161 require_once ABSPATH . WPINC . '/functions.php'; |
117 wp_load_translations_early(); |
162 wp_load_translations_early(); |
118 $args = array( |
163 $args = array( |
119 'exit' => false, |
164 'exit' => false, |
120 'code' => 'mysql_not_found', |
165 'code' => 'mysql_not_found', |
132 * Retrieves the current environment type. |
177 * Retrieves the current environment type. |
133 * |
178 * |
134 * The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable, |
179 * The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable, |
135 * or a constant of the same name. |
180 * or a constant of the same name. |
136 * |
181 * |
137 * Possible values include 'local', 'development', 'staging', 'production'. |
182 * Possible values are 'local', 'development', 'staging', and 'production'. |
138 * If not set, the type defaults to 'production'. |
183 * If not set, the type defaults to 'production'. |
139 * |
184 * |
140 * @since 5.5.0 |
185 * @since 5.5.0 |
141 * @since 5.5.1 Added the 'local' type. |
186 * @since 5.5.1 Added the 'local' type. |
142 * @since 5.5.1 Removed the ability to alter the list of types. |
187 * @since 5.5.1 Removed the ability to alter the list of types. |
369 * |
427 * |
370 * This filter runs before it can be used by plugins. It is designed for |
428 * This filter runs before it can be used by plugins. It is designed for |
371 * non-web run-times. Returning false causes the `WP_DEBUG` and related |
429 * non-web run-times. Returning false causes the `WP_DEBUG` and related |
372 * constants to not be checked and the default PHP values for errors |
430 * constants to not be checked and the default PHP values for errors |
373 * will be used unless you take care to update them yourself. |
431 * will be used unless you take care to update them yourself. |
|
432 * |
|
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 * ); |
374 * |
450 * |
375 * @since 4.6.0 |
451 * @since 4.6.0 |
376 * |
452 * |
377 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. |
453 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. |
378 */ |
454 */ |
587 function wp_start_object_cache() { |
663 function wp_start_object_cache() { |
588 global $wp_filter; |
664 global $wp_filter; |
589 static $first_init = true; |
665 static $first_init = true; |
590 |
666 |
591 // Only perform the following checks once. |
667 // Only perform the following checks once. |
592 if ( $first_init ) { |
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 ) ) { |
593 if ( ! function_exists( 'wp_cache_init' ) ) { |
681 if ( ! function_exists( 'wp_cache_init' ) ) { |
594 /* |
682 /* |
595 * This is the normal situation. First-run of this function. No |
683 * This is the normal situation. First-run of this function. No |
596 * caching backend has been loaded. |
684 * caching backend has been loaded. |
597 * |
685 * |
873 /** |
961 /** |
874 * Determines whether we are currently on an endpoint that should be protected against WSODs. |
962 * Determines whether we are currently on an endpoint that should be protected against WSODs. |
875 * |
963 * |
876 * @since 5.2.0 |
964 * @since 5.2.0 |
877 * |
965 * |
|
966 * @global string $pagenow |
|
967 * |
878 * @return bool True if the current endpoint should be protected. |
968 * @return bool True if the current endpoint should be protected. |
879 */ |
969 */ |
880 function is_protected_endpoint() { |
970 function is_protected_endpoint() { |
881 // Protect login pages. |
971 // Protect login pages. |
882 if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { |
972 if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { |
1444 */ |
1534 */ |
1445 return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); |
1535 return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); |
1446 } |
1536 } |
1447 |
1537 |
1448 /** |
1538 /** |
1449 * Check whether variable is a WordPress Error. |
1539 * Checks whether the given variable is a WordPress Error. |
1450 * |
1540 * |
1451 * Returns true if $thing is an object of the WP_Error class. |
1541 * Returns whether `$thing` is an instance of the `WP_Error` class. |
1452 * |
1542 * |
1453 * @since 2.1.0 |
1543 * @since 2.1.0 |
1454 * |
1544 * |
1455 * @param mixed $thing Check if unknown variable is a WP_Error object. |
1545 * @param mixed $thing The variable to check. |
1456 * @return bool True, if WP_Error. False, if not WP_Error. |
1546 * @return bool Whether the variable is an instance of WP_Error. |
1457 */ |
1547 */ |
1458 function is_wp_error( $thing ) { |
1548 function is_wp_error( $thing ) { |
1459 return ( $thing instanceof WP_Error ); |
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; |
1460 } |
1563 } |
1461 |
1564 |
1462 /** |
1565 /** |
1463 * Determines whether file modifications are allowed. |
1566 * Determines whether file modifications are allowed. |
1464 * |
1567 * |
1494 if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { |
1597 if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { |
1495 echo "###### wp_scraping_result_start:$key ######"; |
1598 echo "###### wp_scraping_result_start:$key ######"; |
1496 echo wp_json_encode( |
1599 echo wp_json_encode( |
1497 array( |
1600 array( |
1498 'code' => 'scrape_nonce_failure', |
1601 'code' => 'scrape_nonce_failure', |
1499 'message' => __( 'Scrape nonce check failed. Please try again.' ), |
1602 'message' => __( 'Scrape key check failed. Please try again.' ), |
1500 ) |
1603 ) |
1501 ); |
1604 ); |
1502 echo "###### wp_scraping_result_end:$key ######"; |
1605 echo "###### wp_scraping_result_end:$key ######"; |
1503 die(); |
1606 die(); |
1504 } |
1607 } |
1535 * @return bool True if `Accepts` or `Content-Type` headers contain `application/json`. |
1638 * @return bool True if `Accepts` or `Content-Type` headers contain `application/json`. |
1536 * False otherwise. |
1639 * False otherwise. |
1537 */ |
1640 */ |
1538 function wp_is_json_request() { |
1641 function wp_is_json_request() { |
1539 |
1642 |
1540 if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) { |
1643 if ( isset( $_SERVER['HTTP_ACCEPT'] ) && wp_is_json_media_type( $_SERVER['HTTP_ACCEPT'] ) ) { |
1541 return true; |
1644 return true; |
1542 } |
1645 } |
1543 |
1646 |
1544 if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) { |
1647 if ( isset( $_SERVER['CONTENT_TYPE'] ) && wp_is_json_media_type( $_SERVER['CONTENT_TYPE'] ) ) { |
1545 return true; |
1648 return true; |
1546 } |
1649 } |
1547 |
1650 |
1548 return false; |
1651 return false; |
1549 |
1652 |
1573 /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */ |
1676 /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */ |
1574 $jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true ); |
1677 $jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true ); |
1575 |
1678 |
1576 return $jsonp_enabled; |
1679 return $jsonp_enabled; |
1577 |
1680 |
|
1681 } |
|
1682 |
|
1683 /** |
|
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 ]; |
1578 } |
1699 } |
1579 |
1700 |
1580 /** |
1701 /** |
1581 * Checks whether current request is an XML request, or is expecting an XML response. |
1702 * Checks whether current request is an XML request, or is expecting an XML response. |
1582 * |
1703 * |
1607 return true; |
1728 return true; |
1608 } |
1729 } |
1609 |
1730 |
1610 return false; |
1731 return false; |
1611 } |
1732 } |
|
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 } |