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
2070           }
2071      }
2072
2073      // Split the filename into a base and extension[s].
2074      $parts = explode( '.', $filename );
2075
2076      // Return if only one extension.
2077      if ( count( $parts ) <= 2 ) {
2078           /** This filter is documented in wp-includes/formatting.php */
2079           return apply_filters( 'sanitize_file_name', $filename, $filename_raw );
2080      }
2081
2082      // Process multiple extensions.
2083      $filename  = array_shift( $parts );
2084      $extension = array_pop( $parts );
2085      $mimes     = get_allowed_mime_types();
2086
2087      /*
2088       * Loop over any intermediate extensions. Postfix them with a trailing underscore
 
Line Code
2110
2111      /**
2112       * Filters a sanitized filename string.
2113       *
2114       * @since 2.8.0
2115       *
2116       * @param string $filename     Sanitized filename.
2117       * @param string $filename_raw The filename prior to sanitization.
2118       */
2119      return apply_filters( 'sanitize_file_name', $filename, $filename_raw );
2120 }
2121
2122 /**
2123  * Sanitizes a username, stripping out unsafe characters.
2124  *
2125  * Removes tags, percent-encoded characters, HTML entities, and if strict is enabled,
2126  * will only keep alphanumeric, _, space, ., -, @. After sanitizing, it passes the username,
2127  * raw username (the username in the parameter), and the value of $strict as parameters
2128  * for the {@see 'sanitize_user'} filter.