diff --git a/features/profile.feature b/features/profile.feature index bf82216..2b36e25 100644 --- a/features/profile.feature +++ b/features/profile.feature @@ -27,3 +27,12 @@ Feature: Basic profile usage | callback | time | | total | | And STDERR should be empty + + Scenario: Trailingslash provided URL to avoid canonical redirect + Given a WP install + + When I run `wp profile hook setup_theme --url=example.com --fields=callback,time` + Then STDERR should be empty + And STDOUT should be a table containing rows: + | callback | time | + | total | | diff --git a/inc/class-command.php b/inc/class-command.php index 6db8dc7..ffef001 100644 --- a/inc/class-command.php +++ b/inc/class-command.php @@ -267,11 +267,13 @@ class Command { * Run the profiler against WordPress */ private function run_profiler() { - if ( ! isset( WP_CLI::get_runner()->config['url'] ) ) { - WP_CLI::add_wp_hook( 'muplugins_loaded', function(){ + WP_CLI::add_wp_hook( 'muplugins_loaded', function(){ + if ( $url = WP_CLI::get_runner()->config['url'] ) { + WP_CLI::set_url( trailingslashit( $url ) ); + } else { WP_CLI::set_url( home_url( '/' ) ); - }); - } + } + }); WP_CLI::add_hook( 'after_wp_config_load', function() { if ( defined( 'SAVEQUERIES' ) && ! SAVEQUERIES ) { WP_CLI::error( "'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php" );