Make WordPress Core

Ticket #32544: 32544.diff

File 32544.diff, 2.5 KB (added by octalmage, 8 years ago)
  • src/wp-includes/functions.php

     
    24692469 * @return array Array of mime types keyed by the file extension regex corresponding
    24702470 *               to those types.
    24712471 */
    2472 function get_allowed_mime_types( $user = null ) {
     2472function get_allowed_mime_types( $user = null , $ignore_user = false ) {
    24732473        $t = wp_get_mime_types();
    24742474
    24752475        unset( $t['swf'], $t['exe'] );
     
    24842484         *
    24852485         * @since 2.0.0
    24862486         *
    2487          * @param array            $t    Mime types keyed by the file extension regex corresponding to
    2488          *                               those types. 'swf' and 'exe' removed from full list. 'htm|html' also
    2489          *                               removed depending on '$user' capabilities.
    2490          * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
     2487         * @param array            $t           Mime types keyed by the file extension regex corresponding to
     2488         *                                      those types. 'swf' and 'exe' removed from full list. 'htm|html' also
     2489         *                                      removed depending on '$user' capabilities.
     2490         * @param int|WP_User|null $user        User ID, User object or null if not provided (indicates current user).
     2491         *
     2492         * @param bool             $ignore_user An override flag to return all possible mime types regardless of user.
    24912493         */
    2492         return apply_filters( 'upload_mimes', $t, $user );
     2494        return apply_filters( 'upload_mimes', $t, $user, $ignore_user );
    24932495}
    24942496
    24952497/**
  • tests/phpunit/tests/functions.php

     
    408408        }
    409409
    410410        /**
     411         * @ticket 32544
     412         */
     413        function test_get_allowed_mime_types_all() {
     414                add_filter( 'upload_mimes', array( $this, 'whitelist_test_mime_type_ignore' ), 10, 3 );
     415                $all_mimes = get_allowed_mime_types( null, true );
     416                $this->assertArrayHasKey( 'test', $all_mimes );
     417
     418                $mimes = get_allowed_mime_types();
     419                $this->assertArrayNotHasKey( 'test', $mimes );
     420        }
     421
     422        public function whitelist_test_mime_type_ignore( $mimes, $user_id, $ignore_user ) {
     423                $mime_types = array( 'test' => 'text/test' );
     424                if ( $ignore_user ) {
     425                        $mimes = array_merge( $mime_types, $mimes );
     426                }
     427                return $mimes;
     428        }
     429
     430        /**
    411431         * @ticket 23688
    412432         */
    413433        function test_canonical_charset() {