Version Description
- Changed remove_underscore function name to wpaddmimetypes_remove_underscore because of the avoidance of the name conflict.
- Tested up to WordPress 5.2.2 and PHP 7.4.
Download this release
Release Info
Developer | kimipooh |
Plugin | WP Add Mime Types |
Version | 2.4.1 |
Comparing to | |
See all releases |
Code changes from version 2.3.1 to 2.4.1
- readme.txt +18 -2
- wp-add-mime-types.php +29 -5
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: Kimiya Kitani
|
|
3 |
Tags: mime,file extention
|
4 |
Requires at least: 4.0
|
5 |
Requires PHP: 5.6
|
6 |
-
Tested up to: 5.
|
7 |
-
Stable tag: 2.
|
8 |
License: GPL v2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -40,6 +40,14 @@ You can see the list of allowed mime types and file extensions by WordPress.
|
|
40 |
|
41 |
== Frequently Asked Questions ==
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
* Can I comment out in the setting value?
|
44 |
Yes. You can comment out above version 2.3.0.
|
45 |
|
@@ -69,6 +77,14 @@ Yes, each setting values are saved as the other setting items.
|
|
69 |
|
70 |
== Changelog ==
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
= 2.3.1 =
|
73 |
* Tested up to WordPress 5.2.2 and PHP 7.3.
|
74 |
|
3 |
Tags: mime,file extention
|
4 |
Requires at least: 4.0
|
5 |
Requires PHP: 5.6
|
6 |
+
Tested up to: 5.3.2
|
7 |
+
Stable tag: 2.4.1
|
8 |
License: GPL v2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
40 |
|
41 |
== Frequently Asked Questions ==
|
42 |
|
43 |
+
* Can the plugin support the multi extensions?
|
44 |
+
Yes. The function was supported by Version 2.4.0.
|
45 |
+
WordPress sanitizes the filename in case of 2 or more extensions.
|
46 |
+
ex. XXX.YYY.ZZZ --> XXX_.YYY.ZZZ.
|
47 |
+
The plugin fixes the sanitized extension when a file is uploaded in the media in case of allowed extensions.
|
48 |
+
ex. XXX.YYY.ZZZ -- sanitized --> XXX_.YYY.ZZZ -- fixed the plugin --> XXX.YYY.ZZZ
|
49 |
+
In detail, please see sanitize_file_name function in "wp-includes/formatting.php".
|
50 |
+
|
51 |
* Can I comment out in the setting value?
|
52 |
Yes. You can comment out above version 2.3.0.
|
53 |
|
77 |
|
78 |
== Changelog ==
|
79 |
|
80 |
+
= 2.4.1 =
|
81 |
+
* Changed remove_underscore function name to wpaddmimetypes_remove_underscore because of the avoidance of the name conflict.
|
82 |
+
* Tested up to WordPress 5.2.2 and PHP 7.4.
|
83 |
+
|
84 |
+
|
85 |
+
= 2.4.0 =
|
86 |
+
* Support of the multi extension. Even if the file extension is "XXX.ZZZ", "XXX.YYY.ZZZ", "AAA.XXX.YYY.ZZZ" or more, it always picks up the tail of the extensions.
|
87 |
+
|
88 |
= 2.3.1 =
|
89 |
* Tested up to WordPress 5.2.2 and PHP 7.3.
|
90 |
|
wp-add-mime-types.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: WP Add Mime Types
|
4 |
Plugin URI:
|
5 |
Description: The plugin additionally allows the mime types and file extensions to WordPress.
|
6 |
-
Version: 2.
|
7 |
Author: Kimiya Kitani
|
8 |
Author URI: http://kitaney-wordpress.blogspot.jp/
|
9 |
Text Domain: wp-add-mime-types
|
@@ -19,7 +19,7 @@ add_action('plugins_loaded', 'enable_language_translation');
|
|
19 |
$plugin_basename = plugin_basename ( __FILE__ );
|
20 |
|
21 |
$default_var = array(
|
22 |
-
'wp_add_mime_types' => '2.
|
23 |
);
|
24 |
|
25 |
// Add Setting to WordPress 'Settings' menu for Multisite.
|
@@ -66,7 +66,7 @@ function add_allow_upload_extension( $mimes ) {
|
|
66 |
// Register the Procedure process to WordPress.
|
67 |
add_filter( 'upload_mimes', 'add_allow_upload_extension');
|
68 |
|
69 |
-
// Exception for WordPress 4.7.1 file contents check system using finfo_file (wp-
|
70 |
// In case of custom extension in this plugins' setting, the WordPress 4.7.1 file contents check system is always true.
|
71 |
function add_allow_upload_extension_exception( $file, $filename, $mimes ) {
|
72 |
global $plugin_basename;
|
@@ -78,8 +78,20 @@ function add_allow_upload_extension_exception( $file, $filename, $mimes ) {
|
|
78 |
if(isset($file['proper_filename'])) $ext = $file['proper_filename'];
|
79 |
if($ext != false && $type != false) return $file;
|
80 |
|
81 |
-
|
|
|
|
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
84 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
85 |
|
@@ -102,7 +114,7 @@ function add_allow_upload_extension_exception( $file, $filename, $mimes ) {
|
|
102 |
|
103 |
$line_value = explode("=", $line);
|
104 |
if(count($line_value) != 2) continue;
|
105 |
-
// " " is the Japanese multi-byte space. If the character is found out, it automatically change the space.
|
106 |
if(trim($line_value[0]) === $f_ext){
|
107 |
$ext = $f_ext;
|
108 |
$type = trim(str_replace(" ", " ", $line_value[1]));
|
@@ -111,6 +123,18 @@ function add_allow_upload_extension_exception( $file, $filename, $mimes ) {
|
|
111 |
}
|
112 |
}
|
113 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
if($flag)
|
115 |
return compact( 'ext', 'type', 'proper_filename' );
|
116 |
else
|
3 |
Plugin Name: WP Add Mime Types
|
4 |
Plugin URI:
|
5 |
Description: The plugin additionally allows the mime types and file extensions to WordPress.
|
6 |
+
Version: 2.4.1
|
7 |
Author: Kimiya Kitani
|
8 |
Author URI: http://kitaney-wordpress.blogspot.jp/
|
9 |
Text Domain: wp-add-mime-types
|
19 |
$plugin_basename = plugin_basename ( __FILE__ );
|
20 |
|
21 |
$default_var = array(
|
22 |
+
'wp_add_mime_types' => '2.4.1',
|
23 |
);
|
24 |
|
25 |
// Add Setting to WordPress 'Settings' menu for Multisite.
|
66 |
// Register the Procedure process to WordPress.
|
67 |
add_filter( 'upload_mimes', 'add_allow_upload_extension');
|
68 |
|
69 |
+
// Exception for WordPress 4.7.1 file contents check system using finfo_file (wp-includes/functions.php)
|
70 |
// In case of custom extension in this plugins' setting, the WordPress 4.7.1 file contents check system is always true.
|
71 |
function add_allow_upload_extension_exception( $file, $filename, $mimes ) {
|
72 |
global $plugin_basename;
|
78 |
if(isset($file['proper_filename'])) $ext = $file['proper_filename'];
|
79 |
if($ext != false && $type != false) return $file;
|
80 |
|
81 |
+
// If file extension is 2 or more
|
82 |
+
$f_sp = explode(".", $mimes);
|
83 |
+
$f_exp_count = count ($f_sp);
|
84 |
|
85 |
+
// Filename type is "XXX" (There is not file extension).
|
86 |
+
if($f_exp_count <= 1){
|
87 |
+
return $file;
|
88 |
+
/* Even if the file extension is "XXX.ZZZ", "XXX.YYY.ZZZ", "AAA.XXX.YYY.ZZZ" or more, it always picks up the tail of the extensions.
|
89 |
+
*/
|
90 |
+
}else{
|
91 |
+
$f_name = $f_sp[0];
|
92 |
+
$f_ext = $f_sp[$f_exp_count - 1];
|
93 |
+
}
|
94 |
+
|
95 |
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
96 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
97 |
|
114 |
|
115 |
$line_value = explode("=", $line);
|
116 |
if(count($line_value) != 2) continue;
|
117 |
+
// " " is the Japanese multi-byte space. If the character is found out, it automatically change the space.
|
118 |
if(trim($line_value[0]) === $f_ext){
|
119 |
$ext = $f_ext;
|
120 |
$type = trim(str_replace(" ", " ", $line_value[1]));
|
123 |
}
|
124 |
}
|
125 |
}
|
126 |
+
// WordPress sanitizes the filename in case of 2 or more extensions.
|
127 |
+
// ex. XXX.YYY.ZZZ --> XXX_.YYY.ZZZ.
|
128 |
+
// The following function fixes the sanitized extension when a file is uploaded in the media in case of allowed extensions.
|
129 |
+
// ex. XXX.YYY.ZZZ -- sanitized --> XXX_.YYY.ZZZ -- fixed the plugin --> XXX.YYY.ZZZ
|
130 |
+
// In detail, please see sanitize_file_name function in "wp-includes/formatting.php".
|
131 |
+
if($f_exp_count > 2){
|
132 |
+
function wpaddmimetypes_remove_underscore($filename, $filename_raw){
|
133 |
+
return str_replace("_.", ".", $filename);
|
134 |
+
}
|
135 |
+
add_filter( 'sanitize_file_name', 'wpaddmimetypes_remove_underscore', 10, 2 );
|
136 |
+
}
|
137 |
+
|
138 |
if($flag)
|
139 |
return compact( 'ext', 'type', 'proper_filename' );
|
140 |
else
|