Created
January 20, 2014 19:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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