Ticket #45933: 45933.3.diff
| File 45933.3.diff, 7.2 KB (added by , 7 years ago) |
|---|
-
src/wp-content/plugins/hello.php
80 80 } 81 81 82 82 add_action( 'admin_head', 'dolly_css' ); 83 84 -
src/wp-includes/class-wp-shutdown-handler.php
122 122 } 123 123 124 124 // Otherwise, fail with a `wp_die()` message. 125 $message = $this->get_error_message_markup(); 125 $message = $this->get_error_message(); 126 $status = 500; 127 $args = array(); 126 128 127 // `wp_die()` wraps the message in paragraph tags, so let's just try working around that.128 if ( substr( $message, 0, 3 ) === '<p>' && substr( $message, -4 ) === '</p>' ) {129 $ message = substr( $message, 3, -4);129 if ( function_exists( 'admin_url' ) ) { 130 $args['back_link'] = admin_url(); 131 $args['back_text'] = __( 'Log into the admin backend to fix this.' ); 130 132 } 131 133 132 wp_die( $message, '', 500 ); 134 if ( class_exists( 'WP_Error', false ) ) { 135 $error_code = 'php_fatal_error'; 136 $message = new WP_Error( $error_code, $message, array_merge( $args, array( 'status' => $status ) ) ); 137 } 138 // Add response 139 $args['response'] = $status; 140 141 wp_die( $message, '', $args ); 133 142 } 134 143 135 144 /** … … 139 148 * 140 149 * @return string Error message HTML output. 141 150 */ 142 protected function get_error_message _markup() {151 protected function get_error_message() { 143 152 if ( ! function_exists( '__' ) ) { 144 153 function __( $text ) { 145 154 return $text; … … 146 155 } 147 156 } 148 157 149 $message = sprintf( 150 '<p>%s</p>', 151 __( 'The site is experiencing technical difficulties.' ) 152 ); 158 $message = __( 'The site is experiencing technical difficulties.' ); 153 159 154 if ( function_exists( 'admin_url' ) ) {155 $message .= sprintf(156 '<hr><p><em>%s <a href="%s">%s</a></em></p>',157 __( 'Are you the site owner?' ),158 admin_url(),159 __( 'Log into the admin backend to fix this.' )160 );161 }162 160 163 161 if ( function_exists( 'apply_filters' ) ) { 164 162 /** -
src/wp-includes/functions.php
2970 2970 * @param callable $function Callback function name. 2971 2971 */ 2972 2972 $function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); 2973 } else if ( wp_is_json_request() ) { 2974 /** 2975 * Filters the callback for killing WordPress execution for JSON requests. 2976 * 2977 * @since 5.1.0 2978 * 2979 * @param callable $function Callback function name. 2980 */ 2981 $function = apply_filters( 'wp_die_json_handler', '_json_wp_die_handler' ); 2973 2982 } elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) { 2974 2983 /** 2975 2984 * Filters the callback for killing WordPress execution for XML-RPC requests. … … 3007 3016 * @param string|array $args Optional. Arguments to control behavior. Default empty array. 3008 3017 */ 3009 3018 function _default_wp_die_handler( $message, $title = '', $args = array() ) { 3010 $defaults = array( 'response' => 500 );3011 $r = wp_parse_args( $args, $defaults );3012 3019 3013 3020 $have_gettext = function_exists( '__' ); 3021 $back_text = $have_gettext ? __( '« Back' ) : '« Back'; 3022 $defaults = array( 'response' => 500, 'back_text' => $back_text ); 3023 $r = wp_parse_args( $args, $defaults ); 3014 3024 3015 3025 if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { 3016 3026 if ( empty( $title ) ) { … … 3036 3046 } 3037 3047 3038 3048 if ( isset( $r['back_link'] ) && $r['back_link'] ) { 3039 $back_ text = $have_gettext ? __( '« Back' ) : '« Back';3040 $message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>";3049 $back_link = ( is_bool( $r['back_link'] ) ) ? "javascript:history.back()" : $r['back_link']; 3050 $message .= "\n<p><a href='" . $back_link . "'>" . $r['back_text'] . "</a></p>"; 3041 3051 } 3042 3052 3043 3053 if ( ! did_action( 'admin_head' ) ) : … … 3229 3239 } 3230 3240 3231 3241 /** 3242 * Kill WordPress execution and display JSON message with error message. 3243 * 3244 * This is the handler for wp_die when processing JSON requests. 3245 * 3246 * @since 5.1.0 3247 * @access private 3248 * 3249 * @param string $message Error message. 3250 * @param string $title Optional. Error title. Default empty. 3251 * @param string|array $args Optional. Arguments to control behavior. Default empty array. 3252 */ 3253 3254 function _json_wp_die_handler( $message, $title = '', $args = array() ) { 3255 $defaults = array( 'response' => 500, 'code' => '_json_wp_die_handler' ); 3256 $r = wp_parse_args( $args, $defaults ); 3257 3258 $data = array(); 3259 if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { 3260 $errors = array(); 3261 foreach ( (array) $message->errors as $code => $messages ) { 3262 foreach ( (array) $messages as $display_message ) { 3263 $errors[] = array( 3264 'code' => $code, 3265 'message' => $display_message, 3266 'data' => $message->get_error_data( $code ), 3267 ); 3268 } 3269 } 3270 3271 $data = $errors[0]; 3272 if ( count( $errors ) > 1 ) { 3273 // Remove the primary error. 3274 array_shift( $errors ); 3275 $data['additional_errors'] = $errors; 3276 } 3277 } else { 3278 $data = array( 3279 'code' => $r['code'], 3280 'message' => $message, 3281 ); 3282 } 3283 3284 if ( ! isset( $data['data']['status'] ) ) { 3285 $data['data']['status'] = $r['response']; 3286 } 3287 3288 if ( isset( $_GET['_jsonp'] ) ) { 3289 $jsonp_callback = $_GET['_jsonp']; 3290 $content_type = 'application/javascript'; 3291 } else { 3292 $jsonp_callback = false; 3293 $content_type = 'application/json'; 3294 } 3295 3296 if ( ! headers_sent() ) { 3297 $blog_charset = 'utf-8'; // Default charset. 3298 header( 'Content-Type: ' . $content_type . '; charset=' . $blog_charset ); 3299 status_header( $data['data']['status'] ); 3300 nocache_headers(); 3301 } 3302 3303 $result = wp_json_encode( $data ); 3304 if ( $jsonp_callback ) { 3305 echo '/**/' . $jsonp_callback . '(' . $result . ')'; 3306 } else { 3307 echo $result; 3308 } 3309 die(); 3310 } 3311 3312 /** 3232 3313 * Kill WordPress ajax execution. 3233 3314 * 3234 3315 * This is the handler for wp_die when processing Ajax requests. -
src/wp-includes/load.php
1473 1473 * 1474 1474 * @since 5.0.0 1475 1475 * 1476 * @return bool True if Accepts or Content-Type headers contain application/json , false otherwise.1476 * @return bool True if Accepts or Content-Type headers contain application/json or 'application/javascript', false otherwise. 1477 1477 */ 1478 1478 function wp_is_json_request() { 1479 1479 1480 if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) { 1481 return true; 1480 $accepted = array( 'application/json', 'application/javascript' ); 1481 1482 if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) { 1483 foreach ( $accepted as $type ) { 1484 if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) { 1485 return true; 1486 } 1487 } 1482 1488 } 1483 1489 1484 if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE']) {1490 if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) { 1485 1491 return true; 1486 1492 } 1487 1493