Skip to content

Commit

Permalink
Set correct mime type and add to allowed mime types
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-mendonca committed Feb 22, 2022
1 parent 2ce5458 commit 93c0d3b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions inc/admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function wpt_customofile_add_rule_validate( $input ) {
$input['deactivate_rule'] = isset( $input['deactivate_rule'] ) ? $input['deactivate_rule'] : null;
$input['activate_rule'] = isset( $input['activate_rule'] ) ? $input['activate_rule'] : null;
$input['delete_rule'] = isset( $input['delete_rule'] ) ? $input['delete_rule'] : null;
$input['mo'] = is_array( $input['mo'] ) ? $input['mo'] : array();
$input['mo'] = isset( $input['mo'] ) && is_array( $input['mo'] ) ? $input['mo'] : array();

$options = get_option( 'wpt_customofile_options' );

Expand All @@ -146,13 +146,15 @@ function wpt_customofile_add_rule_validate( $input ) {
if ( $input['wpt-customofile-add-rule'] && isset( $_FILES['wpt_customofile_mo_file']['name'] ) ) {

add_filter( 'upload_dir', 'wpt_customofile_filter_upload_dir' );
add_filter( 'upload_mimes', 'wpt_customofile_filter_upload_mimes' );
$mo_file = wp_handle_upload(
$_FILES['wpt_customofile_mo_file'], // phpcs:ignore
array(
'test_form' => false,
'mimes' => array( 'mo' => 'application/octet-stream' ),
'mimes' => array( 'mo' => 'application/x-gettext-translation' ),
)
);
remove_filter( 'upload_mimes', 'wpt_customofile_filter_upload_mimes' );
remove_filter( 'upload_dir', 'wpt_customofile_filter_upload_dir' );

if ( $mo_file && empty( $mo_file['error'] ) ) {
Expand Down
18 changes: 18 additions & 0 deletions inc/functions/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ function wpt_customofile_filter_upload_dir( $upload_dir ) {
}


/**
* Filter for upload mime types.
*
* @since 1.2.1
*
* @param array<mixed> $wp_get_mime_types Get upload mime types.
*
* @return array<mixed> Filtered array of upload mime types.
*/
function wpt_customofile_filter_upload_mimes( $wp_get_mime_types ) {

// Add 'mo' mime type.
$wp_get_mime_types['mo'] = 'application/x-gettext-translation';

return $wp_get_mime_types;
}


/**
* Prepare uploads folder.
* Check if folder exist and has empty index, create both if don't exist.
Expand Down

0 comments on commit 93c0d3b

Please sign in to comment.