WP Add Mime Types - Version 2.4.0

Version Description

  • 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.
Download this release

Release Info

Developer kimipooh
Plugin Icon wp plugin WP Add Mime Types
Version 2.4.0
Comparing to
See all releases

Code changes from version 2.2.0 to 2.4.0

Files changed (2) hide show
  1. readme.txt +27 -3
  2. wp-add-mime-types.php +29 -5
readme.txt CHANGED
@@ -1,9 +1,13 @@
1
  === WP Add Mime Types ===
2
  Contributors: Kimiya Kitani
3
  Tags: mime,file extention
4
- Requires at least: 3.0
5
- Tested up to: 4.8
6
- Stable tag: 2.2.0
 
 
 
 
7
 
8
  The plugin additionally allows the mime types and file extensions to WordPress.
9
 
@@ -36,6 +40,14 @@ You can see the list of allowed mime types and file extensions by WordPress.
36
 
37
  == Frequently Asked Questions ==
38
 
 
 
 
 
 
 
 
 
39
  * Can I comment out in the setting value?
40
  Yes. You can comment out above version 2.3.0.
41
 
@@ -65,6 +77,18 @@ Yes, each setting values are saved as the other setting items.
65
 
66
  == Changelog ==
67
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  = 2.2.0 =
69
  * Fixed foreach function warning if a setting value is empty.
70
  * Added to escape HTML tags in a setting value using wp_strip_all_tags function.
1
  === WP Add Mime Types ===
2
  Contributors: Kimiya Kitani
3
  Tags: mime,file extention
4
+ Requires at least: 4.0
5
+ Requires PHP: 5.6
6
+ Tested up to: 5.2.2
7
+ Stable tag: 2.4.0
8
+ License: GPL v2
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
 
12
  The plugin additionally allows the mime types and file extensions to WordPress.
13
 
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.0 =
81
+ * 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.
82
+
83
+ = 2.3.1 =
84
+ * Tested up to WordPress 5.2.2 and PHP 7.3.
85
+
86
+ = 2.3.0 =
87
+ * Tested up to WordPress 5.0 and PHP 7.2.
88
+
89
+ = 2.2.1 =
90
+ * Tested up to WordPress 4.9.
91
+
92
  = 2.2.0 =
93
  * Fixed foreach function warning if a setting value is empty.
94
  * Added to escape HTML tags in a setting value using wp_strip_all_tags function.
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.2.0
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.2.0',
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-include/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,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
- list($f_name,$f_ext) = explode(".", $mimes);
 
 
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.0
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.0',
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 remove_underscore($filename, $filename_raw){
133
+ return str_replace("_.", ".", $filename);
134
+ }
135
+ add_filter( 'sanitize_file_name', 'remove_underscore', 10, 2 );
136
+ }
137
+
138
  if($flag)
139
  return compact( 'ext', 'type', 'proper_filename' );
140
  else