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
2036      if ( count( $parts ) <= 2 ) {
2037           /**
2038            * Filters a sanitized filename string.
2039            *
2040            * @since 2.8.0
2041            *
2042            * @param string $filename     Sanitized filename.
2043            * @param string $filename_raw The filename prior to sanitization.
2044            */
2045           return apply_filters( 'sanitize_file_name', $filename, $filename_raw );
2046      }
2047
2048      // Process multiple extensions.
2049      $filename  = array_shift( $parts );
2050      $extension = array_pop( $parts );
2051      $mimes     = get_allowed_mime_types();
2052
2053      /*
2054       * Loop over any intermediate extensions. Postfix them with a trailing underscore
 
Line Code
2069                if ( ! $allowed ) {
2070                     $filename .= '_';
2071                }
2072           }
2073      }
2074
2075      $filename .= '.' . $extension;
2076
2077      /** This filter is documented in wp-includes/formatting.php */
2078      return apply_filters( 'sanitize_file_name', $filename, $filename_raw );
2079 }
2080
2081 /**
2082  * Sanitizes a username, stripping out unsafe characters.
2083  *
2084  * Removes tags, octets, entities, and if strict is enabled, will only keep
2085  * alphanumeric, _, space, ., -, @. After sanitizing, it passes the username,
2086  * raw username (the username in the parameter), and the value of $strict as
2087  * parameters for the {@see 'sanitize_user'} filter.