wpcf7_cleanup_captcha_files

The Contact Form 7 wpcf7 cleanup captcha files function.

Description

wpcf7_cleanup_captcha_files(); 

Usage

  1. if ( !function_exists( 'wpcf7_cleanup_captcha_files' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/modules/really-simple-captcha.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wpcf7_cleanup_captcha_files(); 
  7.  

Defined (1)

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

/modules/really-simple-captcha.php  
  1. function wpcf7_cleanup_captcha_files() { 
  2. if ( ! $captcha = wpcf7_init_captcha() ) { 
  3. return false; 
  4.  
  5. if ( is_callable( array( $captcha, 'cleanup' ) ) ) 
  6. return $captcha->cleanup(); 
  7.  
  8. $dir = trailingslashit( wpcf7_captcha_tmp_dir() ); 
  9.  
  10. if ( ! is_dir( $dir ) || ! is_readable( $dir ) || ! wp_is_writable( $dir ) ) 
  11. return false; 
  12.  
  13. if ( $handle = @opendir( $dir ) ) { 
  14. while ( false !== ( $file = readdir( $handle ) ) ) { 
  15. if ( ! preg_match( '/^[0-9]+\.(php|txt|png|gif|jpeg)$/', $file ) ) 
  16. continue; 
  17.  
  18. $stat = @stat( $dir . $file ); 
  19. if ( $stat['mtime'] + 3600 < time() ) // 3600 secs == 1 hour 
  20. @unlink( $dir . $file ); 
  21. closedir( $handle );