Merge pull request #83 from runcommand/22-trailingslash

Trailingslash provided URL to avoid canonical redirect
This commit is contained in:
Daniel Bachhuber 2016-10-04 08:05:10 -07:00 committed by GitHub
commit da150e2cb8
2 changed files with 15 additions and 4 deletions

View file

@ -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 | |

View file

@ -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(){
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" );