Custom Customizer Image Sanitize fails to update image

The issue is I use this custom sanitizer to get the appropriate image size so that anyone using my themes can’t mess up and put an 8k image in the website. The code works, but the problem I have is that once the code sanitizes the image and returns to the customizer the image doesn’t update… the old image just stays displayed and is got a shade of grey over it. What am I missing?

function semperfi_sanitize_image( $input , $setting ) {

$postid = attachment_url_to_postid( $input );

$input = wp_get_attachment_image_src( $postid , $setting->manager->get_control( $setting->id )->input_attrs[img_size] )[0];

if ( $postid != 0 )

return esc_url( $input );

else

return esc_url( $setting->default );

}

Read more here:: Custom Customizer Image Sanitize fails to update image

Leave a Reply

Your email address will not be published. Required fields are marked *