I am currently working on a function that will do the following:
Checks if the parameter holds an already created image size and if this size does not exists, create a new one
Loop through all the image sizes to add these as a source element in the code
This is currently what I have, but the only thing that's bugging me is that when I want to display an image with the newly created size it doesn't recognize the size. I get the following notice: Notice undefined index test.
private function checkImageSizes() {
$exists = false;
foreach ($this->getSizes() as $size) {
$exists = false;
foreach ($this->get_image_sizes() as $currentSizes) {
if($size['width'] == $currentSizes['width'] && $size['height'] == $currentSizes['height']) {
$exists = true;
return false;
} else {
$exists = false;
}
}
if($exists == false) {
if(function_exists('add_image_size')) {
add_image_size($size['name'], $size['width'], $size['height'], true);
}
}
}
}
I know this question is not new and there are answered, but I can't seem to find the answer to my problem. Thanks for helping.
add_image_size()
it doesn't apply retroactively, right? It will only apply for newly uploaded images. For exisiting images you need to regenerate them. There are several plugins available for this.