WordPress.org

Make WordPress Core

Changeset 45651


Ignore:
Timestamp:
07/17/2019 01:21:55 AM (9 months ago)
Author:
SergeyBiryukov
Message:

Media: Add "Documents", "Spreadsheets", and "Archives" groups to file type filter in Media Library.

Props zodiac1978, swissspidy, karmatosed, SergeyBiryukov.
Fixes #38195.

File:
1 edited

Legend:

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

    r45625 r45651  
    26402640 *
    26412641 * @since 2.9.0
     2642 * @since 5.3.0 Added the 'Documents', 'Spreadsheets', and 'Archives' mime type groups.
    26422643 *
    26432644 * @return array List of post mime types.
     
    26452646function get_post_mime_types() {
    26462647    $post_mime_types = array(   //  array( adj, noun )
    2647         'image' => array( __( 'Images' ), __( 'Manage Images' ), _n_noop( 'Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>' ) ),
    2648         'audio' => array( __( 'Audio' ), __( 'Manage Audio' ), _n_noop( 'Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>' ) ),
    2649         'video' => array( __( 'Video' ), __( 'Manage Video' ), _n_noop( 'Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>' ) ),
     2648        'image' => array(
     2649            __( 'Images' ),
     2650            __( 'Manage Images' ),
     2651            _n_noop( 'Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>' ),
     2652        ),
     2653        'audio' => array(
     2654            __( 'Audio' ),
     2655            __( 'Manage Audio' ),
     2656            _n_noop( 'Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>' ),
     2657        ),
     2658        'video' => array(
     2659            __( 'Video' ),
     2660            __( 'Manage Video' ),
     2661            _n_noop( 'Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>' ),
     2662        ),
     2663        'document' => array(
     2664            __( 'Documents' ),
     2665            __( 'Manage Documents' ),
     2666            _n_noop( 'Document <span class="count">(%s)</span>', 'Documents <span class="count">(%s)</span>' ),
     2667        ),
     2668        'spreadsheet' => array(
     2669            __( 'Spreadsheets' ),
     2670            __( 'Manage Spreadsheets' ),
     2671            _n_noop( 'Spreadsheet <span class="count">(%s)</span>', 'Spreadsheets <span class="count">(%s)</span>' ),
     2672        ),
     2673        'archive' => array(
     2674            __( 'Archives' ),
     2675            __( 'Manage Archives' ),
     2676            _n_noop( 'Archive <span class="count">(%s)</span>', 'Archives <span class="count">(%s)</span>' ),
     2677        ),
    26502678    );
     2679
     2680    $ext_types  = wp_get_ext_types();
     2681    $mime_types = wp_get_mime_types();
     2682
     2683    foreach ( $post_mime_types as $group => $labels ) {
     2684        if ( in_array( $group, array( 'image', 'audio', 'video' ) ) ) {
     2685            continue;
     2686        }
     2687
     2688        if ( ! isset( $ext_types[ $group ] ) ) {
     2689            unset( $post_mime_types[ $group ] );
     2690            continue;
     2691        }
     2692
     2693        $group_mime_types = array();
     2694        foreach ( $ext_types[ $group ] as $extension ) {
     2695            foreach ( $mime_types as $exts => $mime ) {
     2696                if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
     2697                    $group_mime_types[] = $mime;
     2698                    break;
     2699                }
     2700            }
     2701        }
     2702        $group_mime_types = implode( ',', array_unique( $group_mime_types ) );
     2703
     2704        $post_mime_types[ $group_mime_types ] = $labels;
     2705        unset( $post_mime_types[ $group ] );
     2706    }
    26512707
    26522708    /**
Note: See TracChangeset for help on using the changeset viewer.