From 1ea2fd2a92c31c7efa4b91ac781376493b0b5da0 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 25 Aug 2016 07:19:16 -0700 Subject: [PATCH] Better place to put the Exception handling --- inc/class-profile-command.php | 79 +++++++++++++++++------------------ 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/inc/class-profile-command.php b/inc/class-profile-command.php index d8df4e5..0a1f8a7 100644 --- a/inc/class-profile-command.php +++ b/inc/class-profile-command.php @@ -105,7 +105,11 @@ class Profile_Command { define( 'SAVEQUERIES', true ); } WP_CLI::add_wp_hook( 'all', array( $this, 'wp_hook_begin' ) ); - $this->load_wordpress_with_template(); + try { + $this->load_wordpress_with_template(); + } catch( Exception $e ) { + // pass through + } if ( $this->focus_scope ) { $focus_fields = array( @@ -276,46 +280,41 @@ class Profile_Command { private function load_wordpress_with_template() { global $wp_query; - try { - - $this->scope_track_begin( 'total' ); - $this->scope_track_begin( 'bootstrap' ); - if ( 'bootstrap' === $this->focus_scope ) { - $this->fill_hooks( array( - 'muplugins_loaded', - 'plugins_loaded', - 'setup_theme', - 'after_setup_theme', - 'init', - 'wp_loaded', - ) ); - } - WP_CLI::get_runner()->load_wordpress(); - $this->scope_track_end( 'bootstrap' ); - - // Set up the main WordPress query. - $this->current_scope = 'main_query'; - $this->scope_track_begin( 'main_query' ); - wp(); - $this->scope_track_end( 'main_query' ); - - define( 'WP_USE_THEMES', true ); - - // Template is normally loaded in global scope, so we need to replicate - foreach( $GLOBALS as $key => $value ) { - global $$key; - } - - // Load the theme template. - $this->scope_track_begin( 'template' ); - ob_start(); - require_once( ABSPATH . WPINC . '/template-loader.php' ); - ob_get_clean(); - $this->scope_track_end( 'template' ); - $this->scope_track_end( 'total' ); - } catch( Exception $e ) { - return; + $this->scope_track_begin( 'total' ); + $this->scope_track_begin( 'bootstrap' ); + if ( 'bootstrap' === $this->focus_scope ) { + $this->fill_hooks( array( + 'muplugins_loaded', + 'plugins_loaded', + 'setup_theme', + 'after_setup_theme', + 'init', + 'wp_loaded', + ) ); } + WP_CLI::get_runner()->load_wordpress(); + $this->scope_track_end( 'bootstrap' ); + + // Set up the main WordPress query. + $this->current_scope = 'main_query'; + $this->scope_track_begin( 'main_query' ); + wp(); + $this->scope_track_end( 'main_query' ); + + define( 'WP_USE_THEMES', true ); + + // Template is normally loaded in global scope, so we need to replicate + foreach( $GLOBALS as $key => $value ) { + global $$key; + } + + // Load the theme template. + $this->scope_track_begin( 'template' ); + ob_start(); + require_once( ABSPATH . WPINC . '/template-loader.php' ); + ob_get_clean(); + $this->scope_track_end( 'template' ); + $this->scope_track_end( 'total' ); } /**