Changeset 11602
- Timestamp:
- 06/21/2017 09:30:26 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-attachment.php
r11543 r11602 262 262 } 263 263 264 // Helper for utf-8 filenames. 265 add_filter( 'sanitize_file_name', array( $this, 'sanitize_utf8_filename' ) ); 266 264 267 // Upload the attachment. 265 268 $this->attachment = wp_handle_upload( $file[ $this->file_input ], $overrides, $time ); 269 270 remove_filter( 'sanitize_file_name', array( $this, 'sanitize_utf8_filename' ) ); 266 271 267 272 // Restore WordPress Uploads data. … … 272 277 // Finally return the uploaded file or the error. 273 278 return $this->attachment; 279 } 280 281 /** 282 * Helper to convert utf-8 characters in filenames to their ASCII equivalent. 283 * 284 * @since 2.9.0 285 * 286 * @param string $retval Filename. 287 * @return string 288 */ 289 public function sanitize_utf8_filename( $retval ) { 290 // PHP 5.4+ or with PECL intl 2.0+ 291 if ( function_exists( 'transliterator_transliterate' ) && seems_utf8( $retval ) ) { 292 $retval = transliterator_transliterate( 'Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove', $retval ); 293 294 // Older. 295 } else { 296 // Use WP's built-in function to convert accents to their ASCII equivalent. 297 $retval = remove_accents( $retval ); 298 299 // Still here? use iconv(). 300 if ( function_exists( 'iconv' ) && seems_utf8( $retval ) ) { 301 $retval = iconv( 'UTF-8', 'ASCII//TRANSLIT//IGNORE', $retval ); 302 } 303 } 304 305 return $retval; 274 306 } 275 307
Note: See TracChangeset
for help on using the changeset viewer.