WP_Image_Editor::get_mime_type() WordPress Method

The WP_Image_Editor::get_mime_type() function is used to get the mime type of an image. This function can be used to check the mime type of an image before uploading it to a server.

WP_Image_Editor::get_mime_type( string $extension = null ) #

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


Parameters

$extension

(string)(Optional)

Default value: null


Top ↑

Return

(string|false)


Top ↑

Source

File: wp-includes/class-wp-image-editor.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.