Make WordPress Core


Ignore:
Timestamp:
12/20/2020 04:13:23 PM (3 years ago)
Author:
johnbillion
Message:

Upload: Introduce the {$action}_overrides filter that allows the overrides parameter for file uploads and file sideloads to be filtered.

The dynamic portion of the hook name, $action, refers to the post action.

Props iandunn, jakub.tyrcha, nacin, wonderboymusic, Mte90, johnbillion

Fixes #16849

File:
1 edited

Legend:

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

    r49616 r49845  
    726726 * @param string[]       $file      Reference to a single element of `$_FILES`.
    727727 *                                  Call the function once for each uploaded file.
    728  * @param string[]|false $overrides An associative array of names => values
    729  *                                  to override default variables. Default false.
     728 * @param array|false    $overrides {
     729 *     An array of override parameters for this file, or boolean false if none are provided.
     730 *
     731 *     @type callable $upload_error_handler     Function to call when there is an error during the upload process.
     732 *                                              @see wp_handle_upload_error().
     733 *     @type callable $unique_filename_callback Function to call when determining a unique file name for the file.
     734 *                                              @see wp_unique_filename().
     735 *     @type string[] $upload_error_strings     The strings that describe the error indicated in
     736 *                                              `$_FILES[{form field}]['error']`.
     737 *     @type bool     $test_form                Whether to test that the `$_POST['action]` parameter is as expected.
     738 *     @type bool     $test_size                Whether to test that the file size is greater than zero bytes.
     739 *     @type bool     $test_type                Whether to test that the mime type of the file is as expected.
     740 *     @type string[] $mimes                    Array of allowed mime types keyed by their file extension regex.
     741 * }
    730742 * @param string         $time      Time formatted in 'yyyy/mm'.
    731743 * @param string         $action    Expected value for `$_POST['action']`.
     
    746758     *
    747759     * The dynamic portion of the hook name, `$action`, refers to the post action.
     760     * Possible filter names include:
     761     *
     762     *  - `wp_handle_sideload_prefilter`
     763     *  - `wp_handle_upload_prefilter`
    748764     *
    749765     * @since 2.9.0 as 'wp_handle_upload_prefilter'.
    750766     * @since 4.0.0 Converted to a dynamic hook with `$action`.
    751767     *
    752      * @param string[] $file An array of data for a single file.
     768     * @param string[] $file An array of data for the file. Reference to a single element of `$_FILES`.
    753769     */
    754770    $file = apply_filters( "{$action}_prefilter", $file );
     771
     772    /**
     773     * Filters the override parameters for a file before it is uploaded to WordPress.
     774     *
     775     * The dynamic portion of the hook name, `$action`, refers to the post action.
     776     * Possible filter names include:
     777     *
     778     *  - `wp_handle_sideload_overrides`
     779     *  - `wp_handle_upload_overrides`
     780     *
     781     * @since 5.7.0
     782     *
     783     * @param array|false $overrides An array of override parameters for this file. Boolean false if none are
     784     *                               provided. @see _wp_handle_upload().
     785     * @param string[]    $file      An array of data for the file. Reference to a single element of `$_FILES`.
     786     */
     787    $overrides = apply_filters( "{$action}_overrides", $overrides, $file );
    755788
    756789    // You may define your own function and pass the name in $overrides['upload_error_handler'].
Note: See TracChangeset for help on using the changeset viewer.