mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:02 +08:00
Throw an exception, because there's no way we can restore the hooks
This commit is contained in:
parent
785c83949e
commit
10a7f500e9
1 changed files with 43 additions and 45 deletions
|
@ -14,8 +14,7 @@ class Profile_Command {
|
||||||
private $focus_log = array();
|
private $focus_log = array();
|
||||||
private $hook_scope;
|
private $hook_scope;
|
||||||
private $hook_log = array();
|
private $hook_log = array();
|
||||||
private $backup_wp_filter = null;
|
private $current_filter_callbacks = array();
|
||||||
private $backup_wp_filter_callbacks = array();
|
|
||||||
private $query_offset = 0;
|
private $query_offset = 0;
|
||||||
private $focus_query_offset = 0;
|
private $focus_query_offset = 0;
|
||||||
private $hook_offset = 0;
|
private $hook_offset = 0;
|
||||||
|
@ -183,10 +182,10 @@ class Profile_Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->focus_hook && $current_filter === $this->focus_hook ) {
|
if ( $this->focus_hook && $current_filter === $this->focus_hook ) {
|
||||||
$this->backup_wp_filter = $current_filter;
|
$this->current_filter_callbacks = $wp_filter[ $current_filter ];
|
||||||
$this->backup_wp_filter_callbacks = $wp_filter[ $current_filter ];
|
|
||||||
unset( $wp_filter[ $current_filter ] );
|
unset( $wp_filter[ $current_filter ] );
|
||||||
call_user_func_array( array( $this, 'do_action' ), func_get_args() );
|
call_user_func_array( array( $this, 'do_action' ), func_get_args() );
|
||||||
|
throw new Exception( "Need to bail, because can't restore the hooks" );
|
||||||
}
|
}
|
||||||
|
|
||||||
WP_CLI::add_wp_hook( $current_filter, array( $this, 'wp_hook_end' ), 999 );
|
WP_CLI::add_wp_hook( $current_filter, array( $this, 'wp_hook_end' ), 999 );
|
||||||
|
@ -198,7 +197,7 @@ class Profile_Command {
|
||||||
private function do_action( $tag, $arg = '' ) {
|
private function do_action( $tag, $arg = '' ) {
|
||||||
global $wp_actions, $merged_filters, $wp_current_filter, $wpdb;
|
global $wp_actions, $merged_filters, $wp_current_filter, $wpdb;
|
||||||
$wp_filter = array();
|
$wp_filter = array();
|
||||||
$wp_filter[ $tag ] = $this->backup_wp_filter_callbacks;
|
$wp_filter[ $tag ] = $this->current_filter_callbacks;
|
||||||
|
|
||||||
if ( ! isset($wp_actions[$tag]) )
|
if ( ! isset($wp_actions[$tag]) )
|
||||||
$wp_actions[$tag] = 1;
|
$wp_actions[$tag] = 1;
|
||||||
|
@ -267,12 +266,6 @@ class Profile_Command {
|
||||||
$this->focus_query_offset = count( $wpdb->queries );
|
$this->focus_query_offset = count( $wpdb->queries );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $this->backup_wp_filter ) ) {
|
|
||||||
// $wp_filter[ $current_filter ] = $this->backup_wp_filter_callbacks;
|
|
||||||
unset( $this->backup_wp_filter );
|
|
||||||
unset( $this->backup_wp_filter_callbacks );
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->hook_time += microtime( true ) - $this->hook_start_time;
|
$this->hook_time += microtime( true ) - $this->hook_start_time;
|
||||||
return $filter_value;
|
return $filter_value;
|
||||||
}
|
}
|
||||||
|
@ -283,41 +276,46 @@ class Profile_Command {
|
||||||
private function load_wordpress_with_template() {
|
private function load_wordpress_with_template() {
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
|
|
||||||
$this->scope_track_begin( 'total' );
|
try {
|
||||||
$this->scope_track_begin( 'bootstrap' );
|
|
||||||
if ( 'bootstrap' === $this->focus_scope ) {
|
$this->scope_track_begin( 'total' );
|
||||||
$this->fill_hooks( array(
|
$this->scope_track_begin( 'bootstrap' );
|
||||||
'muplugins_loaded',
|
if ( 'bootstrap' === $this->focus_scope ) {
|
||||||
'plugins_loaded',
|
$this->fill_hooks( array(
|
||||||
'setup_theme',
|
'muplugins_loaded',
|
||||||
'after_setup_theme',
|
'plugins_loaded',
|
||||||
'init',
|
'setup_theme',
|
||||||
'wp_loaded',
|
'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;
|
||||||
}
|
}
|
||||||
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' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue