WordPress.org

Make WordPress Core

Changeset 44671


Ignore:
Timestamp:
01/21/2019 07:09:23 PM (3 months ago)
Author:
flixos90
Message:

Bootstrap/Load: Ensure that the fatal error shutdown handler does not prevent other shutdown handlers from being called.

This changeset adds support for a new wp_die() argument exit, which defaults to true and determines whether wp_die() should actually terminate the request. The new fatal error handler then calls wp_die() with that argument set to false, as calling die() or exit from a PHP shutdown function prevents other shutdown functions from being called.

Props schlessera, johnbillion.
Fixes #46038. See #44458.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-shutdown-handler.php

    r44624 r44671  
    137137            if ( is_readable( $php_error_pluggable ) ) {
    138138                require_once $php_error_pluggable;
    139                 die();
     139                return;
    140140            }
    141141        }
     
    167167        $message = __( 'The site is experiencing technical difficulties.' );
    168168
    169         $args = array( 'response' => 500 );
     169        $args = array(
     170            'response' => 500,
     171            'exit'     => false,
     172        );
    170173        if ( function_exists( 'admin_url' ) ) {
    171174            $args['link_url']  = admin_url();
  • trunk/src/wp-includes/functions.php

    r44666 r44671  
    29582958 *     @type string $code           Error code to use. Default is 'wp_die', or the main error code if $message
    29592959 *                                  is a WP_Error.
     2960 *     @type bool   $exit           Whether to exit the process after completion. Default true.
    29602961 * }
    29612962 */
     
    32023203</html>
    32033204    <?php
    3204     die();
     3205    if ( $r['exit'] ) {
     3206        die();
     3207    }
    32053208}
    32063209
     
    32373240
    32383241    echo wp_json_encode( $data );
    3239     die();
     3242    if ( $r['exit'] ) {
     3243        die();
     3244    }
    32403245}
    32413246
     
    32633268        $wp_xmlrpc_server->output( $error->getXml() );
    32643269    }
    3265     die();
     3270    if ( $r['exit'] ) {
     3271        die();
     3272    }
    32663273}
    32673274
     
    32923299
    32933300    if ( is_scalar( $message ) ) {
    3294         die( (string) $message );
    3295     }
    3296     die( '0' );
     3301        $message = (string) $message;
     3302    } else {
     3303        $message = '0';
     3304    }
     3305
     3306    if ( $r['exit'] ) {
     3307        die( $message );
     3308    }
     3309
     3310    echo $message;
    32973311}
    32983312
     
    33033317 *
    33043318 * @since 3.4.0
     3319 * @since 5.1.0 Added the $title and $args parameters.
    33053320 * @access private
    33063321 *
    3307  * @param string $message Optional. Response to print. Default empty.
    3308  */
    3309 function _scalar_wp_die_handler( $message = '' ) {
     3322 * @param string       $message Optional. Response to print. Default empty.
     3323 * @param string       $title   Optional. Error title (unused). Default empty.
     3324 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
     3325 */
     3326function _scalar_wp_die_handler( $message = '', $title = '', $args = array() ) {
     3327    list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args );
     3328
     3329    if ( $r['exit'] ) {
     3330        if ( is_scalar( $message ) ) {
     3331            die( (string) $message );
     3332        }
     3333        die();
     3334    }
     3335
    33103336    if ( is_scalar( $message ) ) {
    3311         die( (string) $message );
    3312     }
    3313     die();
     3337        echo (string) $message;
     3338    }
    33143339}
    33153340
     
    33293354        'response'          => 0,
    33303355        'code'              => '',
     3356        'exit'              => true,
    33313357        'back_link'         => false,
    33323358        'link_url'          => '',
Note: See TracChangeset for help on using the changeset viewer.