Make WordPress Core

Ticket #32544: 32544.1.3.patch

File 32544.1.3.patch, 3.1 KB (added by hozayx, 7 weeks ago)
  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 67544bc..0c3334b 100644
    a b function wp_filesize( $path ) { 
    35983598 * Retrieves the list of allowed mime types and file extensions.
    35993599 *
    36003600 * @since 2.8.6
     3601 * @since 6.7 Added the `$ignore_user` parameter to return all possible mime types regardless of user.
    36013602 *
    3602  * @param int|WP_User $user Optional. User to check. Defaults to current user.
    3603  * @return string[] Array of mime types keyed by the file extension regex corresponding
     3603 * @param int|WP_User   $user                   Optional. User to check. Defaults to current user.
     3604 * @param bool                  $ignore_user    Optional. An override flag to return all possible mime types regardless of user.
     3605 * @return string[]     Array of mime types keyed by the file extension regex corresponding
    36043606 *                  to those types.
    36053607 */
    3606 function get_allowed_mime_types( $user = null ) {
     3608function get_allowed_mime_types( $user = null, $ignore_user = false ) {
    36073609        $t = wp_get_mime_types();
    36083610
    36093611        unset( $t['swf'], $t['exe'] );
    function get_allowed_mime_types( $user = null ) { 
    36163618        }
    36173619
    36183620        /**
    3619          * Filters the list of allowed mime types and file extensions.
    3620          *
    3621          * @since 2.0.0
    3622          *
    3623          * @param array            $t    Mime types keyed by the file extension regex corresponding to those types.
    3624          * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
     3621        * @param array            $t           Mime types keyed by the file extension regex corresponding to
     3622        *                                      those types. 'swf' and 'exe' removed from full list. 'htm|html' also
     3623        *                                      removed depending on '$user' capabilities.
     3624        * @param int|WP_User|null $user        User ID, User object or null if not provided (indicates current user).
     3625        *
     3626        * @param bool             $ignore_user An override flag to return all possible mime types regardless of user.
     3627        *
    36253628         */
    3626         return apply_filters( 'upload_mimes', $t, $user );
     3629        return apply_filters( 'upload_mimes', $t, $user, $ignore_user );
    36273630}
    36283631
    36293632/**
  • tests/phpunit/tests/functions.php

    diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php
    index 9d3260a..1a539d6 100644
    a b class Tests_Functions extends WP_UnitTestCase { 
    22182218                );
    22192219                $this->assertSameSetsWithIndex( $theme_json, $expected_theme_json );
    22202220        }
     2221
     2222        /**
     2223        * @ticket 32544
     2224        */
     2225        function test_get_allowed_mime_types_all() {
     2226                add_filter( 'upload_mimes', array( $this, 'add_mime_type_for_all_mime_test' ), 10, 3 );
     2227                $all_mimes = get_allowed_mime_types( null, true );
     2228                $this->assertArrayHasKey( 'test', $all_mimes );
     2229               
     2230                $mimes = get_allowed_mime_types();
     2231                $this->assertArrayNotHasKey( 'test', $mimes );
     2232        }
     2233
     2234        public function add_mime_type_for_all_mime_test( $mimes, $user_id, $ignore_user ) {
     2235                $mime_types = array( 'test' => 'text/test' );
     2236                if ( $ignore_user ) {
     2237                        $mimes = array_merge( $mime_types, $mimes );
     2238                }
     2239                return $mimes;
     2240        }
    22212241}