The image_editor_default_mime_type WordPress PHP Filter allows you to modify the default mime type before getting the file extension.
Usage
add_filter('image_editor_default_mime_type', 'custom_image_editor_default_mime_type', 10, 1);
function custom_image_editor_default_mime_type($mime_type) {
// your custom code here
return $mime_type;
}
Parameters
$mime_type(string) – Mime type string.
More information
See WordPress Developer Resources: image_editor_default_mime_type
Examples
Change Default Mime Type to PNG
Change the default mime type to “image/png” for the image editor.
add_filter('image_editor_default_mime_type', 'change_default_mime_type_to_png', 10, 1);
function change_default_mime_type_to_png($mime_type) {
$mime_type = 'image/png';
return $mime_type;
}
Force SVG Mime Type
Force the SVG mime type for the image editor.
add_filter('image_editor_default_mime_type', 'force_svg_mime_type', 10, 1);
function force_svg_mime_type($mime_type) {
$mime_type = 'image/svg+xml';
return $mime_type;
}
Allow WebP Mime Type
Allow the WebP mime type for the image editor.
add_filter('image_editor_default_mime_type', 'allow_webp_mime_type', 10, 1);
function allow_webp_mime_type($mime_type) {
$mime_type = 'image/webp';
return $mime_type;
}
Change Mime Type Based on User Role
Change the default mime type based on the current user’s role.
add_filter('image_editor_default_mime_type', 'change_mime_type_based_on_user_role', 10, 1);
function change_mime_type_based_on_user_role($mime_type) {
$user = wp_get_current_user();
if (in_array('administrator', $user->roles)) {
$mime_type = 'image/png';
} else {
$mime_type = 'image/jpeg';
}
return $mime_type;
}
Add Custom Mime Type for Custom Image Format
Add a custom mime type for a custom image format.
add_filter('image_editor_default_mime_type', 'add_custom_mime_type', 10, 1);
function add_custom_mime_type($mime_type) {
$mime_type = 'image/my-custom-format';
return $mime_type;
}