Skip to content

Instantly share code, notes, and snippets.

@angelorocha
Last active December 6, 2018 18:00
Show Gist options
  • Save angelorocha/bec26ed2bb08b64f65adb3cf5f45650f to your computer and use it in GitHub Desktop.
Save angelorocha/bec26ed2bb08b64f65adb3cf5f45650f to your computer and use it in GitHub Desktop.
Sanitize wordpress uploaded filenames
<?php
/**
* Include in your theme functions
*/
add_filter( 'sanitize_file_name', 'sanitize_uploaded_filename' );
function sanitize_uploaded_filename( $filename ) {
$fileNewName = sanitize_title( pathinfo( $filename )['filename'] ) . '.' . pathinfo( $filename )['extension'];
return $fileNewName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment