Skip to content

Instantly share code, notes, and snippets.

@mgmartel
Created January 20, 2014 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgmartel/8526965 to your computer and use it in GitHub Desktop.
Save mgmartel/8526965 to your computer and use it in GitHub Desktop.
In WordPress, when you edit images using the Image Editor, only core sizes are saved, and not any of your custom sizes (including post-thumbnail!). If you register image sizes using the functions in this Gist, images edited in the Image Editor will be saved in all image sizes.
<?php
/**
* If you register image sizes using the function below, images
* edited in the Image Editor will be saved in all image sizes.
*
* @see https://core.trac.wordpress.org/ticket/19889
*/
if ( !function_exists( 'add_image_editor_size') ) :
function add_image_editor_size( $name, $width = 0, $height = 0, $crop = false ) {
add_image_size( $name, $width, $height, $crop );
add_filter( "pre_option_{$name}_size_w", function() use ( $width ) { return $width; } );
add_filter( "pre_option_{$name}_size_h", function() use ( $height ) { return $height; } );
add_filter( "pre_option_{$name}_crop", function() use ( $crop ) { return $crop; } );
}
endif;
if ( !function_exists( 'set_post_thumbnail_editor_size' ) ) :
function set_post_thumbnail_editor_size( $width = 0, $height = 0, $crop = false ) {
add_image_editor_size( 'post-thumbnail', $width, $height, $crop );
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment