public function regenerate( $args, $assoc_args = array() ) {
		$assoc_args = wp_parse_args(
			$assoc_args,
			[ 'image_size' => '' ]
		);

		$image_size = $assoc_args['image_size'];
		if ( $image_size && ! in_array( $image_size, get_intermediate_image_sizes(), true ) ) {
			WP_CLI::error( sprintf( 'Unknown image size "%s".', $image_size ) );
		}

		if ( empty( $args ) ) {
			if ( $image_size ) {
				WP_CLI::confirm( sprintf( 'Do you really want to regenerate the "%s" image size for all images?', $image_size ), $assoc_args );
			} else {
				WP_CLI::confirm( 'Do you really want to regenerate all images?', $assoc_args );
			}
		}

		$skip_delete  = Utils\get_flag_value( $assoc_args, 'skip-delete' );
		$only_missing = Utils\get_flag_value( $assoc_args, 'only-missing' );
		if ( $only_missing ) {
			$skip_delete = true;
		}

		$additional_mime_types = array();

		if ( Utils\wp_version_compare( '4.7', '>=' ) ) {
			$additional_mime_types[] = 'application/pdf';
		}

		$images = $this->get_images( $args, $additional_mime_types );
		$count  = $images->post_count;

		if ( ! $count ) {
			WP_CLI::warning( 'No images found.' );
			return;
		}

		WP_CLI::log(
			sprintf(
				'Found %1$d %2$s to regenerate.',
				$count,
				_n( 'image', 'images', $count )
			)
		);

		if ( $image_size ) {
			$image_size_filters = $this->add_image_size_filters( $image_size );
		}

		$number    = 0;
		$successes = 0;
		$errors    = 0;
		$skips     = 0;
		foreach ( $images->posts as $post ) {
			$number++;
			if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) {
				Utils\wp_clear_object_cache();
			}
			$this->process_regeneration( $post->ID, $skip_delete, $only_missing, $image_size, $number . '/' . $count, $successes, $errors, $skips );
		}

		if ( $image_size ) {
			$this->remove_image_size_filters( $image_size_filters );
		}

		Utils\report_batch_operation_results( 'image', 'regenerate', $count, $successes, $errors, $skips );
	}
public function regenerate( $args, $assoc_args = array() ) {
		$assoc_args = wp_parse_args(
			$assoc_args,
			[ 'image_size' => '' ]
		);

		$image_size = $assoc_args['image_size'];
		if ( $image_size && ! in_array( $image_size, get_intermediate_image_sizes(), true ) ) {
			WP_CLI::error( sprintf( 'Unknown image size "%s".', $image_size ) );
		}

		if ( empty( $args ) ) {
			if ( $image_size ) {
				WP_CLI::confirm( sprintf( 'Do you really want to regenerate the "%s" image size for all images?', $image_size ), $assoc_args );
			} else {
				WP_CLI::confirm( 'Do you really want to regenerate all images?', $assoc_args );
			}
		}

		$skip_delete  = Utils\get_flag_value( $assoc_args, 'skip-delete' );
		$only_missing = Utils\get_flag_value( $assoc_args, 'only-missing' );
		if ( $only_missing ) {
			$skip_delete = true;
		}

		$additional_mime_types = array();

		if ( Utils\wp_version_compare( '4.7', '>=' ) ) {
			$additional_mime_types[] = 'application/pdf';
		}

		$images = $this->get_images( $args, $additional_mime_types );
		$count  = $images->post_count;

		if ( ! $count ) {
			WP_CLI::warning( 'No images found.' );
			return;
		}

		WP_CLI::log(
			sprintf(
				'Found %1$d %2$s to regenerate.',
				$count,
				_n( 'image', 'images', $count )
			)
		);

		if ( $image_size ) {
			$image_size_filters = $this->add_image_size_filters( $image_size );
		}

		$number    = 0;
		$successes = 0;
		$errors    = 0;
		$skips     = 0;
		foreach ( $images->posts as $post ) {
			$number++;
			if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) {
				Utils\wp_clear_object_cache();
			}
			$this->process_regeneration( $post->ID, $skip_delete, $only_missing, $image_size, $number . '/' . $count, $successes, $errors, $skips );
		}

		if ( $image_size ) {
			$this->remove_image_size_filters( $image_size_filters );
		}

		Utils\report_batch_operation_results( 'image', 'regenerate', $count, $successes, $errors, $skips );
	}
