Media: Add an `image_sideload_extensions` filter to the list of allowed file extensions when sideloading an image from a URL.
Props paulschreiber, hellofromTonya Fixes #50695 Built from https://develop.svn.wordpress.org/trunk@49198 git-svn-id: http://core.svn.wordpress.org/trunk@48960 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
727922c8eb
commit
1bcda42567
|
@ -980,8 +980,29 @@ function wp_media_upload_handler() {
|
|||
function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) {
|
||||
if ( ! empty( $file ) ) {
|
||||
|
||||
$allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif' );
|
||||
|
||||
/**
|
||||
* Filters the list of allowed file extensions when sideloading an image from a URL.
|
||||
*
|
||||
* The default allowed extensions are:
|
||||
*
|
||||
* - `jpg`
|
||||
* - `jpeg`
|
||||
* - `jpe`
|
||||
* - `png`
|
||||
* - `gif`
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param string[] $allowed_extensions Array of allowed file extensions.
|
||||
* @param string $file The URL of the image to download.
|
||||
*/
|
||||
$allowed_extensions = apply_filters( 'image_sideload_extensions', $allowed_extensions, $file );
|
||||
$allowed_extensions = array_map( 'preg_quote', $allowed_extensions );
|
||||
|
||||
// Set variables for storage, fix file filename for query strings.
|
||||
preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
|
||||
preg_match( '/[^\?]+\.(' . implode( '|', $allowed_extensions ) . ')\b/i', $file, $matches );
|
||||
|
||||
if ( ! $matches ) {
|
||||
return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL.' ) );
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.6-alpha-49197';
|
||||
$wp_version = '5.6-alpha-49198';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue