Filter
uncanny-automator
automator_email_remote_file_extensions_identifier
Filters the allowed remote file extensions for identifying file types before saving.
add_filter( 'automator_email_remote_file_extensions_identifier', $callback, 10, 2 );
Description
Allow developers to extend the MIME type to file extension mapping used by the remote file identifier. This filter enables custom recognition of file types beyond the default set, ensuring compatibility with various remote file formats. Modify or add new MIME type entries to the provided array.
Usage
add_filter( 'automator_email_remote_file_extensions_identifier', 'your_function_name', 10, 2 );
Parameters
-
$mime_types(mixed) - This parameter is an array that maps MIME types to their corresponding file extensions.
-
$content_type(mixed) - This parameter contains an array of MIME types and their corresponding file extensions.
Return Value
The filtered value.
Examples
<?php
/**
* Add support for identifying a custom file type by its MIME type.
*
* @param array $mime_types An array of existing MIME type to extension mappings.
* @param string $content_type The MIME type of the file being identified.
*
* @return array The modified array of MIME type to extension mappings.
*/
add_filter( 'automator_email_remote_file_extensions_identifier', function( $mime_types, $content_type ) {
// Example: Add support for identifying a custom PDF format.
if ( 'application/my-custom-pdf-type' === $content_type ) {
$mime_types[ $content_type ] = 'mycpd'; // Custom extension for our PDF type
}
// Example: Remove support for a specific MIME type if needed.
if ( isset( $mime_types['application/vnd.apple.keynote'] ) ) {
// unset( $mime_types['application/vnd.apple.keynote'] );
}
return $mime_types;
}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/services/file/remote-file-extension-identifier.php:110
private function map_content_type_to_extension( $content_type ) {
$mime_types = array(
'text/plain' => 'txt', // Plain text file
'application/pdf' => 'pdf', // Portable Document Format
'application/msword' => 'doc', // Microsoft Word document
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', // Microsoft Word document (XML-based)
'application/vnd.ms-excel' => 'xls', // Microsoft Excel spreadsheet
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', // Microsoft Excel spreadsheet (XML-based)
'application/vnd.ms-powerpoint' => 'ppt', // Microsoft PowerPoint presentation
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', // Microsoft PowerPoint presentation (XML-based)
'application/vnd.oasis.opendocument.text' => 'odt', // OpenDocument text document
'application/vnd.oasis.opendocument.spreadsheet' => 'ods', // OpenDocument spreadsheet
'image/jpeg' => 'jpg', // JPEG image
'image/jpeg' => 'jpeg', // JPEG image
'image/png' => 'png', // Portable Network Graphics
'image/gif' => 'gif', // Graphics Interchange Format
'image/bmp' => 'bmp', // Bitmap image
'image/tiff' => 'tiff', // Tagged Image File Format
'application/zip' => 'zip', // Compressed archive
'application/x-rar-compressed' => 'rar', // Compressed archive
'application/x-7z-compressed' => '7z', // 7-Zip compressed archive
'audio/mpeg' => 'mp3', // MP3 audio file
'audio/wav' => 'wav', // WAV audio file
'video/mp4' => 'mp4', // MP4 video file
'video/x-msvideo' => 'avi', // AVI video file
'video/quicktime' => 'mov', // QuickTime video file
'text/csv' => 'csv', // Comma-separated values
'application/rtf' => 'rtf', // Rich Text Format
'application/x-apple-diskimage' => 'dmg', // macOS Disk Image
'application/vnd.apple.installer+xml' => 'pkg', // macOS Installer Package
'application/vnd.apple.pages' => 'pages', // Apple Pages document
'application/vnd.apple.numbers' => 'numbers', // Apple Numbers spreadsheet
'application/vnd.apple.keynote' => 'key', // Apple Keynote presentation
);
// Allow plugin users to identify other file extensions.
$mime_types = apply_filters( 'automator_email_remote_file_extensions_identifier', $mime_types, $content_type );
return isset( $mime_types[ $content_type ] ) ? $mime_types[ $content_type ] : '';
}