Make WordPress Core

Ticket #46813: 46813.5.diff

File 46813.5.diff, 2.2 KB (added by tmdesigned, 6 years ago)

Original approach of directly checking for $wp_query, with unit tests

  • src/wp-includes/functions.php

     
    29722972 */
    29732973function wp_die( $message = '', $title = '', $args = array() ) {
    29742974
     2975        global $wp_query;
     2976
    29752977        if ( is_int( $args ) ) {
    29762978                $args = array( 'response' => $args );
    29772979        } elseif ( is_int( $title ) ) {
     
    30163018                 */
    30173019                $function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' );
    30183020        } elseif ( wp_is_xml_request()
    3019                 || function_exists( 'is_feed' ) && is_feed()
    3020                 || function_exists( 'is_comment_feed' ) && is_comment_feed()
    3021                 || function_exists( 'is_trackback' ) && is_trackback() ) {
     3021                || isset( $wp_query ) && function_exists( 'is_feed' ) && is_feed()
     3022                || isset( $wp_query ) && function_exists( 'is_comment_feed' ) && is_comment_feed()
     3023                || isset( $wp_query ) && function_exists( 'is_trackback' ) && is_trackback() ) {
    30223024                /**
    30233025                 * Filters the callback for killing WordPress execution for XML requests.
    30243026                 *
  • tests/phpunit/tests/includes/helpers.php

     
    378378        }
    379379
    380380        /**
     381         * This tests that _doing_it_wrong is suppressed in the wp_die() handler
     382         *
     383         * @ticket 46813
     384         */
     385        public function test_wp_die_has_doing_it_wrong_suppressed(){
     386                $expected = "Some Catastrophic Error";
     387
     388                //Unset query to trigger _doing_it_wrong later
     389                unset($GLOBALS['wp_query']);
     390
     391                try{
     392                        //remove any other errors
     393                        error_clear_last();
     394                        //trigger our own error, suppressing error handling
     395                        @trigger_error( $expected, E_USER_WARNING );
     396                        //run wp_die to test if _doing_it_wrong runs
     397                        wp_die();
     398                }catch (WPDieException $e){
     399                        //do nothing with exception regardless
     400                }
     401
     402                //test that no additional errors were reported after ours
     403                $last_error_reported = error_get_last();
     404                $this->assertSame( $last_error_reported['message'], $expected );
     405        }
     406       
     407        /**
    381408         * This test is just a setup for the one that follows.
    382409         *
    383410         * @ticket 38196