diff --git a/includes/class-starter-content.php b/includes/class-starter-content.php index 3b54a9173d..0df7a45792 100644 --- a/includes/class-starter-content.php +++ b/includes/class-starter-content.php @@ -226,6 +226,6 @@ public static function upload_logo() { * @return bool E2E testing environment? */ public static function is_e2e() { - return defined( 'WP_NEWSPACK_IS_E2E' ) && WP_NEWSPACK_IS_E2E; + return defined( 'NEWSPACK_IS_E2E' ) && NEWSPACK_IS_E2E; } } diff --git a/includes/cli/class-initializer.php b/includes/cli/class-initializer.php index 67d67a78fd..65a787d3a1 100644 --- a/includes/cli/class-initializer.php +++ b/includes/cli/class-initializer.php @@ -39,6 +39,7 @@ public static function register_comands() { } WP_CLI::add_command( 'newspack setup', 'Newspack\CLI\Setup' ); + WP_CLI::add_command( 'newspack remove-starter-content', [ 'Newspack\Starter_Content','remove_starter_content' ] ); // Utility commands for managing RAS data via WP CLI. WP_CLI::add_command( diff --git a/includes/cli/class-setup.php b/includes/cli/class-setup.php index 6b15da9cda..41a08433cf 100644 --- a/includes/cli/class-setup.php +++ b/includes/cli/class-setup.php @@ -121,8 +121,9 @@ private function initial_content( $assoc_args ) { return WP_CLI::error( $response->data['message'] ); } - WP_CLI::line( 'Creating Posts' ); - for ( $i = 0; $i < 40; $i++ ) { + $posts_count = \Newspack\Starter_Content::is_e2e() ? 10 : 40; + WP_CLI::line( sprintf( 'Creating %d posts', $posts_count ) ); + for ( $i = 0; $i < $posts_count; $i++ ) { $request = new WP_REST_Request( 'POST', '/' . NEWSPACK_API_NAMESPACE . '/wizard/newspack-setup-wizard/starter-content/post/' . $i ); $response = rest_do_request( $request ); echo '.'; diff --git a/includes/starter_content/class-starter-content-generated.php b/includes/starter_content/class-starter-content-generated.php index 93e558126c..8264b3c973 100644 --- a/includes/starter_content/class-starter-content-generated.php +++ b/includes/starter_content/class-starter-content-generated.php @@ -57,7 +57,7 @@ public static function create_post( $post_index ) { } $page_templates = [ '', 'single-feature.php' ]; $paragraphs = explode( PHP_EOL, self::get_lipsum( 'paras', 5 ) ); - $title = self::generate_title(); + $title = self::generate_title( $post_index ); $post_data = [ 'post_title' => $title, 'post_name' => sanitize_title_with_dashes( $title, '', 'save' ), @@ -247,11 +247,12 @@ public static function create_homepage() { /** * Generate a post title * + * @param int $post_index The index of the created post. * @return string The title. */ - public static function generate_title() { + public static function generate_title( $post_index = 0 ) { if ( Starter_Content::is_e2e() ) { - return file_get_contents( NEWSPACK_ABSPATH . 'includes/raw_assets/markup/title.txt' ); + return $post_index . ' ' . file_get_contents( NEWSPACK_ABSPATH . 'includes/raw_assets/markup/title.txt' ); } $title = self::get_lipsum( 'words', wp_rand( 7, 14 ) ); $title = ucfirst( strtolower( str_replace( '.', '', $title ) ) ); // Remove periods, convert to sentence case.