diff --git a/features/rewrite.feature b/features/rewrite.feature index a942bf5cb..9ccb04f0c 100644 --- a/features/rewrite.feature +++ b/features/rewrite.feature @@ -5,7 +5,6 @@ Feature: Manage WordPress rewrites Scenario: Change site permastructs When I run `wp rewrite structure /blog/%year%/%monthnum%/%day%/%postname%/ --category-base=section --tag-base=topic` - And I run `wp rewrite flush` When I run `wp option get permalink_structure` Then STDOUT should contain: diff --git a/php/commands/rewrite.php b/php/commands/rewrite.php index 0f85ddc12..1597d9726 100644 --- a/php/commands/rewrite.php +++ b/php/commands/rewrite.php @@ -85,7 +85,14 @@ public function structure( $args, $assoc_args ) { // make sure we detect mod_rewrite if configured in apache_modules in config self::apache_modules(); - flush_rewrite_rules( isset( $assoc_args['hard'] ) ); + + // Launch a new process to flush rewrites because core expects flush + // to happen after rewrites are set + $new_assoc_args = array(); + if ( isset( $assoc_args['hard'] ) ) + $new_assoc_args['hard'] = true; + \WP_CLI::launch_wpcli( 'rewrite flush', array(), $new_assoc_args ); + WP_CLI::success( "Rewrite structure set." ); }