From 8aee5319783ff6c95d7a827540254ba5eb5e7c71 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 21:38:21 +0000 Subject: [PATCH 1/8] Initial plan From 28d4d3535762efc3b2f2e07fcd70f80cf1c91514 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 21:41:34 +0000 Subject: [PATCH 2/8] Add --search option to wp profile hook to filter by callback name Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/profile-hook.feature | 46 +++++++++++++++++++++++++++++++++++ src/Command.php | 23 ++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/features/profile-hook.feature b/features/profile-hook.feature index b3335ca9..4d7b0661 100644 --- a/features/profile-hook.feature +++ b/features/profile-hook.feature @@ -128,6 +128,52 @@ Feature: Profile a specific hook | total (1) | | 0 | 1 | And STDERR should be empty + @require-wp-4.4 + Scenario: Search for callbacks by name pattern on a specific hook + Given a WP install + And a wp-content/mu-plugins/search-test.php file: + """ + ] * : Set orderby which field. * + * [--search=] + * : Filter callbacks to those matching the given search pattern (case-insensitive). + * * ## EXAMPLES * * # Profile a hook. @@ -291,6 +294,10 @@ public function hook( $args, $assoc_args ) { if ( Utils\get_flag_value( $assoc_args, 'spotlight' ) ) { $loggers = self::shine_spotlight( $loggers, $metrics ); } + $search = Utils\get_flag_value( $assoc_args, 'search', false ); + if ( $search ) { + $loggers = self::filter_by_callback( $loggers, $search ); + } $formatter->display_items( $loggers, true, $order, $orderby ); } @@ -534,4 +541,20 @@ private static function shine_spotlight( $loggers, $metrics ) { return $loggers; } + + /** + * Filter loggers to only those whose callback name matches a pattern. + * + * @param array $loggers + * @param string $pattern + * @return array + */ + private static function filter_by_callback( $loggers, $pattern ) { + foreach ( $loggers as $k => $logger ) { + if ( ! isset( $logger->callback ) || false === stripos( $logger->callback, $pattern ) ) { + unset( $loggers[ $k ] ); + } + } + return $loggers; + } } From e10355c050455afb336f7719414c1caf8da812b0 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 10 Mar 2026 22:08:36 +0100 Subject: [PATCH 3/8] Update test --- features/profile.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/profile.feature b/features/profile.feature index 459d7d3b..2c7a665b 100644 --- a/features/profile.feature +++ b/features/profile.feature @@ -8,7 +8,7 @@ Feature: Basic profile usage """ usage: wp profile eval [--hook[=]] [--fields=] [--format=] [--order=] [--orderby=] or: wp profile eval-file [--hook[=]] [--fields=] [--format=] [--order=] [--orderby=] - or: wp profile hook [] [--all] [--spotlight] [--url=] [--fields=] [--format=] [--order=] [--orderby=] + or: wp profile hook [] [--all] [--spotlight] [--url=] [--fields=] [--format=] [--order=] [--orderby=] [--search=] or: wp profile stage [] [--all] [--spotlight] [--url=] [--fields=] [--format=] [--order=] [--orderby=] See 'wp help profile ' for more information on a specific command. From 02dc83d07e4ef028021abf556d93f501f9782c10 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 10 Mar 2026 22:17:17 +0100 Subject: [PATCH 4/8] Update src/Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Command.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Command.php b/src/Command.php index 7478b1b1..e795c7e0 100644 --- a/src/Command.php +++ b/src/Command.php @@ -296,6 +296,9 @@ public function hook( $args, $assoc_args ) { } $search = Utils\get_flag_value( $assoc_args, 'search', false ); if ( $search ) { + if ( ! $focus ) { + WP_CLI::error( '--search requires --all or a specific hook.' ); + } $loggers = self::filter_by_callback( $loggers, $search ); } $formatter->display_items( $loggers, true, $order, $orderby ); From 0d9e630ef95ec18a1e45358f08c6700a825c32b2 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 10 Mar 2026 22:17:25 +0100 Subject: [PATCH 5/8] Update src/Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command.php b/src/Command.php index e795c7e0..8f3f2b75 100644 --- a/src/Command.php +++ b/src/Command.php @@ -295,7 +295,7 @@ public function hook( $args, $assoc_args ) { $loggers = self::shine_spotlight( $loggers, $metrics ); } $search = Utils\get_flag_value( $assoc_args, 'search', false ); - if ( $search ) { + if ( false !== $search && '' !== $search ) { if ( ! $focus ) { WP_CLI::error( '--search requires --all or a specific hook.' ); } From f5f330513103ea75827046c6ff561b2cea07504b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 10 Mar 2026 22:17:36 +0100 Subject: [PATCH 6/8] Update features/profile-hook.feature Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- features/profile-hook.feature | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/features/profile-hook.feature b/features/profile-hook.feature index bb30ccbc..3a324bc8 100644 --- a/features/profile-hook.feature +++ b/features/profile-hook.feature @@ -153,6 +153,32 @@ Feature: Profile a specific hook """ And STDERR should be empty + Scenario: Profile an intermediate stage hook + Given a WP install + + When I run `wp profile hook muplugins_loaded --fields=hook` + Then STDOUT should be a table containing rows: + | hook | + | muplugins_loaded | + And STDERR should be empty + + Scenario: Profile the muplugins_loaded:before hook + Given a WP install + + When I run `wp profile hook muplugins_loaded:before --fields=hook` + Then STDOUT should be a table containing rows: + | hook | + | muplugins_loaded:before | + And STDERR should be empty + + Scenario: Profile the muplugins_loaded:after hook + Given a WP install + + When I run `wp profile hook muplugins_loaded:after --fields=hook` + Then STDOUT should be a table containing rows: + | hook | + | muplugins_loaded:after | + And STDERR should be empty Scenario: Hooks should only be called once Given a WP install And a wp-content/mu-plugins/action-test.php file: From 3b148c759d9d072328462f9f819cbea7f7b1583b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 21:32:25 +0000 Subject: [PATCH 7/8] Refactor filter_by_callback to use array_filter Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Command.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Command.php b/src/Command.php index 8f3f2b75..b9f19e61 100644 --- a/src/Command.php +++ b/src/Command.php @@ -553,11 +553,11 @@ private static function shine_spotlight( $loggers, $metrics ) { * @return array */ private static function filter_by_callback( $loggers, $pattern ) { - foreach ( $loggers as $k => $logger ) { - if ( ! isset( $logger->callback ) || false === stripos( $logger->callback, $pattern ) ) { - unset( $loggers[ $k ] ); + return array_filter( + $loggers, + function ( $logger ) use ( $pattern ) { + return isset( $logger->callback ) && false !== stripos( $logger->callback, $pattern ); } - } - return $loggers; + ); } } From 72b124cbedc1512fcf27299ce673ebe2a787a9ba Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 11 Mar 2026 09:48:59 +0100 Subject: [PATCH 8/8] Remove some tests --- features/profile-hook.feature | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/features/profile-hook.feature b/features/profile-hook.feature index 3a324bc8..bb30ccbc 100644 --- a/features/profile-hook.feature +++ b/features/profile-hook.feature @@ -153,32 +153,6 @@ Feature: Profile a specific hook """ And STDERR should be empty - Scenario: Profile an intermediate stage hook - Given a WP install - - When I run `wp profile hook muplugins_loaded --fields=hook` - Then STDOUT should be a table containing rows: - | hook | - | muplugins_loaded | - And STDERR should be empty - - Scenario: Profile the muplugins_loaded:before hook - Given a WP install - - When I run `wp profile hook muplugins_loaded:before --fields=hook` - Then STDOUT should be a table containing rows: - | hook | - | muplugins_loaded:before | - And STDERR should be empty - - Scenario: Profile the muplugins_loaded:after hook - Given a WP install - - When I run `wp profile hook muplugins_loaded:after --fields=hook` - Then STDOUT should be a table containing rows: - | hook | - | muplugins_loaded:after | - And STDERR should be empty Scenario: Hooks should only be called once Given a WP install And a wp-content/mu-plugins/action-test.php file: