WP Add Mime Types - Version 2.5.4

Version Description

  • Added the function for removing this plugin's settings in the database when this plugin is uninstall.
  • Fixed the function names for not influencing the function name for other plugins.
Download this release

Release Info

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

Code changes from version 2.5.3 to 2.5.4

includes/admin.php CHANGED
@@ -1,25 +1,22 @@
1
  <?php
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
-
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.
@@ -60,12 +57,12 @@ function admin_settings_page(){
60
  }
61
  }
62
  // Update to WordPress Data.
63
- if(is_multisite() && is_plugin_active_for_network($plugin_basename))
64
- get_site_option('wp_add_mime_types_network_array', $settings);
65
  else{
66
  if(isset($_POST["wamt-form"]) && $_POST["wamt-form"])
67
  if(check_admin_referer("wamt-nonce-key", "wamt-form"))
68
- update_option('wp_add_mime_types_array', $settings);
69
  }
70
 
71
  ?>
@@ -73,7 +70,7 @@ function admin_settings_page(){
73
 
74
  <div id="add_mime_media_admin_menu">
75
  <h2><?php _e('WP Add Mime Types Admin Settings', 'wp-add-mime-types'); ?></h2>
76
-
77
  <form method="post" action="">
78
  <?php // for CSRF (Cross-Site Request Forgery): https://propansystem.net/blog/2018/02/20/post-6279/
79
  wp_nonce_field("wamt-nonce-key", "wamt-form"); ?>
@@ -123,16 +120,16 @@ if(!empty($allowed_mime_values)){
123
  <fieldset style="border:1px solid #777777; width: 750px; padding-left: 6px; padding-bottom: 1em;">
124
  <legend><h3><?php _e('Security Options','wp-add-mime-types'); ?></h3></legend>
125
  <?php _e('* The plugin avoids some security checks by WordPress core. If you do not want to avoid them, please turn on the following setting.','wp-add-mime-types'); ?></p>
126
- <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>
127
 
128
  <?php // ?>
129
  <p>
130
  <input type="hidden" name="security_attempt_enable" value="no" />
131
- <input type="checkbox" name="security_attempt_enable" value="yes" <?php if( isset($settings['security_attempt_enable']) && $settings['security_attempt_enable'] === "yes" ) echo "checked"; ?> <?php if(!$permission || (is_multisite() && is_plugin_active_for_network($plugin_basename))) echo "disabled"; ?>/> <?php _e('Enable the attempt to determine the real file type of a file by WordPress core.','wp-add-mime-types'); ?>
132
  </p>
133
  <p>
134
  <input type="hidden" name="filename_sanitized_enable" value="no" />
135
- <input type="checkbox" name="filename_sanitized_enable" value="yes" <?php if( isset($settings['filename_sanitized_enable']) && $settings['filename_sanitized_enable'] === "yes" ) echo "checked"; ?> <?php if(!$permission || (is_multisite() && is_plugin_active_for_network($plugin_basename))) echo "disabled"; ?>/> <?php _e('Enable to sanitize the multiple file extensions within the filename by WordPress core.','wp-add-mime-types'); ?>
136
  </p>
137
  </fieldset>
138
 
@@ -140,10 +137,10 @@ if(!empty($allowed_mime_values)){
140
  <legend><h3><?php _e('Add Values','wp-add-mime-types'); ?></h3></legend>
141
  <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'); ?>
142
  <br/><?php _e('* Ignore to the right of "#" on a line. ','wp-add-mime-types'); ?></p>
143
- <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>
144
 
145
  <?php // If the permission is not allowed, the user can only read the setting. ?>
146
- <textarea name="mime_type_values" cols="100" rows="10" <?php if(!$permission || (is_multisite() && is_plugin_active_for_network($plugin_basename))) echo "disabled"; ?>><?php if(isset($mimes) && is_array($mimes)) foreach ($mimes as $m_type=>$m_value) echo $m_type . "\t= " .$m_value . "\n"; ?></textarea>
147
  </fieldset>
148
 
149
  <?php
1
  <?php
2
+ function wamt_add_to_settings_menu(){
 
3
  $admin_permission = 'manage_options';
4
  // add_options_page (Title, Setting Title, Permission, Special Definition, function name);
5
+ add_options_page(__('WP Add Mime Types Admin Settings', 'wp-add-mime-types'), __('Mime Type Settings','wp-add-mime-types'), $admin_permission, __FILE__, 'wamt_admin_settings_page');
6
  }
7
 
8
  // Processing Setting menu for the plugin.
9
+ function wamt_admin_settings_page(){
 
 
10
  if ( ! function_exists( 'is_plugin_active_for_network' ) )
11
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
12
 
13
  $admin_permission = 'manage_options';
14
  // Loading the stored setting data (wp_add_mime_types_array) from WordPress database.
15
+ if(is_multisite() && is_plugin_active_for_network(WAMT_PLUGIN_BASENAME)){
16
+ $settings = get_site_option(WAMT_SITEADMIN_SETTING_FILE);
17
+ $past_settings = get_option(WAMT_SETTING_FILE);
18
  }else
19
+ $settings = get_option(WAMT_SETTING_FILE);
20
 
21
  $permission = false;
22
  // The user who can manage the WordPress option can only access the Setting menu of this plugin.
57
  }
58
  }
59
  // Update to WordPress Data.
60
+ if(is_multisite() && is_plugin_active_for_network(WAMT_PLUGIN_BASENAME))
61
+ get_site_option(WAMT_SITEADMIN_SETTING_FILE, $settings);
62
  else{
63
  if(isset($_POST["wamt-form"]) && $_POST["wamt-form"])
64
  if(check_admin_referer("wamt-nonce-key", "wamt-form"))
65
+ update_option(WAMT_SETTING_FILE, $settings);
66
  }
67
 
68
  ?>
70
 
71
  <div id="add_mime_media_admin_menu">
72
  <h2><?php _e('WP Add Mime Types Admin Settings', 'wp-add-mime-types'); ?></h2>
73
+
74
  <form method="post" action="">
75
  <?php // for CSRF (Cross-Site Request Forgery): https://propansystem.net/blog/2018/02/20/post-6279/
76
  wp_nonce_field("wamt-nonce-key", "wamt-form"); ?>
120
  <fieldset style="border:1px solid #777777; width: 750px; padding-left: 6px; padding-bottom: 1em;">
121
  <legend><h3><?php _e('Security Options','wp-add-mime-types'); ?></h3></legend>
122
  <?php _e('* The plugin avoids some security checks by WordPress core. If you do not want to avoid them, please turn on the following setting.','wp-add-mime-types'); ?></p>
123
+ <p><span style="color:red;"><?php if(is_multisite() && is_plugin_active_for_network(WAMT_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>
124
 
125
  <?php // ?>
126
  <p>
127
  <input type="hidden" name="security_attempt_enable" value="no" />
128
+ <input type="checkbox" name="security_attempt_enable" value="yes" <?php if( isset($settings['security_attempt_enable']) && $settings['security_attempt_enable'] === "yes" ) echo "checked"; ?> <?php if(!$permission || (is_multisite() && is_plugin_active_for_network(WAMT_PLUGIN_BASENAME))) echo "disabled"; ?>/> <?php _e('Enable the attempt to determine the real file type of a file by WordPress core.','wp-add-mime-types'); ?>
129
  </p>
130
  <p>
131
  <input type="hidden" name="filename_sanitized_enable" value="no" />
132
+ <input type="checkbox" name="filename_sanitized_enable" value="yes" <?php if( isset($settings['filename_sanitized_enable']) && $settings['filename_sanitized_enable'] === "yes" ) echo "checked"; ?> <?php if(!$permission || (is_multisite() && is_plugin_active_for_network(WAMT_PLUGIN_BASENAME))) echo "disabled"; ?>/> <?php _e('Enable to sanitize the multiple file extensions within the filename by WordPress core.','wp-add-mime-types'); ?>
133
  </p>
134
  </fieldset>
135
 
137
  <legend><h3><?php _e('Add Values','wp-add-mime-types'); ?></h3></legend>
138
  <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'); ?>
139
  <br/><?php _e('* Ignore to the right of "#" on a line. ','wp-add-mime-types'); ?></p>
140
+ <p><span style="color:red;"><?php if(is_multisite() && is_plugin_active_for_network(WAMT_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>
141
 
142
  <?php // If the permission is not allowed, the user can only read the setting. ?>
143
+ <textarea name="mime_type_values" cols="100" rows="10" <?php if(!$permission || (is_multisite() && is_plugin_active_for_network(WAMT_PLUGIN_BASENAME))) echo "disabled"; ?>><?php if(isset($mimes) && is_array($mimes)) foreach ($mimes as $m_type=>$m_value) echo $m_type . "\t= " .$m_value . "\n"; ?></textarea>
144
  </fieldset>
145
 
146
  <?php
includes/network-admin.php CHANGED
@@ -1,24 +1,22 @@
1
  <?php
2
-
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
 
11
  $admin_permission = 'manage_network_options';
12
 
13
  // add_options_page (Title, Setting Title, Permission, Special Definition, function name);
14
- add_submenu_page( 'settings.php', __('WP Add Mime Types Admin Settings for Network Administrator', 'wp-add-mime-types'), __('Mime Type Settings','wp-add-mime-types'), $admin_permission, __FILE__,'network_admin_settings_page');
15
  }
16
 
17
  // Processing Setting menu for the plugin.
18
- function network_admin_settings_page(){
19
  $admin_permission = 'manage_network_options';
20
  // Loading the stored setting data (wp_add_mime_types_network_array) from WordPress database.
21
- $settings = get_site_option('wp_add_mime_types_network_array');
22
 
23
  $permission = false;
24
  // The user who can manage the WordPress option can only access the Setting menu of this plugin.
@@ -57,7 +55,7 @@ function network_admin_settings_page(){
57
  }
58
 
59
  // Update on wp_sitemeta
60
- update_site_option('wp_add_mime_types_network_array', $settings);
61
  }
62
  }
63
 
@@ -66,7 +64,7 @@ function network_admin_settings_page(){
66
 
67
  <div id="network_add_mime_media_admin_menu">
68
  <h2><?php _e('WP Add Mime Types Admin Settings for Network Administrator', 'wp-add-mime-types'); ?></h2>
69
-
70
  <form method="post" action="">
71
  <?php // for CSRF (Cross-Site Request Forgery): https://propansystem.net/blog/2018/02/20/post-6279/
72
  wp_nonce_field("wamt-network-nonce-key", "wamt-network-form"); ?>
@@ -116,16 +114,15 @@ if(!empty($allowed_mime_values)){
116
  <fieldset style="border:1px solid #777777; width: 750px; padding-left: 6px; padding-bottom: 1em;">
117
  <legend><h3><?php _e('Security Options','wp-add-mime-types'); ?></h3></legend>
118
  <?php _e('* The plugin avoids some security checks by WordPress core. If you do not want to avoid them, please turn on the following setting.','wp-add-mime-types'); ?></p>
119
- <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>
120
 
121
  <?php // ?>
122
  <p>
123
  <input type="hidden" name="security_attempt_enable" value="no" />
124
- <input type="checkbox" name="security_attempt_enable" value="yes" <?php if( isset($settings['security_attempt_enable']) && $settings['security_attempt_enable'] === "yes" ) echo "checked"; ?> <?php if(!$permission || (is_multisite() && is_plugin_active_for_network($plugin_basename))) echo "disabled"; ?>/> <?php _e('Enable the attempt to determine the real file type of a file by WordPress core.','wp-add-mime-types'); ?>
125
  </p>
126
  <p>
127
  <input type="hidden" name="filename_sanitized_enable" value="no" />
128
- <input type="checkbox" name="filename_sanitized_enable" value="yes" <?php if( isset($settings['filename_sanitized_enable']) && $settings['filename_sanitized_enable'] === "yes" ) echo "checked"; ?> <?php if(!$permission || (is_multisite() && is_plugin_active_for_network($plugin_basename))) echo "disabled"; ?>/> <?php _e('Enable to sanitize the multiple file extensions within the filename by WordPress core.','wp-add-mime-types'); ?>
129
  </p>
130
  </fieldset>
131
 
1
  <?php
2
+ function wamt_network_add_to_settings_menu(){
 
 
3
  if ( ! function_exists( 'is_plugin_active_for_network' ) )
4
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
5
 
6
+ if( ! is_multisite() || ! is_plugin_active_for_network(WAMT_PLUGIN_BASENAME))
7
  return ;
8
 
9
  $admin_permission = 'manage_network_options';
10
 
11
  // add_options_page (Title, Setting Title, Permission, Special Definition, function name);
12
+ add_submenu_page( 'settings.php', __('WP Add Mime Types Admin Settings for Network Administrator', 'wp-add-mime-types'), __('Mime Type Settings','wp-add-mime-types'), $admin_permission, __FILE__, 'wamt_network_admin_settings_page');
13
  }
14
 
15
  // Processing Setting menu for the plugin.
16
+ function wamt_network_admin_settings_page(){
17
  $admin_permission = 'manage_network_options';
18
  // Loading the stored setting data (wp_add_mime_types_network_array) from WordPress database.
19
+ $settings = get_site_option(WAMT_SITEADMIN_SETTING_FILE);
20
 
21
  $permission = false;
22
  // The user who can manage the WordPress option can only access the Setting menu of this plugin.
55
  }
56
 
57
  // Update on wp_sitemeta
58
+ update_site_option(WAMT_SITEADMIN_SETTING_FILE, $settings);
59
  }
60
  }
61
 
64
 
65
  <div id="network_add_mime_media_admin_menu">
66
  <h2><?php _e('WP Add Mime Types Admin Settings for Network Administrator', 'wp-add-mime-types'); ?></h2>
67
+
68
  <form method="post" action="">
69
  <?php // for CSRF (Cross-Site Request Forgery): https://propansystem.net/blog/2018/02/20/post-6279/
70
  wp_nonce_field("wamt-network-nonce-key", "wamt-network-form"); ?>
114
  <fieldset style="border:1px solid #777777; width: 750px; padding-left: 6px; padding-bottom: 1em;">
115
  <legend><h3><?php _e('Security Options','wp-add-mime-types'); ?></h3></legend>
116
  <?php _e('* The plugin avoids some security checks by WordPress core. If you do not want to avoid them, please turn on the following setting.','wp-add-mime-types'); ?></p>
 
117
 
118
  <?php // ?>
119
  <p>
120
  <input type="hidden" name="security_attempt_enable" value="no" />
121
+ <input type="checkbox" name="security_attempt_enable" value="yes" <?php if( isset($settings['security_attempt_enable']) && $settings['security_attempt_enable'] === "yes" ) echo "checked"; ?> <?php if(!$permission) echo "disabled"; ?>/> <?php _e('Enable the attempt to determine the real file type of a file by WordPress core.','wp-add-mime-types'); ?>
122
  </p>
123
  <p>
124
  <input type="hidden" name="filename_sanitized_enable" value="no" />
125
+ <input type="checkbox" name="filename_sanitized_enable" value="yes" <?php if( isset($settings['filename_sanitized_enable']) && $settings['filename_sanitized_enable'] === "yes" ) echo "checked"; ?> <?php if(!$permission) echo "disabled"; ?>/> <?php _e('Enable to sanitize the multiple file extensions within the filename by WordPress core.','wp-add-mime-types'); ?>
126
  </p>
127
  </fieldset>
128
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.5.3
8
  License: GPL v2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -79,6 +79,10 @@ Yes, each setting values are saved as the other setting items.
79
 
80
  == Changelog ==
81
 
 
 
 
 
82
  = 2.5.3 =
83
  * Fixed the issue of "Undefined variable: f_exp_more2_flag" warning.
84
 
4
  Requires at least: 4.0
5
  Requires PHP: 5.6
6
  Tested up to: 5.3.2
7
+ Stable tag: 2.5.4
8
  License: GPL v2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
79
 
80
  == Changelog ==
81
 
82
+ = 2.5.4 =
83
+ * Added the function for removing this plugin's settings in the database when this plugin is uninstall.
84
+ * Fixed the function names for not influencing the function name for other plugins.
85
+
86
  = 2.5.3 =
87
  * Fixed the issue of "Undefined variable: f_exp_more2_flag" warning.
88
 
wp-add-mime-types.php CHANGED
@@ -3,45 +3,55 @@
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.5.3
7
  Author: Kimiya Kitani
8
  Author URI: http://kitaney-wordpress.blogspot.jp/
9
  Text Domain: wp-add-mime-types
10
  Domain Path: /lang
11
  */
 
 
 
 
 
 
12
 
13
- // Multi-language support.
14
- function enable_language_translation(){
15
- load_plugin_textdomain('wp-add-mime-types', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/');
16
- }
17
- add_action('plugins_loaded', 'enable_language_translation');
18
 
19
- $plugin_basename = plugin_basename ( __FILE__ );
 
 
 
 
 
 
 
20
 
21
- $default_var = array(
22
- 'wp_add_mime_types' => '2.5.3',
23
- );
 
 
 
24
 
25
  // Add Setting to WordPress 'Settings' menu for Multisite.
26
  if(is_multisite()){
27
- add_action('network_admin_menu', 'network_add_to_settings_menu');
28
  require_once( dirname( __FILE__ ) . '/includes/network-admin.php');
29
  }
30
- add_action('admin_menu', 'add_to_settings_menu');
31
- require_once( dirname( __FILE__ ) . '/includes/admin.php');
32
 
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
 
38
  if ( ! function_exists( 'is_plugin_active_for_network' ) )
39
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
40
 
41
- if(is_multisite() && is_plugin_active_for_network($plugin_basename))
42
- $settings = get_site_option('wp_add_mime_types_network_array');
43
  else
44
- $settings = get_option('wp_add_mime_types_array');
45
 
46
  if(!isset($settings['mime_type_values']) || empty($settings['mime_type_values'])) return $mimes;
47
  else
@@ -65,22 +75,21 @@ function add_allow_upload_extension( $mimes ) {
65
  }
66
 
67
  // Register the Procedure process to WordPress.
68
- add_filter( 'upload_mimes', 'add_allow_upload_extension');
69
 
70
  // Using in add_allow_upload_extension_exception function.
71
- function wpaddmimetypes_remove_underscore($filename, $filename_raw){
72
  return str_replace("_.", ".", $filename);
73
  }
74
  // Exception for WordPress 4.7.1 file contents check system using finfo_file (wp-includes/functions.php)
75
  // In case of custom extension in this plugins' setting, the WordPress 4.7.1 file contents check system is always true.
76
- function add_allow_upload_extension_exception( $data, $file, $filename,$mimes,$real_mime) {
77
- global $plugin_basename;
78
  $mime_type_values = false;
79
 
80
- if(is_multisite() && is_plugin_active_for_network($plugin_basename))
81
- $settings = get_site_option('wp_add_mime_types_network_array');
82
  else
83
- $settings = get_option('wp_add_mime_types_array');
84
 
85
  if ( ! function_exists( 'is_plugin_active_for_network' ) )
86
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
@@ -116,7 +125,7 @@ function add_allow_upload_extension_exception( $data, $file, $filename,$mimes,$r
116
  //var_dump($settings['filename_sanitized_enable']);
117
  if(isset($settings['filename_sanitized_enable']) && $settings['filename_sanitized_enable'] === "yes"){
118
  }else{
119
- add_filter( 'sanitize_file_name', 'wpaddmimetypes_remove_underscore', 10, 2 );
120
  }
121
  }
122
 
@@ -151,4 +160,4 @@ function add_allow_upload_extension_exception( $data, $file, $filename,$mimes,$r
151
  return $data;
152
  }
153
 
154
- add_filter( 'wp_check_filetype_and_ext', 'add_allow_upload_extension_exception',10,5);
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.5.4
7
  Author: Kimiya Kitani
8
  Author URI: http://kitaney-wordpress.blogspot.jp/
9
  Text Domain: wp-add-mime-types
10
  Domain Path: /lang
11
  */
12
+ define('WAMT_DEFAULT_VAR', '2.5.4');
13
+ define('WAMT_PLUGIN_DIR', 'wp-add-mime-types');
14
+ define('WAMT_PLUGIN_NAME', 'wp-add-mime-types');
15
+ define('WAMT_PLUGIN_BASENAME', WAMT_PLUGIN_DIR . '/' . WAMT_PLUGIN_NAME . '.php');
16
+ define('WAMT_SITEADMIN_SETTING_FILE', 'wp_add_mime_types_network_array');
17
+ define('WAMT_SETTING_FILE', 'wp_add_mime_types_array');
18
 
19
+ require_once( dirname( __FILE__ ) . '/includes/admin.php');
 
 
 
 
20
 
21
+ // Uninstall settings when the plugin is uninstalled.
22
+ function wamt_uninstaller(){
23
+ if(is_multisite())
24
+ delete_site_option(WAMT_SITEADMIN_SETTING_FILE);
25
+ delete_option(WAMT_SETTING_FILE);
26
+ }
27
+ if ( function_exists('register_uninstall_hook') )
28
+ register_uninstall_hook( __FILE__, 'wamt_uninstaller' );
29
 
30
+ // Multi-language support.
31
+ function wamt_enable_language_translation(){
32
+ load_plugin_textdomain('wp-add-mime-types')
33
+ or load_plugin_textdomain('wp-add-mime-types', false, dirname( WAMT_PLUGIN_BASENAME ) . '/lang/');
34
+ }
35
+ add_action('plugins_loaded', 'wamt_enable_language_translation');
36
 
37
  // Add Setting to WordPress 'Settings' menu for Multisite.
38
  if(is_multisite()){
39
+ add_action('network_admin_menu', 'wamt_network_add_to_settings_menu');
40
  require_once( dirname( __FILE__ ) . '/includes/network-admin.php');
41
  }
42
+ add_action('admin_menu', 'wamt_add_to_settings_menu');
 
43
 
44
  // Procedure for adding the mime types and file extensions to WordPress.
45
+ function wamt_add_allow_upload_extension( $mimes ) {
 
46
  $mime_type_values = false;
47
 
48
  if ( ! function_exists( 'is_plugin_active_for_network' ) )
49
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
50
 
51
+ if(is_multisite() && is_plugin_active_for_network(WAMT_PLUGIN_BASENAME))
52
+ $settings = get_site_option(WAMT_SITEADMIN_SETTING_FILE);
53
  else
54
+ $settings = get_option(WAMT_SETTING_FILE);
55
 
56
  if(!isset($settings['mime_type_values']) || empty($settings['mime_type_values'])) return $mimes;
57
  else
75
  }
76
 
77
  // Register the Procedure process to WordPress.
78
+ add_filter( 'upload_mimes', 'wamt_add_allow_upload_extension');
79
 
80
  // Using in add_allow_upload_extension_exception function.
81
+ function wamt_remove_underscore($filename, $filename_raw){
82
  return str_replace("_.", ".", $filename);
83
  }
84
  // Exception for WordPress 4.7.1 file contents check system using finfo_file (wp-includes/functions.php)
85
  // In case of custom extension in this plugins' setting, the WordPress 4.7.1 file contents check system is always true.
86
+ function wamt_add_allow_upload_extension_exception( $data, $file, $filename,$mimes,$real_mime) {
 
87
  $mime_type_values = false;
88
 
89
+ if(is_multisite() && is_plugin_active_for_network(WAMT_PLUGIN_BASENAME))
90
+ $settings = get_site_option(WAMT_SITEADMIN_SETTING_FILE);
91
  else
92
+ $settings = get_option(WAMT_SETTING_FILE);
93
 
94
  if ( ! function_exists( 'is_plugin_active_for_network' ) )
95
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
125
  //var_dump($settings['filename_sanitized_enable']);
126
  if(isset($settings['filename_sanitized_enable']) && $settings['filename_sanitized_enable'] === "yes"){
127
  }else{
128
+ add_filter( 'sanitize_file_name', 'wamt_remove_underscore', 10, 2 );
129
  }
130
  }
131
 
160
  return $data;
161
  }
162
 
163
+ add_filter( 'wp_check_filetype_and_ext', 'wamt_add_allow_upload_extension_exception',10,5);