wpcf7_antiscript_file_name

The Contact Form 7 wpcf7 antiscript file name function.

Description

wpcf7_antiscript_file_name( (string) $filename ); 

Parameters (1)

0. $filename (string)
The filename.

Usage

  1. if ( !function_exists( 'wpcf7_antiscript_file_name' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/includes/formatting.php'; 
  3.  
  4. // The filename. 
  5. $filename = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wpcf7_antiscript_file_name($filename); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/formatting.php  
  1. function wpcf7_antiscript_file_name( $filename ) { 
  2. $filename = basename( $filename ); 
  3. $parts = explode( '.', $filename ); 
  4.  
  5. if ( count( $parts ) < 2 ) { 
  6. return $filename; 
  7.  
  8. $script_pattern = '/^(php|phtml|pl|py|rb|cgi|asp|aspx)\d?$/i'; 
  9.  
  10. $filename = array_shift( $parts ); 
  11. $extension = array_pop( $parts ); 
  12.  
  13. foreach ( (array) $parts as $part ) { 
  14. if ( preg_match( $script_pattern, $part ) ) { 
  15. $filename .= '.' . $part . '_'; 
  16. } else { 
  17. $filename .= '.' . $part; 
  18.  
  19. if ( preg_match( $script_pattern, $extension ) ) { 
  20. $filename .= '.' . $extension . '_.txt'; 
  21. } else { 
  22. $filename .= '.' . $extension; 
  23.  
  24. return $filename;