admin管理员组文章数量:1327849
I would like to unset image sizes before uploading images that are not meant to be featured images. Right now I have a clunky workflow where, whenever I upload images, I comment out the custom image sizes use for featured images, then bulk upload non-featured images. Then I uncomment those lines and then upload the featured images. I have a photosite with thousands of photos so making sure I don't have useless image sizes for non-featured images is important.
I would like to know if there is a way to add a checkbox (probably via a plugin that I create) to the upload new media page at Dashboard > Media > Add New, when checked, it will run a simple piece of code before the media is uploaded.
This is the code I would run if he box is checked.
function disable_featured_image_sizes($sizes)
{
unset($sizes['my_small_square']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'disable_featured_image_sizes');
My problem is I don't know if it's possible to add such a checkbox to the Add New Media page and, if it was possible, how to get this value in my plugin.
I would like to unset image sizes before uploading images that are not meant to be featured images. Right now I have a clunky workflow where, whenever I upload images, I comment out the custom image sizes use for featured images, then bulk upload non-featured images. Then I uncomment those lines and then upload the featured images. I have a photosite with thousands of photos so making sure I don't have useless image sizes for non-featured images is important.
I would like to know if there is a way to add a checkbox (probably via a plugin that I create) to the upload new media page at Dashboard > Media > Add New, when checked, it will run a simple piece of code before the media is uploaded.
This is the code I would run if he box is checked.
function disable_featured_image_sizes($sizes)
{
unset($sizes['my_small_square']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'disable_featured_image_sizes');
My problem is I don't know if it's possible to add such a checkbox to the Add New Media page and, if it was possible, how to get this value in my plugin.
Share Improve this question edited Jul 31, 2020 at 16:56 OctaviaLo asked Jul 31, 2020 at 13:32 OctaviaLoOctaviaLo 1398 bronze badges1 Answer
Reset to default 0You get $sizes
as array, where size name is a value, not a key
Try this
//remove sizes with init hook and remove_image_size
add_action('init', function ($sizes) {
remove_image_size('2048x2048');
remove_image_size('1536x1536');
return $sizes;
});
// or just return sizes you need
add_filter('intermediate_image_sizes', function ($sizes) {
return ['thumbnail','medium','large'];
});
本文标签: uploadsUnset image sizes before images are uploaded
版权声明:本文标题:uploads - Unset image sizes before images are uploaded 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742218499a2435005.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论