[beta tester] Simulate core error early in the request lifecycle before WP fully loaded. (#51330)
* Improve remote logging tool to simulate core error early in the request lifecycle before wp fully loaded * Disable wp error handler when simulate_woocommerce_error
This commit is contained in:
parent
2fc6528c61
commit
dfd7d52d6b
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: enhancement
|
||||||
|
|
||||||
|
Improve remote logging tool to simulate core error early in the request lifecycle before wp fully loaded
|
|
@ -143,10 +143,30 @@ add_action(
|
||||||
/**
|
/**
|
||||||
* Simulate a WooCommerce error for remote logging testing.
|
* Simulate a WooCommerce error for remote logging testing.
|
||||||
*
|
*
|
||||||
* @throws Exception A simulated WooCommerce error if the option is set.
|
* This function adds a filter to the 'woocommerce_template_path' hook
|
||||||
|
* that throws an exception, then triggers the filter by calling WC()->template_path().
|
||||||
|
*
|
||||||
|
* @throws Exception A simulated WooCommerce error for testing purposes.
|
||||||
*/
|
*/
|
||||||
function simulate_woocommerce_error() {
|
function simulate_woocommerce_error() {
|
||||||
throw new Exception( 'Simulated WooCommerce error for remote logging test' );
|
// Return if WooCommerce is not loaded.
|
||||||
|
if ( ! function_exists( 'WC' ) || ! class_exists( 'WooCommerce' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define a constant to prevent the error from being caught by the WP Error Handler.
|
||||||
|
if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
|
||||||
|
define( 'WP_SANDBOX_SCRAPING', true );
|
||||||
|
}
|
||||||
|
|
||||||
|
add_filter(
|
||||||
|
'woocommerce_template_path',
|
||||||
|
function() {
|
||||||
|
throw new Exception( 'Simulated WooCommerce error for remote logging test' );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
WC()->template_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
$simulate_error = get_option( 'wc_beta_tester_simulate_woocommerce_php_error', false );
|
$simulate_error = get_option( 'wc_beta_tester_simulate_woocommerce_php_error', false );
|
||||||
|
@ -155,7 +175,8 @@ if ( $simulate_error ) {
|
||||||
delete_option( 'wc_beta_tester_simulate_woocommerce_php_error' );
|
delete_option( 'wc_beta_tester_simulate_woocommerce_php_error' );
|
||||||
|
|
||||||
if ( 'core' === $simulate_error ) {
|
if ( 'core' === $simulate_error ) {
|
||||||
add_action( 'woocommerce_loaded', 'simulate_woocommerce_error' );
|
// Hook into the plugin_loaded action to simulate the error early before WP fully initializes.
|
||||||
|
add_action( 'plugin_loaded', 'simulate_woocommerce_error' );
|
||||||
} elseif ( 'beta-tester' === $simulate_error ) {
|
} elseif ( 'beta-tester' === $simulate_error ) {
|
||||||
throw new Exception( 'Test PHP exception from WooCommerce Beta Tester' );
|
throw new Exception( 'Test PHP exception from WooCommerce Beta Tester' );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue