$parts =
explode( '.',
$filename );
// Return if only one extension.
if ( count( $parts ) <= 2
) { /** This filter is documented in wp-includes/formatting.php */
return apply_filters( 'sanitize_file_name',
$filename,
$filename_raw );
} // Process multiple extensions.
$filename =
array_shift( $parts );
$extension =
array_pop( $parts );
$mimes =
get_allowed_mime_types();
/*
* Loop over any intermediate extensions. Postfix them with a trailing underscore
* if they are a 2 - 5 character long alpha string not in the allowed extension list.
*/
foreach ( (array) $parts as $part ) { $filename .= '.' .
$part;
if ( preg_match( '/^[a-zA-Z]{2,5}\d?$/',
$part ) ) { $allowed = false;
foreach ( $mimes as $ext_preg =>
$mime_match ) {