WordPress.org

Make WordPress Core

Changeset 49198


Ignore:
Timestamp:
10/18/2020 09:04:33 PM (14 months ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r49193 r49198  
    981981    if ( ! empty( $file ) ) {
    982982
     983        $allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif' );
     984
     985        /**
     986         * Filters the list of allowed file extensions when sideloading an image from a URL.
     987         *
     988         * The default allowed extensions are:
     989         *
     990         *  - `jpg`
     991         *  - `jpeg`
     992         *  - `jpe`
     993         *  - `png`
     994         *  - `gif`
     995         *
     996         * @since 5.6.0
     997         *
     998         * @param string[] $allowed_extensions Array of allowed file extensions.
     999         * @param string   $file               The URL of the image to download.
     1000         */
     1001        $allowed_extensions = apply_filters( 'image_sideload_extensions', $allowed_extensions, $file );
     1002        $allowed_extensions = array_map( 'preg_quote', $allowed_extensions );
     1003
    9831004        // Set variables for storage, fix file filename for query strings.
    984         preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
     1005        preg_match( '/[^\?]+\.(' . implode( '|', $allowed_extensions ) . ')\b/i', $file, $matches );
    9851006
    9861007        if ( ! $matches ) {
Note: See TracChangeset for help on using the changeset viewer.