From 5f2c0f52cc6922dd02559c9b30aa33855bfa02d3 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Sat, 8 Oct 2016 16:02:46 -0700 Subject: [PATCH] Keep track of recursion in a more precise manner --- inc/class-profiler.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/inc/class-profiler.php b/inc/class-profiler.php index 47b628d..88a46d9 100644 --- a/inc/class-profiler.php +++ b/inc/class-profiler.php @@ -100,19 +100,20 @@ class Profiler { $this->loggers[ $current_filter ]->start(); } - if ( ! is_null( $this->previous_filter_callbacks ) && 0 === $this->filter_depth ) { + if ( 0 === $this->filter_depth + && ! is_null( $this->previous_filter_callbacks ) ) { self::set_filter_callbacks( $this->previous_filter, $this->previous_filter_callbacks ); $this->previous_filter_callbacks = null; } - if ( 'hook' === $this->type && $current_filter === $this->focus && 0 === $this->filter_depth ) { + if ( 'hook' === $this->type + && $current_filter === $this->focus + && 0 === $this->filter_depth ) { $this->wrap_current_filter_callbacks( $current_filter ); - $this->filter_depth = 1; } + $this->filter_depth++; - if ( ! ( 'hook' === $this->type && 'shutdown' === $this->focus ) ) { - WP_CLI::add_wp_hook( $current_filter, array( $this, 'wp_hook_end' ), 9999 ); - } + WP_CLI::add_wp_hook( $current_filter, array( $this, 'wp_hook_end' ), 9999 ); } /** @@ -161,10 +162,6 @@ class Profiler { } $current_filter = current_filter(); - if ( 'hook' === $this->type && $current_filter === $this->focus ) { - $this->filter_depth = 0; - } - if ( ( 'stage' === $this->type && in_array( $current_filter, $this->current_stage_hooks ) ) || ( 'hook' === $this->type && ! $this->focus ) ) { $this->loggers[ $current_filter ]->stop(); @@ -182,6 +179,8 @@ class Profiler { } } + $this->filter_depth--; + return $filter_value; }