Because WordPress won't generate images that are larger than the original image uploaded, if larger image sizes than those available are requested using rwp_style(), then a PHP notice is generated when the function attempts to generate the background image declarations (as the images array is empty).
This can be avoided by checking for an empty image array at the start of the build_css() function before attempting to generate the <style /> declaration.
However, this still means that no background image is displayed, despite one being available (albeit not a large-enough size).
A possible solution would be to add some logic to the remove_images_in_sizes_not_selected() function to ensure that if the resulting image array is empty, then it is repopulated with the selected sizes but with the 'src' for each size set to the 'full' sized image URL (as this is the closest match).
At least then the sizing of the resulting background image(s) can be controlled via CSS, i.e. background-size: cover; etc.
Happy to create a pull request if this seems like a reasonable solution.
Hi Matt!
Thanks for reporting the issue! I'm not quite following what the problem is without testing it, but it sounds like you're on top of it! ;) Feel free to create a PR if you want to :)
Because WordPress won't generate images that are larger than the original image uploaded, if larger image sizes than those available are requested using
rwp_style()
, then a PHP notice is generated when the function attempts to generate the background image declarations (as the images array is empty).This can be avoided by checking for an empty image array at the start of the
build_css()
function before attempting to generate the<style />
declaration.However, this still means that no background image is displayed, despite one being available (albeit not a large-enough size).
A possible solution would be to add some logic to the remove_images_in_sizes_not_selected() function to ensure that if the resulting image array is empty, then it is repopulated with the selected sizes but with the 'src' for each size set to the 'full' sized image URL (as this is the closest match).
At least then the sizing of the resulting background image(s) can be controlled via CSS, i.e.
background-size: cover;
etc.Happy to create a pull request if this seems like a reasonable solution.
Props for the plugin BTW :)