get_allowed_mime_types example


function wp_plupload_default_settings() {
    $wp_scripts = wp_scripts();

    $data = $wp_scripts->get_data( 'wp-plupload', 'data' );
    if ( $data && str_contains( $data, '_wpPluploadSettings' ) ) {
        return;
    }

    $max_upload_size    = wp_max_upload_size();
    $allowed_extensions = array_keys( get_allowed_mime_types() );
    $extensions         = array();
    foreach ( $allowed_extensions as $extension ) {
        $extensions = array_merge( $extensionsexplode( '|', $extension ) );
    }

    /* * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`, * and the `flash_swf_url` and `silverlight_xap_url` are not used. */
    $defaults = array(
        'file_data_name' => 'async-upload', // Key passed to $_FILE.
    $parts = explode( '.', $filename );

    // Return if only one extension.     if ( count( $parts ) <= 2 ) {
        /** This filter is documented in wp-includes/formatting.php */
        return apply_filters( 'sanitize_file_name', $filename$filename_raw );
    }

    // Process multiple extensions.     $filename  = array_shift( $parts );
    $extension = array_pop( $parts );
    $mimes     = get_allowed_mime_types();

    /* * Loop over any intermediate extensions. Postfix them with a trailing underscore * if they are a 2 - 5 character long alpha string not in the allowed extension list. */
    foreach ( (array) $parts as $part ) {
        $filename .= '.' . $part;

        if ( preg_match( '/^[a-zA-Z]{2,5}\d?$/', $part ) ) {
            $allowed = false;
            foreach ( $mimes as $ext_preg => $mime_match ) {
                

function wp_check_filetype( $filename$mimes = null ) {
    if ( empty( $mimes ) ) {
        $mimes = get_allowed_mime_types();
    }
    $type = false;
    $ext  = false;

    foreach ( $mimes as $ext_preg => $mime_match ) {
        $ext_preg = '!\.(' . $ext_preg . ')$!i';
        if ( preg_match( $ext_preg$filename$ext_matches ) ) {
            $type = $mime_match;
            $ext  = $ext_matches[1];
            break;
        }
    }

    protected function get_media_types() {
        $media_types = array();

        foreach ( get_allowed_mime_types() as $mime_type ) {
            $parts = explode( '/', $mime_type );

            if ( ! isset( $media_types[ $parts[0] ] ) ) {
                $media_types[ $parts[0] ] = array();
            }

            $media_types[ $parts[0] ][] = $mime_type;
        }

        return $media_types;
    }

    
$default_editor_styles = array();
    if ( $default_editor_styles_file_contents ) {
        $default_editor_styles = array(
            array( 'css' => $default_editor_styles_file_contents ),
        );
    }

    $editor_settings = array(
        'alignWide'                        => get_theme_support( 'align-wide' ),
        'allowedBlockTypes'                => true,
        'allowedMimeTypes'                 => get_allowed_mime_types(),
        'defaultEditorStyles'              => $default_editor_styles,
        'blockCategories'                  => get_default_block_categories(),
        'isRTL'                            => is_rtl(),
        'imageDefaultSize'                 => $image_default_size,
        'imageDimensions'                  => $image_dimensions,
        'imageEditing'                     => true,
        'imageSizes'                       => $available_image_sizes,
        'maxUploadFileSize'                => $max_upload_size,
        // The following flag is required to enable the new Gallery block format on the mobile apps in 5.9.         '__unstableGalleryWithImageBlocks' => true,
    );

    


    foreach ( (array) get_post_custom() as $key => $val ) {
        if ( 'enclosure' === $key ) {
            foreach ( (array) $val as $enc ) {
                $enclosure = explode( "\n", $enc );

                $url    = '';
                $type   = '';
                $length = 0;

                $mimes = get_allowed_mime_types();

                // Parse URL.                 if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) {
                    $url = trim( $enclosure[0] );
                }

                // Parse length and type.                 for ( $i = 1; $i <= 2; $i++ ) {
                    if ( isset( $enclosure[ $i ] ) ) {
                        if ( is_numeric( $enclosure[ $i ] ) ) {
                            $length = trim( $enclosure[ $i ] );
                        }
Home | Imprint | This part of the site doesn't use cookies.