I needed to add some formats such as ico and svg in a part of the WordPress theme that I designed, which I did by placing the following code in the functions.php
file:
function upload( $mime_types ) {
$mime_types[ 'svg' ] = 'image/svg+xml';
$mime_types[ 'ico' ] = 'image/vnd.microsoft.icon';
return $mime_types;
}
add_filter( 'upload_mimes', 'upload', 1, 1 );
Now I want to introduce two formats .po and .mo
to WordPress for support.
My only problem is that I don't know what these two formats are and no matter what I searched for, I didn't find anything.
Does anyone know the type of these two formats?
Or can I use application/msword (.doc)
for them?
Edit:
I found the following tutorial for the .po and .mo
format, but I still couldn't find the format type:
The answer by Dyn to the question How to make a header for gettext .po files? has your answer for the
.po
file:The mime type for
.po
is: text/plain.As for the
.mo
file, this is a binary file. RFC 2046 (MIME) Part Two: Media Types says:The mime type that can be used for
.mo
is: application/octet-stream.UPDATE
It looks like there are at least two approaches you can try:
wp-config.php
I've tested both. They both work on WordPress version 6.4.
wp_check_filetype_and_ext
Nathan Johnson's answer from this question: Allow CSV files to be uploaded uses the WordPress filter hook wp_check_filetype_and_ext. The WordPress Docs for this hook say that it:
wp_check_filetype_and_ext
in addition to either the mime_types filter hook or the upload_mimes filter hook allow users with at least the Author role to upload.po
and.mo
files. You can follow Nathan Johnson's answer more closely to restrict this upload privilege to specific user roles. See code sample below.Code sample
ALLOW_UNFILTERED_UPLOADS
The
wp-config.php
update suggested under the heading Non-Image File Upload Error in this WP Engine post MIME Types in WordPress says: