The image_sideload_extensions WordPress PHP Filter allows you to modify the list of allowed file extensions when sideloading an image from a URL.
Usage
add_filter('image_sideload_extensions', 'my_custom_image_sideload_extensions', 10, 2); function my_custom_image_sideload_extensions($allowed_extensions, $file) { // your custom code here return $allowed_extensions; }
Parameters
$allowed_extensions
(string[]): Array of allowed file extensions.$file
(string): The URL of the image to download.
More information
See WordPress Developer Resources: image_sideload_extensions
Examples
Add BMP file extension
Allow BMP file extension when sideloading images.
add_filter('image_sideload_extensions', 'allow_bmp_extension', 10, 2); function allow_bmp_extension($allowed_extensions, $file) { $allowed_extensions[] = 'bmp'; return $allowed_extensions; }
Add SVG file extension
Allow SVG file extension when sideloading images.
add_filter('image_sideload_extensions', 'allow_svg_extension', 10, 2); function allow_svg_extension($allowed_extensions, $file) { $allowed_extensions[] = 'svg'; return $allowed_extensions; }
Remove WebP file extension
Disallow WebP file extension when sideloading images.
add_filter('image_sideload_extensions', 'remove_webp_extension', 10, 2); function remove_webp_extension($allowed_extensions, $file) { $key = array_search('webp', $allowed_extensions); if ($key !== false) { unset($allowed_extensions[$key]); } return $allowed_extensions; }
Change allowed file extensions
Only allow PNG and GIF file extensions when sideloading images.
add_filter('image_sideload_extensions', 'change_allowed_extensions', 10, 2); function change_allowed_extensions($allowed_extensions, $file) { $allowed_extensions = ['png', 'gif']; return $allowed_extensions; }
Log allowed file extensions
Log the allowed file extensions when sideloading images.
add_filter('image_sideload_extensions', 'log_allowed_extensions', 10, 2); function log_allowed_extensions($allowed_extensions, $file) { error_log('Allowed extensions: ' . implode(', ', $allowed_extensions)); return $allowed_extensions; }