Version Description
- Tested up to WordPress 4.9.
Download this release
Release Info
Developer | kimipooh |
Plugin | WP Add Mime Types |
Version | 2.2.1 |
Comparing to | |
See all releases |
Code changes from version 2.1.3 to 2.2.1
- includes/admin.php +45 -33
- includes/network-admin.php +42 -32
- readme.txt +15 -2
- screenshot-3.png +0 -0
- wp-add-mime-types.php +39 -26
includes/admin.php
CHANGED
@@ -2,26 +2,27 @@
|
|
2 |
|
3 |
function add_to_settings_menu(){
|
4 |
$admin_permission = 'manage_options';
|
5 |
-
|
6 |
add_options_page(__('WP Add Mime Types Admin Settings', 'wp-add-mime-types'), __('Mime Type Settings','wp-add-mime-types'), $admin_permission, __FILE__,'admin_settings_page');
|
7 |
}
|
8 |
|
9 |
// Processing Setting menu for the plugin.
|
10 |
function admin_settings_page(){
|
11 |
global $plugin_basename;
|
|
|
12 |
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
$settings = get_site_option('wp_add_mime_types_network_array');
|
19 |
$past_settings = get_option('wp_add_mime_types_array');
|
20 |
}else
|
21 |
$settings = get_option('wp_add_mime_types_array');
|
22 |
|
23 |
$permission = false;
|
24 |
-
|
25 |
if(current_user_can($admin_permission)) $permission = true;
|
26 |
// If the adding data is not set, the value "mime_type_values" sets "empty".
|
27 |
if(!isset($settings['mime_type_values'])) $settings['mime_type_values'] = '';
|
@@ -29,15 +30,17 @@ function admin_settings_page(){
|
|
29 |
if(isset($_POST['mime_type_values'])){
|
30 |
$p_set = esc_attr(strip_tags(html_entity_decode($_POST['mime_type_values']),ENT_QUOTES));
|
31 |
$mime_type_values = explode("\n", $p_set);
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
// Update to WordPress Data.
|
40 |
-
|
41 |
get_site_option('wp_add_mime_types_network_array', $settings);
|
42 |
else
|
43 |
update_option('wp_add_mime_types_array', $settings);
|
@@ -58,25 +61,33 @@ function admin_settings_page(){
|
|
58 |
$allowed_mime_values = get_allowed_mime_types();
|
59 |
|
60 |
// Getting the extension name in the saved data
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
// List view of the allowed mime types including the addition (red color) in the admin settings.
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
}
|
81 |
?>
|
82 |
</table>
|
@@ -86,7 +97,8 @@ foreach($allowed_mime_values as $type=>$value){
|
|
86 |
|
87 |
<fieldset style="border:1px solid #777777; width: 750px; padding-left: 6px;">
|
88 |
<legend><h3><?php _e('Add Values','wp-add-mime-types'); ?></h3></legend>
|
89 |
-
<p><?php _e('* About the mime type value for the file extension, please search "mime type [file extension name] using a search engine.<br/>Ex. epub = application/epub+zip<br/>Reference: <a href="http://www.iana.org/assignments/media-types/media-types.xhtml" target="_blank">Media Types on the Internet Assigned Numbers Authority (IANA)</a><br/>* If the added mime type does not work, please deactivate other mime type plugins or the setting of other mime type plugins.','wp-add-mime-types');
|
|
|
90 |
<p><span style="color:red;"><?php if(is_multisite() && is_plugin_active_for_network($plugin_basename)) _e('* The site administrator cannot add the value for mime type because the multisite is enabled. <br/>Please contact the multisite administrator if you would like to add the value.','wp-add-mime-types'); ?></span></p>
|
91 |
|
92 |
<?php // If the permission is not allowed, the user can only read the setting. ?>
|
2 |
|
3 |
function add_to_settings_menu(){
|
4 |
$admin_permission = 'manage_options';
|
5 |
+
// add_options_page (Title, Setting Title, Permission, Special Definition, function name);
|
6 |
add_options_page(__('WP Add Mime Types Admin Settings', 'wp-add-mime-types'), __('Mime Type Settings','wp-add-mime-types'), $admin_permission, __FILE__,'admin_settings_page');
|
7 |
}
|
8 |
|
9 |
// Processing Setting menu for the plugin.
|
10 |
function admin_settings_page(){
|
11 |
global $plugin_basename;
|
12 |
+
$mime_type_values = false;
|
13 |
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
14 |
+
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
15 |
+
|
16 |
+
$admin_permission = 'manage_options';
|
17 |
+
// Loading the stored setting data (wp_add_mime_types_array) from WordPress database.
|
18 |
+
if(is_multisite() && is_plugin_active_for_network($plugin_basename)){
|
19 |
$settings = get_site_option('wp_add_mime_types_network_array');
|
20 |
$past_settings = get_option('wp_add_mime_types_array');
|
21 |
}else
|
22 |
$settings = get_option('wp_add_mime_types_array');
|
23 |
|
24 |
$permission = false;
|
25 |
+
// The user who can manage the WordPress option can only access the Setting menu of this plugin.
|
26 |
if(current_user_can($admin_permission)) $permission = true;
|
27 |
// If the adding data is not set, the value "mime_type_values" sets "empty".
|
28 |
if(!isset($settings['mime_type_values'])) $settings['mime_type_values'] = '';
|
30 |
if(isset($_POST['mime_type_values'])){
|
31 |
$p_set = esc_attr(strip_tags(html_entity_decode($_POST['mime_type_values']),ENT_QUOTES));
|
32 |
$mime_type_values = explode("\n", $p_set);
|
33 |
+
if(!empty($mime_type_values)){
|
34 |
+
foreach($mime_type_values as $m_type=>$m_value)
|
35 |
+
// " " is the Japanese multi-byte space. If the character is found out, it automatically change the space.
|
36 |
+
$mime_type_values[$m_type] = trim(str_replace(" ", " ", $m_value));
|
37 |
+
$settings['mime_type_values'] = serialize($mime_type_values);
|
38 |
+
}
|
39 |
+
}else
|
40 |
+
$mime_type_values = unserialize($settings['mime_type_values']);
|
41 |
+
|
42 |
// Update to WordPress Data.
|
43 |
+
if(is_multisite() && is_plugin_active_for_network($plugin_basename))
|
44 |
get_site_option('wp_add_mime_types_network_array', $settings);
|
45 |
else
|
46 |
update_option('wp_add_mime_types_array', $settings);
|
61 |
$allowed_mime_values = get_allowed_mime_types();
|
62 |
|
63 |
// Getting the extension name in the saved data
|
64 |
+
if(!empty($mime_type_values)){
|
65 |
+
foreach ($mime_type_values as $line){
|
66 |
+
$line_value = explode("=", $line);
|
67 |
+
if(count($line_value) != 2) continue;
|
68 |
+
$mimes[trim($line_value[0])] = trim($line_value[1]);
|
69 |
+
}
|
70 |
+
}
|
71 |
|
72 |
// List view of the allowed mime types including the addition (red color) in the admin settings.
|
73 |
+
if(!empty($allowed_mime_values)){
|
74 |
+
foreach($allowed_mime_values as $type=>$value){
|
75 |
+
// Escape strings
|
76 |
+
$type = wp_strip_all_tags($type);
|
77 |
+
$value = wp_strip_all_tags($value);
|
78 |
+
if(isset($mimes)){
|
79 |
+
$add_mime_type_check = "";
|
80 |
+
foreach($mimes as $a_type=>$a_value){
|
81 |
+
if(!strcmp($type, $a_type)){
|
82 |
+
$add_mime_type_check = " style='color:red;'";
|
83 |
+
break;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
echo "<tr><td$add_mime_type_check>$type</td><td$add_mime_type_check>=</td><td$add_mime_type_check>$value</td></tr>\n";
|
87 |
+
}else{
|
88 |
+
echo "<tr><td>$type</td><td>=</td><td>$value</td></tr>\n";
|
89 |
+
}
|
90 |
+
}
|
91 |
}
|
92 |
?>
|
93 |
</table>
|
97 |
|
98 |
<fieldset style="border:1px solid #777777; width: 750px; padding-left: 6px;">
|
99 |
<legend><h3><?php _e('Add Values','wp-add-mime-types'); ?></h3></legend>
|
100 |
+
<p><?php _e('* About the mime type value for the file extension, please search "mime type [file extension name] using a search engine.<br/>Ex. epub = application/epub+zip<br/>Reference: <a href="http://www.iana.org/assignments/media-types/media-types.xhtml" target="_blank">Media Types on the Internet Assigned Numbers Authority (IANA)</a><br/>* If the added mime type does not work, please deactivate other mime type plugins or the setting of other mime type plugins.','wp-add-mime-types'); ?>
|
101 |
+
<br/><?php _e('* Ignore to the right of "#" on a line. ','wp-add-mime-types'); ?></p>
|
102 |
<p><span style="color:red;"><?php if(is_multisite() && is_plugin_active_for_network($plugin_basename)) _e('* The site administrator cannot add the value for mime type because the multisite is enabled. <br/>Please contact the multisite administrator if you would like to add the value.','wp-add-mime-types'); ?></span></p>
|
103 |
|
104 |
<?php // If the permission is not allowed, the user can only read the setting. ?>
|
includes/network-admin.php
CHANGED
@@ -3,8 +3,8 @@
|
|
3 |
function network_add_to_settings_menu(){
|
4 |
global $plugin_basename;
|
5 |
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
6 |
-
|
7 |
-
|
8 |
if( ! is_multisite() || ! is_plugin_active_for_network($plugin_basename))
|
9 |
return ;
|
10 |
|
@@ -17,12 +17,13 @@ function network_add_to_settings_menu(){
|
|
17 |
// Processing Setting menu for the plugin.
|
18 |
function network_admin_settings_page(){
|
19 |
$admin_permission = 'manage_network_options';
|
|
|
20 |
|
21 |
-
|
22 |
$settings = get_site_option('wp_add_mime_types_network_array');
|
23 |
|
24 |
$permission = false;
|
25 |
-
|
26 |
if(current_user_can($admin_permission)) $permission = true;
|
27 |
// If the adding data is not set, the value "mime_type_values" sets "empty".
|
28 |
if(!isset($settings['mime_type_values'])) $settings['mime_type_values'] = '';
|
@@ -30,14 +31,15 @@ function network_admin_settings_page(){
|
|
30 |
if(isset($_POST['mime_type_values'])){
|
31 |
$p_set = esc_attr(strip_tags(html_entity_decode($_POST['mime_type_values']),ENT_QUOTES));
|
32 |
$mime_type_values = explode("\n", $p_set);
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
41 |
// Update on wp_sitemeta
|
42 |
update_site_option('wp_add_mime_types_network_array', $settings);
|
43 |
|
@@ -57,26 +59,33 @@ function network_admin_settings_page(){
|
|
57 |
$allowed_mime_values = get_allowed_mime_types();
|
58 |
|
59 |
// Getting the extension name in the saved data
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
foreach($allowed_mime_values as $type=>$value){
|
68 |
-
if(isset($mimes)){
|
69 |
-
$add_mime_type_check = "";
|
70 |
-
foreach($mimes as $a_type=>$a_value){
|
71 |
-
if(!strcmp($type, $a_type)){
|
72 |
-
$add_mime_type_check = " style='color:red;'";
|
73 |
-
break;
|
74 |
-
}
|
75 |
-
}
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
}
|
81 |
?>
|
82 |
</table>
|
@@ -86,7 +95,8 @@ foreach($allowed_mime_values as $type=>$value){
|
|
86 |
|
87 |
<fieldset style="border:1px solid #777777; width: 750px; padding-left: 6px;">
|
88 |
<legend><h3><?php _e('Add Values','wp-add-mime-types'); ?></h3></legend>
|
89 |
-
<p><?php _e('* About the mime type value for the file extension, please search "mime type [file extension name] using a search engine.<br/>Ex. epub = application/epub+zip<br/>Reference: <a href="http://www.iana.org/assignments/media-types/media-types.xhtml" target="_blank">Media Types on the Internet Assigned Numbers Authority (IANA)</a><br/>* If the added mime type does not work, please deactivate other mime type plugins or the setting of other mime type plugins.','wp-add-mime-types');
|
|
|
90 |
|
91 |
<?php // If the permission is not allowed, the user can only read the setting. ?>
|
92 |
<textarea name="mime_type_values" cols="100" rows="10" <?php if(!$permission) echo "disabled"; ?>><?php if(isset($mimes) && is_array($mimes)) foreach ($mimes as $m_type=>$m_value) echo $m_type . "\t= " .$m_value . "\n"; ?></textarea>
|
3 |
function network_add_to_settings_menu(){
|
4 |
global $plugin_basename;
|
5 |
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
6 |
+
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
7 |
+
|
8 |
if( ! is_multisite() || ! is_plugin_active_for_network($plugin_basename))
|
9 |
return ;
|
10 |
|
17 |
// Processing Setting menu for the plugin.
|
18 |
function network_admin_settings_page(){
|
19 |
$admin_permission = 'manage_network_options';
|
20 |
+
$mime_type_values = false;
|
21 |
|
22 |
+
// Loading the stored setting data (wp_add_mime_types_network_array) from WordPress database.
|
23 |
$settings = get_site_option('wp_add_mime_types_network_array');
|
24 |
|
25 |
$permission = false;
|
26 |
+
// The user who can manage the WordPress option can only access the Setting menu of this plugin.
|
27 |
if(current_user_can($admin_permission)) $permission = true;
|
28 |
// If the adding data is not set, the value "mime_type_values" sets "empty".
|
29 |
if(!isset($settings['mime_type_values'])) $settings['mime_type_values'] = '';
|
31 |
if(isset($_POST['mime_type_values'])){
|
32 |
$p_set = esc_attr(strip_tags(html_entity_decode($_POST['mime_type_values']),ENT_QUOTES));
|
33 |
$mime_type_values = explode("\n", $p_set);
|
34 |
+
if(!empty($mime_type_values)){
|
35 |
+
foreach($mime_type_values as $m_type=>$m_value)
|
36 |
+
// " " is the Japanese multi-byte space. If the character is found out, it automatically change the space.
|
37 |
+
$mime_type_values[$m_type] = trim(str_replace(" ", " ", $m_value));
|
38 |
+
$settings['mime_type_values'] = serialize($mime_type_values);
|
39 |
+
}
|
40 |
+
}else
|
41 |
+
$mime_type_values = unserialize($settings['mime_type_values']);
|
42 |
+
|
43 |
// Update on wp_sitemeta
|
44 |
update_site_option('wp_add_mime_types_network_array', $settings);
|
45 |
|
59 |
$allowed_mime_values = get_allowed_mime_types();
|
60 |
|
61 |
// Getting the extension name in the saved data
|
62 |
+
if(!empty($mime_type_values)){
|
63 |
+
foreach ($mime_type_values as $line){
|
64 |
+
$line_value = explode("=", $line);
|
65 |
+
if(count($line_value) != 2) continue;
|
66 |
+
$mimes[trim($line_value[0])] = trim($line_value[1]);
|
67 |
+
}
|
68 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
// List view of the allowed mime types including the addition (red color) in the admin settings.
|
71 |
+
if(!empty($allowed_mime_values)){
|
72 |
+
foreach($allowed_mime_values as $type=>$value){
|
73 |
+
// Escape strings
|
74 |
+
$type = wp_strip_all_tags($type);
|
75 |
+
$value = wp_strip_all_tags($value);
|
76 |
+
if(isset($mimes)){
|
77 |
+
$add_mime_type_check = "";
|
78 |
+
foreach($mimes as $a_type=>$a_value){
|
79 |
+
if(!strcmp($type, $a_type)){
|
80 |
+
$add_mime_type_check = " style='color:red;'";
|
81 |
+
break;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
echo "<tr><td$add_mime_type_check>$type</td><td$add_mime_type_check>=</td><td$add_mime_type_check>$value</td></tr>\n";
|
85 |
+
}else{
|
86 |
+
echo "<tr><td>$type</td><td>=</td><td>$value</td></tr>\n";
|
87 |
+
}
|
88 |
+
}
|
89 |
}
|
90 |
?>
|
91 |
</table>
|
95 |
|
96 |
<fieldset style="border:1px solid #777777; width: 750px; padding-left: 6px;">
|
97 |
<legend><h3><?php _e('Add Values','wp-add-mime-types'); ?></h3></legend>
|
98 |
+
<p><?php _e('* About the mime type value for the file extension, please search "mime type [file extension name] using a search engine.<br/>Ex. epub = application/epub+zip<br/>Reference: <a href="http://www.iana.org/assignments/media-types/media-types.xhtml" target="_blank">Media Types on the Internet Assigned Numbers Authority (IANA)</a><br/>* If the added mime type does not work, please deactivate other mime type plugins or the setting of other mime type plugins.','wp-add-mime-types'); ?>
|
99 |
+
<br/><?php _e('* Ignore to the right of "#" on a line. ','wp-add-mime-types'); ?></p>
|
100 |
|
101 |
<?php // If the permission is not allowed, the user can only read the setting. ?>
|
102 |
<textarea name="mime_type_values" cols="100" rows="10" <?php if(!$permission) echo "disabled"; ?>><?php if(isset($mimes) && is_array($mimes)) foreach ($mimes as $m_type=>$m_value) echo $m_type . "\t= " .$m_value . "\n"; ?></textarea>
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: Kimiya Kitani
|
3 |
Tags: mime,file extention
|
4 |
Requires at least: 3.0
|
5 |
-
Tested up to: 4.
|
6 |
-
Stable tag: 2.1
|
7 |
|
8 |
The plugin additionally allows the mime types and file extensions to WordPress.
|
9 |
|
@@ -36,6 +36,9 @@ You can see the list of allowed mime types and file extensions by WordPress.
|
|
36 |
|
37 |
== Frequently Asked Questions ==
|
38 |
|
|
|
|
|
|
|
39 |
* (Above 4.7.1) In case of custom extension in this plugins' setting, the WordPress 4.7.1 file contents check system using finfo_info function is always true.
|
40 |
|
41 |
= Cannot work =
|
@@ -57,9 +60,19 @@ Yes, each setting values are saved as the other setting items.
|
|
57 |
== Screenshots ==
|
58 |
1. Setting Menu
|
59 |
2. Setting Menu in case of the multisite
|
|
|
|
|
60 |
|
61 |
== Changelog ==
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
= 2.1.3 =
|
64 |
* Tested up to WordPress 4.8 and PHP 7.1
|
65 |
|
2 |
Contributors: Kimiya Kitani
|
3 |
Tags: mime,file extention
|
4 |
Requires at least: 3.0
|
5 |
+
Tested up to: 4.9
|
6 |
+
Stable tag: 2.2.1
|
7 |
|
8 |
The plugin additionally allows the mime types and file extensions to WordPress.
|
9 |
|
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 |
+
|
42 |
* (Above 4.7.1) In case of custom extension in this plugins' setting, the WordPress 4.7.1 file contents check system using finfo_info function is always true.
|
43 |
|
44 |
= Cannot work =
|
60 |
== Screenshots ==
|
61 |
1. Setting Menu
|
62 |
2. Setting Menu in case of the multisite
|
63 |
+
3. Ignore to the right of '#' on a line
|
64 |
+
|
65 |
|
66 |
== Changelog ==
|
67 |
|
68 |
+
= 2.2.1 =
|
69 |
+
* Tested up to WordPress 4.9.
|
70 |
+
|
71 |
+
= 2.2.0 =
|
72 |
+
* Fixed foreach function warning if a setting value is empty.
|
73 |
+
* Added to escape HTML tags in a setting value using wp_strip_all_tags function.
|
74 |
+
* Added to ignore to the right of '#' on a line.
|
75 |
+
|
76 |
= 2.1.3 =
|
77 |
* Tested up to WordPress 4.8 and PHP 7.1
|
78 |
|
screenshot-3.png
ADDED
Binary file
|
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.1
|
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.1
|
23 |
);
|
24 |
|
25 |
// Add Setting to WordPress 'Settings' menu for Multisite.
|
@@ -33,6 +33,7 @@ require_once( dirname( __FILE__ ) . '/includes/admin.php');
|
|
33 |
// Procedure for adding the mime types and file extensions to WordPress.
|
34 |
function add_allow_upload_extension( $mimes ) {
|
35 |
global $plugin_basename;
|
|
|
36 |
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
37 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
38 |
|
@@ -44,27 +45,33 @@ function add_allow_upload_extension( $mimes ) {
|
|
44 |
if(!isset($settings['mime_type_values']) || empty($settings['mime_type_values'])) return $mimes;
|
45 |
else
|
46 |
$mime_type_values = unserialize($settings['mime_type_values']);
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
}
|
59 |
|
60 |
// Register the Procedure process to WordPress.
|
61 |
add_filter( 'upload_mimes', 'add_allow_upload_extension');
|
62 |
|
63 |
-
|
64 |
// Exception for WordPress 4.7.1 file contents check system using finfo_file (wp-include/functions.php)
|
65 |
// In case of custom extension in this plugins' setting, the WordPress 4.7.1 file contents check system is always true.
|
66 |
function add_allow_upload_extension_exception( $file, $filename, $mimes ) {
|
67 |
global $plugin_basename;
|
|
|
|
|
68 |
$ext = $type = $proper_filename = false;
|
69 |
if(isset($file['ext'])) $ext = $file['ext'];
|
70 |
if(isset($file['type'])) $ext = $file['type'];
|
@@ -86,18 +93,24 @@ function add_allow_upload_extension_exception( $file, $filename, $mimes ) {
|
|
86 |
$mime_type_values = unserialize($settings['mime_type_values']);
|
87 |
|
88 |
$flag = false;
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
if($flag)
|
102 |
return compact( 'ext', 'type', 'proper_filename' );
|
103 |
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.2.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.2.1',
|
23 |
);
|
24 |
|
25 |
// Add Setting to WordPress 'Settings' menu for Multisite.
|
33 |
// Procedure for adding the mime types and file extensions to WordPress.
|
34 |
function add_allow_upload_extension( $mimes ) {
|
35 |
global $plugin_basename;
|
36 |
+
$mime_type_values = false;
|
37 |
if ( ! function_exists( 'is_plugin_active_for_network' ) )
|
38 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
39 |
|
45 |
if(!isset($settings['mime_type_values']) || empty($settings['mime_type_values'])) return $mimes;
|
46 |
else
|
47 |
$mime_type_values = unserialize($settings['mime_type_values']);
|
48 |
+
|
49 |
+
if(!empty($mime_type_values)){
|
50 |
+
foreach ((array)$mime_type_values as $line){
|
51 |
+
// Ignore to the right of '#' on a line.
|
52 |
+
$line = substr($line, 0, strcspn($line, '#'));
|
53 |
+
// Escape Strings
|
54 |
+
$line = wp_strip_all_tags($line);
|
55 |
+
// If 2 or more "=" character in the line data, it will be ignored.
|
56 |
+
$line_value = explode("=", $line);
|
57 |
+
if(count($line_value) != 2) continue;
|
58 |
+
// " " is the Japanese multi-byte space. If the character is found out, it automatically change the space.
|
59 |
+
$mimes[trim($line_value[0])] = trim(str_replace(" ", " ", $line_value[1]));
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
return $mimes;
|
64 |
}
|
65 |
|
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;
|
73 |
+
$mime_type_values = false;
|
74 |
+
|
75 |
$ext = $type = $proper_filename = false;
|
76 |
if(isset($file['ext'])) $ext = $file['ext'];
|
77 |
if(isset($file['type'])) $ext = $file['type'];
|
93 |
$mime_type_values = unserialize($settings['mime_type_values']);
|
94 |
|
95 |
$flag = false;
|
96 |
+
if(!empty($mime_type_values)){
|
97 |
+
foreach ((array)$mime_type_values as $line){
|
98 |
+
// Ignore to the right of '#' on a line.
|
99 |
+
$line = substr($line, 0, strcspn($line, '#'));
|
100 |
+
// Escape Strings
|
101 |
+
$line = wp_strip_all_tags($line);
|
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]));
|
109 |
+
$flag = true;
|
110 |
+
break;
|
111 |
+
}
|
112 |
+
}
|
113 |
+
}
|
114 |
if($flag)
|
115 |
return compact( 'ext', 'type', 'proper_filename' );
|
116 |
else
|