image_sideload_extensions
Filter HookDescription
Filters the list of allowed file extensions when sideloading an image from a URL. The default allowed extensions are: - `jpg` - `jpeg` - `jpe` - `png` - `gif` - `webp`Hook Information
File Location |
wp-admin/includes/media.php
View on GitHub
|
Hook Type | Filter |
Line Number | 1038 |
Hook Parameters
Type | Name | Description |
---|---|---|
string[]
|
$allowed_extensions
|
Array of allowed file extensions. |
string
|
$file
|
The URL of the image to download. |
Usage Examples
Basic Usage
<?php
// Hook into image_sideload_extensions
add_filter('image_sideload_extensions', 'my_custom_filter', 10, 2);
function my_custom_filter($allowed_extensions, $file) {
// Your custom filtering logic here
return $allowed_extensions;
}
Source Code Context
wp-admin/includes/media.php:1038
- How this hook is used in WordPress core
<?php
1033 * @since 5.8.0 Added 'webp' to the default list of allowed file extensions.
1034 *
1035 * @param string[] $allowed_extensions Array of allowed file extensions.
1036 * @param string $file The URL of the image to download.
1037 */
1038 $allowed_extensions = apply_filters( 'image_sideload_extensions', $allowed_extensions, $file );
1039 $allowed_extensions = array_map( 'preg_quote', $allowed_extensions );
1040
1041 // Set variables for storage, fix file filename for query strings.
1042 preg_match( '/[^\?]+\.(' . implode( '|', $allowed_extensions ) . ')\b/i', $file, $matches );
1043
PHP Documentation
<?php
/**
* Filters the list of allowed file extensions when sideloading an image from a URL.
*
* The default allowed extensions are:
*
* - `jpg`
* - `jpeg`
* - `jpe`
* - `png`
* - `gif`
* - `webp`
*
* @since 5.6.0
* @since 5.8.0 Added 'webp' to the default list of allowed file extensions.
*
* @param string[] $allowed_extensions Array of allowed file extensions.
* @param string $file The URL of the image to download.
*/
Quick Info
- Hook Type: Filter
- Parameters: 2
- File: wp-admin/includes/media.php
Related Hooks
Related hooks will be displayed here in future updates.