Ticket #45933: 45933.4.diff
| File 45933.4.diff, 7.9 KB (added by , 7 years ago) |
|---|
-
src/wp-includes/class-wp-shutdown-handler.php
122 122 * Displays the PHP error template and sends the HTTP status code, typically 500. 123 123 * 124 124 * A drop-in 'php-error.php' can be used as a custom template. This drop-in should control the HTTP status code and 125 * print the HTML markup indicating that a PHP error occurred. Alternatively, {@see wp_die()} can be used. Note126 * that this drop-in may potentially be executed very early in the WordPress bootstrap process, so any core127 * functions used that are not part of`wp-includes/load.php` should be checked for before being called.125 * print the HTML markup indicating that a PHP error occurred. Note that this drop-in may potentially be executed 126 * very early in the WordPress bootstrap process, so any core functions used that are not part of 127 * `wp-includes/load.php` should be checked for before being called. 128 128 * 129 * The default template also displays a link to the admin in order to fix the problem, however doing so is not 130 * mandatory. 129 * If no such drop-in is available, this will call {@see WP_Shutdown_Handler::display_default_error_template()}. 131 130 * 132 131 * @since 5.1.0 133 132 */ … … 141 140 } 142 141 } 143 142 144 // Otherwise, fail with a `wp_die()` message. 145 $message = $this->get_error_message_markup(); 146 147 // `wp_die()` wraps the message in paragraph tags, so let's just try working around that. 148 if ( substr( $message, 0, 3 ) === '<p>' && substr( $message, -4 ) === '</p>' ) { 149 $message = substr( $message, 3, -4 ); 150 } 151 152 wp_die( $message, '', 500 ); 143 // Otherwise, display the default error template. 144 $this->display_default_error_template(); 153 145 } 154 146 155 147 /** 156 * Returns the error message markup to display in the defaulterror template.148 * Displays the default PHP error template. 157 149 * 150 * This method is called conditionally if no 'php-error.php' drop-in is available. 151 * 152 * It calls {@see wp_die()} with a message indicating that the site is experiencing technical difficulties and a 153 * login link to the admin backend. The {@see 'wp_php_error_message'} and {@see 'wp_php_error_args'} filters can 154 * be used to modify these parameters. 155 * 158 156 * @since 5.1.0 159 *160 * @return string Error message HTML output.161 157 */ 162 protected function get_error_message_markup() {158 protected function display_default_error_template() { 163 159 if ( ! function_exists( '__' ) ) { 164 160 wp_load_translations_early(); 165 161 } 166 162 167 $message = sprintf( 168 '<p>%s</p>', 169 __( 'The site is experiencing technical difficulties.' ) 170 ); 163 if ( ! function_exists( 'wp_die' ) ) { 164 require_once ABSPATH . WPINC . '/functions.php'; 165 } 171 166 167 $message = __( 'The site is experiencing technical difficulties.' ); 168 169 $args = array( 'response' => 500 ); 172 170 if ( function_exists( 'admin_url' ) ) { 173 $message .= sprintf( 174 '<hr><p><em>%s <a href="%s">%s</a></em></p>', 175 __( 'Are you the site owner?' ), 176 admin_url(), 177 __( 'Log into the admin backend to fix this.' ) 178 ); 171 $args['link_url'] = admin_url(); 172 $args['link_text'] = __( 'Log into the admin backend to fix this.' ); 179 173 } 180 174 181 if ( function_exists( 'apply_filters' ) ) { 182 /** 183 * Filters the message that the default PHP error page displays. 184 * 185 * @since 5.1.0 186 * 187 * @param string $message HTML error message to display. 188 */ 189 $message = apply_filters( 'wp_technical_issues_display', $message ); 190 } 175 /** 176 * Filters the message that the default PHP error template displays. 177 * 178 * @since 5.1.0 179 * 180 * @param string $message HTML error message to display. 181 */ 182 $message = apply_filters( 'wp_php_error_message', $message ); 191 183 192 return $message; 184 /** 185 * Filters the arguments passed to {@see wp_die()} for the default PHP error template. 186 * 187 * @since 5.1.0 188 * 189 * @param array $args Associative array of arguments passed to `wp_die()`. By default these contain a 190 * 'response' key, and optionally 'link_url' and 'link_text' keys. 191 */ 192 $args = apply_filters( 'wp_php_error_args', $args ); 193 194 wp_die( $message, '', $args ); 193 195 } 194 196 } -
src/wp-includes/functions.php
2933 2933 * @since 2.0.4 2934 2934 * @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept 2935 2935 * an integer to be used as the response code. 2936 * @since 5.1.0 The `$link_url` and `$link_text` arguments were added. 2936 2937 * 2937 2938 * @param string|WP_Error $message Optional. Error message. If this is a WP_Error object, 2938 2939 * and not an Ajax or XML-RPC request, the error's messages are used. … … 2946 2947 * as the response code. Default empty array. 2947 2948 * 2948 2949 * @type int $response The HTTP response code. Default 200 for Ajax requests, 500 otherwise. 2950 * @type string $link_url A URL to include a link to. Only works in combination with $link_text. 2951 * Default empty string. 2952 * @type string $link_text A label for the link to include. Only works in combination with $link_url. 2953 * Default empty string. 2949 2954 * @type bool $back_link Whether to include a link to go back. Default false. 2950 2955 * @type string $text_direction The text direction. This is only useful internally, when WordPress 2951 2956 * is still loading and the site's locale is not set up yet. Accepts 'rtl'. … … 2970 2975 * @param callable $function Callback function name. 2971 2976 */ 2972 2977 $function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); 2978 } elseif ( wp_is_json_request() ) { 2979 /** 2980 * Filters the callback for killing WordPress execution for JSON requests. 2981 * 2982 * @since 5.1.0 2983 * 2984 * @param callable $function Callback function name. 2985 */ 2986 $function = apply_filters( 'wp_die_json_handler', '_json_wp_die_handler' ); 2973 2987 } elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) { 2974 2988 /** 2975 2989 * Filters the callback for killing WordPress execution for XML-RPC requests. … … 3035 3049 $message = "<p>$message</p>"; 3036 3050 } 3037 3051 3052 if ( ! empty( $r['link_url'] ) && ! empty( $r['link_text'] ) ) { 3053 $link_url = $r['link_url']; 3054 if ( function_exists( 'esc_url' ) ) { 3055 $link_url = esc_url( $link_url ); 3056 } 3057 $link_text = $r['link_text']; 3058 $message .= "\n<p><a href='{$link_url}'>{$link_text}</a></p>"; 3059 } 3060 3038 3061 if ( isset( $r['back_link'] ) && $r['back_link'] ) { 3039 3062 $back_text = $have_gettext ? __( '« Back' ) : '« Back'; 3040 3063 $message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>"; … … 3202 3225 } 3203 3226 3204 3227 /** 3228 * Kill WordPress execution and display JSON message with error message. 3229 * 3230 * This is the handler for wp_die when processing JSON requests. 3231 * 3232 * @since 5.1.0 3233 * @access private 3234 * 3235 * @param string $message Error message. 3236 * @param string $title Optional. Error title. Default empty. 3237 * @param string|array $args Optional. Arguments to control behavior. Default empty array. 3238 */ 3239 function _json_wp_die_handler( $message, $title = '', $args = array() ) { 3240 $defaults = array( 'response' => 500 ); 3241 3242 $r = wp_parse_args( $args, $defaults ); 3243 3244 $data = array( 3245 'code' => 'wp_die', 3246 'message' => $message, 3247 'status' => $r['response'], 3248 ); 3249 3250 if ( ! headers_sent() ) { 3251 header( 'Content-Type: application/json; charset=utf-8' ); 3252 if ( null !== $r['response'] ) { 3253 status_header( $r['response'] ); 3254 } 3255 } 3256 3257 echo wp_json_encode( $data ); 3258 die(); 3259 } 3260 3261 /** 3205 3262 * Kill WordPress execution and display XML message with error message. 3206 3263 * 3207 3264 * This is the handler for wp_die when processing XMLRPC requests.