From 6d58109b09d3c3c1eb7e22509c0056df0b4cf36d Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 5 Apr 2019 15:20:55 +0000 Subject: [PATCH] Bootstrap/Load: Ensure `WP_Fatal_Error_Handler` does not conflict with existing mechanisms treating fatal errors. Prior to this change, resuming or activating a plugin or theme that is still broken would result in a redirect loop if in recovery mode. If outside recovery mode, it would cause the error template to be displayed. Furthermore this applies to breaking a plugin or theme when editing from the backend. Props aandrewdixon, azaozz, dhanukanuwan, henrywright, ocean90, ohiosierra, PandelisZ, xkon. Fixes #46045, #46751. Built from https://develop.svn.wordpress.org/trunk@45114 git-svn-id: http://core.svn.wordpress.org/trunk@44923 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/plugin.php | 3 +++ wp-admin/includes/theme.php | 1 + wp-includes/class-wp-fatal-error-handler.php | 4 ++++ wp-includes/load.php | 1 + wp-includes/version.php | 2 +- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 54c6db27ac..2716bd4fef 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -631,9 +631,11 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen if ( ! empty( $redirect ) ) { wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) ); // we'll override this later if the plugin can be included without fatal error } + ob_start(); wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); $_wp_plugin_file = $plugin; + define( 'WP_SANDBOX_SCRAPING', true ); include_once( WP_PLUGIN_DIR . '/' . $plugin ); $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin. @@ -2125,6 +2127,7 @@ function wp_clean_plugins_cache( $clear_update_cache = true ) { * @param string $plugin Path to the plugin file relative to the plugins directory. */ function plugin_sandbox_scrape( $plugin ) { + define( 'WP_SANDBOX_SCRAPING', true ); wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); include( WP_PLUGIN_DIR . '/' . $plugin ); } diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php index 1ab7959e5f..98391123aa 100644 --- a/wp-admin/includes/theme.php +++ b/wp-admin/includes/theme.php @@ -859,6 +859,7 @@ function resume_theme( $theme, $redirect = '' ) { // Load the theme's functions.php to test whether it throws a fatal error. ob_start(); + define( 'WP_SANDBOX_SCRAPING', true ); include $functions_path; ob_clean(); } diff --git a/wp-includes/class-wp-fatal-error-handler.php b/wp-includes/class-wp-fatal-error-handler.php index 8ec87c9e24..270bb9e444 100644 --- a/wp-includes/class-wp-fatal-error-handler.php +++ b/wp-includes/class-wp-fatal-error-handler.php @@ -26,6 +26,10 @@ class WP_Fatal_Error_Handler { * @since 5.2.0 */ public function handle() { + if ( defined( 'WP_SANDBOX_SCRAPING' ) && WP_SANDBOX_SCRAPING ) { + return; + } + try { // Bail if no error found. $error = $this->detect_error(); diff --git a/wp-includes/load.php b/wp-includes/load.php index f2c9318da6..1915fbde17 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -1444,6 +1444,7 @@ function wp_start_scraping_edited_file_errors() { echo "###### wp_scraping_result_end:$key ######"; die(); } + define( 'WP_SANDBOX_SCRAPING', true ); register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 95e6b9fba4..306d56ff32 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.2-beta1-45113'; +$wp_version = '5.2-beta1-45114'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.