public function regenerate ( $ args , $ assoc_args = array ( ) ) { $ assoc_args = wp_parse_args ( $ assoc_args , [ 'image_size' => '' ] ) ; $ image_size = $ assoc_args [ 'image_size' ] ; if ( $ image_size && ! in_array ( $ image_size , get_intermediate_image_sizes ( ) , true ) ) { WP_CLI :: error ( sprintf ( 'Unknown image size "%s".' , $ image_size ) ) ; } if ( empty ( $ args ) ) { if ( $ image_size ) { WP_CLI :: confirm ( sprintf ( 'Do you really want to regenerate the "%s" image size for all images?' , $ image_size ) , $ assoc_args ) ; } else { WP_CLI :: confirm ( 'Do you really want to regenerate all images?' , $ assoc_args ) ; } } $ skip_delete = Utils \ get_flag_value ( $ assoc_args , 'skip-delete' ) ; $ only_missing = Utils \ get_flag_value ( $ assoc_args , 'only-missing' ) ; if ( $ only_missing ) { $ skip_delete = true ; } $ additional_mime_types = array ( ) ; if ( Utils \ wp_version_compare ( '4.7' , '>=' ) ) { $ additional_mime_types [ ] = 'application/pdf' ; } $ images = $ this -> get_images ( $ args , $ additional_mime_types ) ; $ count = $ images -> post_count ; if ( ! $ count ) { WP_CLI :: warning ( 'No images found.' ) ; return ; } WP_CLI :: log ( sprintf ( 'Found %1$d %2$s to regenerate.' , $ count , _n ( 'image' , 'images' , $ count ) ) ) ; if ( $ image_size ) { $ image_size_filters = $ this -> add_image_size_filters ( $ image_size ) ; } $ number = 0 ; $ successes = 0 ; $ errors = 0 ; $ skips = 0 ; foreach ( $ images -> posts as $ post ) { $ number ++ ; if ( 0 === $ number % self :: WP_CLEAR_OBJECT_CACHE_INTERVAL ) { Utils \ wp_clear_object_cache ( ) ; } $ this -> process_regeneration ( $ post -> ID , $ skip_delete , $ only_missing , $ image_size , $ number . '/' . $ count , $ successes , $ errors , $ skips ) ; } if ( $ image_size ) { $ this -> remove_image_size_filters ( $ image_size_filters ) ; } Utils \ report_batch_operation_results ( 'image' , 'regenerate' , $ count , $ successes , $ errors , $ skips ) ; }
Regenerates thumbnails for one or more attachments.

## OPTIONS

[<attachment-id>...]
: One or more IDs of the attachments to regenerate.

[--image_size=<image_size>]
: Name of the image size to regenerate. Only thumbnails of this image size will be regenerated, thumbnails of other image sizes will not.

[--skip-delete]
: Skip deletion of the original thumbnails. If your thumbnails are linked from sources outside your control, it's likely best to leave them around. Defaults to false.

[--only-missing]
: Only generate thumbnails for images missing image sizes.

[--yes]
: Answer yes to the confirmation message. Confirmation only shows when no IDs passed as arguments.

## EXAMPLES

# Regenerate thumbnails for given attachment IDs.
$ wp media regenerate 123 124 125
Found 3 images to regenerate.
1/3 Regenerated thumbnails for "Vertical Image" (ID 123).
2/3 Regenerated thumbnails for "Horizontal Image" (ID 124).
3/3 Regenerated thumbnails for "Beautiful Picture" (ID 125).
Success: Regenerated 3 of 3 images.

# Regenerate all thumbnails, without confirmation.
$ wp media regenerate --yes
Found 3 images to regenerate.
1/3 Regenerated thumbnails for "Sydney Harbor Bridge" (ID 760).
2/3 Regenerated thumbnails for "Boardwalk" (ID 757).
3/3 Regenerated thumbnails for "Sunburst Over River" (ID 756).
Success: Regenerated 3 of 3 images.

# Re-generate all thumbnails that have IDs between 1000 and 2000.
$ seq 1000 2000 | xargs wp media regenerate
Found 4 images to regenerate.
1/4 Regenerated thumbnails for "Vertical Featured Image" (ID 1027).
2/4 Regenerated thumbnails for "Horizontal Featured Image" (ID 1022).
3/4 Regenerated thumbnails for "Unicorn Wallpaper" (ID 1045).
4/4 Regenerated thumbnails for "I Am Worth Loving Wallpaper" (ID 1023).
Success: Regenerated 4 of 4 images.

# Re-generate only the thumbnails of "large" image size for all images.
$ wp media regenerate --image_size=large
Do you really want to regenerate the "large" image size for all images? [y/n] y
Found 3 images to regenerate.
1/3 Regenerated "large" thumbnail for "Sydney Harbor Bridge" (ID 760).
2/3 No "large" thumbnail regeneration needed for "Boardwalk" (ID 757).
3/3 Regenerated "large" thumbnail for "Sunburst Over River" (ID 756).
Success: Regenerated 3 of 3 images.
Regenerates thumbnails for one or more attachments .