Changeset 1302725
- Timestamp:
- 12/08/2015 05:39:45 AM (10 years ago)
- Location:
- clean-media-library-file-names/trunk
- Files:
-
- 2 edited
-
clean-media-library-file-names.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
clean-media-library-file-names/trunk/clean-media-library-file-names.php
r911360 r1302725 4 4 Plugin Group: Media Library 5 5 Plugin URI: http://phplug.in/ 6 Version: 0. 26 Version: 0.3.1 7 7 Description: This plugin cleans uploaded file names to remove special characters and spaces. 8 8 Author: Eric King … … 23 23 *********************************************/ 24 24 25 defined('ABSPATH') || die('What are you doing? You\'re not allowed back here!');25 defined('ABSPATH') || exit; 26 26 27 function wde_ clean_media_library_file_names(array $data, $file, $filename, $mimes)27 function wde_get_file_info( $file ) 28 28 { 29 if (isset($data['ext'])) { 30 $data['proper_filename'] = sanitize_title_with_dashes( 31 substr($filename, 0, strlen($filename) - strlen($data['ext']) - 1), 32 '', 33 'save' 34 ) . '.' . $data['ext']; 29 if ( ! function_exists('finfo_file') ) { 30 return false; 35 31 } 32 33 $finfo = finfo_open( FILEINFO_MIME_TYPE ); 34 $mime = finfo_file( $finfo, $file ); 35 finfo_close( $finfo ); 36 37 $extensions = array_search( $mime, wp_get_mime_types() ); 38 39 if ( $extensions === false ) { 40 return false; 41 } 42 43 $ext = explode('|', $extensions); 44 45 return array( 46 'ext' => reset( $ext ), 47 'type' => $mime 48 ); 49 } 50 51 function wde_clean_media_library_file_names( array $data, $file, $filename, $mimes ) 52 { 53 $clean_name = sanitize_file_name( $filename ); 54 55 if ( $filename === $clean_name ) { 56 return $data; 57 } 58 59 if ( $data['ext'] === false || $data['type'] === false ) { 60 $info = wde_get_file_info( $file ); 61 62 if ( $info !== false ) { 63 $data = array_merge( $data, $info ); 64 } 65 } 66 67 if ( $clean_name == '' || $clean_name == $data['ext'] ) { 68 69 if ( $data['ext'] !== false ) { 70 71 $clean_name = sprintf('%s-%s.%s', str_replace('/', '-', $data['type'] ), uniqid(), $data['ext'] ); 72 73 } else { 74 75 $clean_name = sprintf('%s-%s', str_replace('/', '-', $data['type'] ), uniqid() ); 76 77 } 78 79 } 80 81 $data['proper_filename'] = $clean_name; 82 36 83 return $data; 37 84 } 38 add_filter('wp_check_filetype_and_ext', 'wde_clean_media_library_file_names', 10, 4); 85 86 add_filter( 'wp_check_filetype_and_ext', 'wde_clean_media_library_file_names', 10, 4 ); -
clean-media-library-file-names/trunk/readme.txt
r911667 r1302725 1 1 === Clean Media Library File Names === 2 Plugin Name: Clean Media Library File Names3 2 Contributors: webdeveric 4 Author URI: http://webdeveric.com/5 Plugin URI: http://phplug.in/6 3 Tags: media library, filename, sanitize, special characters 7 4 Requires at least: 3.0.0 8 Tested up to: 3.9.19 Stable tag: 0. 25 Tested up to: 4.4.0 6 Stable tag: 0.3.1 10 7 11 8 This plugin cleans uploaded file names to remove special characters and spaces. … … 17 14 == Installation == 18 15 19 1. Upload `clean-media-library-file -names` folder to the `/wp-content/plugins/` directory16 1. Upload `clean-media-library-filenames` folder to the `/wp-content/plugins/` directory 20 17 1. Activate the plugin through the 'Plugins' menu in WordPress 21 18 1. You're done 22 19 23 20 == Changelog == 21 22 = 0.3.1 = 23 * Works with WordPress 4.4 24 25 = 0.3 = 26 * Added default file name when the sanitized file name is blank. This could happen when the file name contains only special characters. 24 27 25 28 = 0.2 =
Note: See TracChangeset
for help on using the changeset viewer.