WP_Image_Editor::get_mime_type()protected staticWP 3.5.0

Returns first matched mime-type from extension, as mapped from wp_get_mime_types()

Method of the class: WP_Image_Editor{}

No Hooks.

Return

String|false.

Usage

$result = WP_Image_Editor::get_mime_type( $extension );
$extension(string)
-
Default: null

Changelog

Since 3.5.0 Introduced.

WP_Image_Editor::get_mime_type() code WP 6.6.2

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;
}