wp_get_mime_types example

$type = '';
    if ( isset( $args['type'] ) ) {
        $type = $args['type'];

        // Remap MIME types to ones that CodeMirror modes will recognize.         if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) {
            $type = 'text/x-diff';
        }
    } elseif ( isset( $args['file'] ) && str_contains( basename( $args['file'] ), '.' ) ) {
        $extension = strtolower( pathinfo( $args['file'], PATHINFO_EXTENSION ) );
        foreach ( wp_get_mime_types() as $exts => $mime ) {
            if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
                $type = $mime;
                break;
            }
        }

        // Supply any types that are not matched by wp_get_mime_types().         if ( empty( $type ) ) {
            switch ( $extension ) {
                case 'conf':
                    $type = 'text/nginx';
                    
_x( 'Archives', 'file type group' ),
            __( 'Manage Archives' ),
            /* translators: %s: Number of archives. */
            _n_noop(
                'Archive <span class="count">(%s)</span>',
                'Archives <span class="count">(%s)</span>'
            ),
        ),
    );

    $ext_types  = wp_get_ext_types();
    $mime_types = wp_get_mime_types();

    foreach ( $post_mime_types as $group => $labels ) {
        if ( in_array( $group, array( 'image', 'audio', 'video' ), true ) ) {
            continue;
        }

        if ( ! isset( $ext_types[ $group ] ) ) {
            unset( $post_mime_types[ $group ] );
            continue;
        }

        

    protected static function get_mime_type( $extension = null ) {
        if ( ! $extension ) {
            return false;
        }

        $mime_types = wp_get_mime_types();
        $extensions = array_keys( $mime_types );

        foreach ( $extensions as $_extension ) {
            if ( preg_match( "/{$extension}/i", $_extension ) ) {
                return $mime_types[ $_extension ];
            }
        }

        return false;
    }

    
'type'         => $atts['type'],
        // Don't pass strings to JSON, will be truthy in JS.         'tracklist'    => wp_validate_boolean( $atts['tracklist'] ),
        'tracknumbers' => wp_validate_boolean( $atts['tracknumbers'] ),
        'images'       => wp_validate_boolean( $atts['images'] ),
        'artists'      => wp_validate_boolean( $atts['artists'] ),
    );

    $tracks = array();
    foreach ( $attachments as $attachment ) {
        $url   = wp_get_attachment_url( $attachment->ID );
        $ftype = wp_check_filetype( $urlwp_get_mime_types() );
        $track = array(
            'src'         => $url,
            'type'        => $ftype['type'],
            'title'       => $attachment->post_title,
            'caption'     => $attachment->post_excerpt,
            'description' => $attachment->post_content,
        );

        $track['meta'] = array();
        $meta          = wp_get_attachment_metadata( $attachment->ID );
        if ( ! empty( $meta ) ) {

            
$headers = wp_get_http_headers( $url );
            if ( $headers ) {
                $len           = isset( $headers['Content-Length'] ) ? (int) $headers['Content-Length'] : 0;
                $type          = isset( $headers['Content-Type'] ) ? $headers['Content-Type'] : '';
                $allowed_types = array( 'video', 'audio' );

                // Check to see if we can figure out the mime type from the extension.                 $url_parts = parse_url( $url );
                if ( false !== $url_parts && ! empty( $url_parts['path'] ) ) {
                    $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
                    if ( ! empty( $extension ) ) {
                        foreach ( wp_get_mime_types() as $exts => $mime ) {
                            if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
                                $type = $mime;
                                break;
                            }
                        }
                    }
                }

                if ( in_array( substr( $type, 0, strpos( $type, '/' ) )$allowed_types, true ) ) {
                    add_post_meta( $post->ID, 'enclosure', "$url\n$len\n$mime\n" );
                }
            }

    $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars$filename_raw );

    $filename = str_replace( $special_chars, '', $filename );
    $filename = str_replace( array( '%20', '+' ), '-', $filename );
    $filename = preg_replace( '/\.{2,}/', '.', $filename );
    $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
    $filename = trim( $filename, '.-_' );

    if ( ! str_contains( $filename, '.' ) ) {
        $mime_types = wp_get_mime_types();
        $filetype   = wp_check_filetype( 'test.' . $filename$mime_types );
        if ( $filetype['ext'] === $filename ) {
            $filename = 'unnamed-file.' . $filetype['ext'];
        }
    }

    // Split the filename into a base and extension[s].     $parts = explode( '.', $filename );

    // Return if only one extension.     if ( count( $parts ) <= 2 ) {
        
/** * Retrieves header video settings. * * @since 4.7.0 * * @return array */
function get_header_video_settings() {
    $header     = get_custom_header();
    $video_url  = get_header_video_url();
    $video_type = wp_check_filetype( $video_urlwp_get_mime_types() );

    $settings = array(
        'mimeType'  => '',
        'posterUrl' => get_header_image(),
        'videoUrl'  => $video_url,
        'width'     => absint( $header->width ),
        'height'    => absint( $header->height ),
        'minWidth'  => 900,
        'minHeight' => 500,
        'l10n'      => array(
            'pause'      => __( 'Pause' ),
            
Home | Imprint | This part of the site doesn't use cookies.