Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: sanitize_file_name

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 2 times in this file.

Line Code
686      $filename = str_replace($special_chars, '', $filename);
687      $filename = preg_replace('/[\s-]+/', '-', $filename);
688      $filename = trim($filename, '.-_');
689
690      // Split the filename into a base and extension[s]
691      $parts = explode('.', $filename);
692
693      // Return if only one extension
694      if ( count($parts) <= 2 )
695           return apply_filters('sanitize_file_name', $filename, $filename_raw);
696
697      // Process multiple extensions
698      $filename = array_shift($parts);
699      $extension = array_pop($parts);
700      $mimes = get_allowed_mime_types();
701
702      // Loop over any intermediate extensions.  Munge them with a trailing underscore if they are a 2 - 5 character
703      // long alpha string not in the extension whitelist.
704      foreach ( (array) $parts as $part) {
 
Line Code
713                          break;
714                     }
715                }
716                if ( !$allowed )
717                     $filename .= '_';
718           }
719      }
720      $filename .= '.' . $extension;
721
722      return apply_filters('sanitize_file_name', $filename, $filename_raw);
723 }
724
725 /**
726  * Sanitize username stripping out unsafe characters.
727  *
728  * Removes tags, octets, entities, and if strict is enabled, will only keep
729  * alphanumeric, _, space, ., -, @. After sanitizing, it passes the username,
730  * raw username (the username in the parameter), and the value of $strict as
731  * parameters for the 'sanitize_user' filter.