Skip to content

Commit 9ba40cc

Browse files
swissspidyCopilot
andauthored
Update src/Profiler.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b325338 commit 9ba40cc

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/Profiler.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,18 @@ public function get_loggers() {
7979
* Run the profiler against WordPress
8080
*/
8181
public function run() {
82-
$url = WP_CLI::get_runner()->config['url'];
83-
$this->is_admin_request = ! empty( $url ) && (bool) preg_match( '#/wp-admin(/|$)#i', $url );
82+
$url = WP_CLI::get_runner()->config['url'];
83+
$path = '';
84+
if ( ! empty( $url ) ) {
85+
$parsed_url = @parse_url( $url );
86+
if ( false !== $parsed_url && isset( $parsed_url['path'] ) ) {
87+
$path = $parsed_url['path'];
88+
} else {
89+
// Fallback for cases where $url is just a path.
90+
$path = $url;
91+
}
92+
}
93+
$this->is_admin_request = ! empty( $path ) && (bool) preg_match( '#/wp-admin(/|$|\?)#i', $path );
8494

8595
if ( $this->is_admin_request && 'admin' !== WP_CLI::get_runner()->config['context'] ) {
8696
WP_CLI::error( 'Profiling an admin URL requires --context=admin.' );

0 commit comments

Comments
 (0)