So, after poking around in the code it looks like the filter image_make_intermediate_size
is not called by the various WP_Customize_Control()
classes at either WP_Customize_Image_Control()
or it’s parent WP_Customize_Upload_Control()
.
I’m looking to auto-generate images of various sizes, for responsive image serving and I need to execute the image_make_intermediate_size()
function with some custom sizes that are specific to my extended custom control. Just not sure how to ensure that the uploaded images call this function mainly because I haven’t been able to track down where or how the upload functionality of WP_Customize_Control()
is “unhooked” from the default upload behavior where the function is normally executed.
Note that the way it works is obviously the best option, don’t want every image uploaded through the theme customizer to auto-generate all the default image sizes, but for my use case, I prefer to use native functionality and just pass some unique size paramters to image_make_intermediate_size()
.
If someone has a better solution, I’m open to it, however, what I came up with seems to work fine.
Basically the following code is just waiting for the image to finish uploading and then hooking into the
add_attachment
action. Once the first is added, we hook in and then generate the new images via the post ID (for the image attachment) which is the only data passed to us by theadd_attachment
action.First, we get the image by calling the post by ID and then a bit of regex saves the various filepaths, filename, and other data bits. Note that I’m recursively adding 3 images of different sizes so change that if you’re just looking to create 1 image or images of different sizes. Also I’ve named my theme as a prerequisite for the
$_POST
data, from looking at this data on various image upload actions, it looks like this is the most concrete way to set a conditional for being inside the theme customizer. There’s not much else to go on, but none of the other areas that utilize the image editor include$_POST['post_data']['theme']
, so just replace that with your theme name or useproperty_exists
if you want it to apply to all themes and only the customizer.