function wpcf7_cleanup_captcha_files()
{
    if (!($captcha = wpcf7_init_captcha())) {
        return false;
    }
    if (is_callable(array($captcha, 'cleanup'))) {
        return $captcha->cleanup();
    }
    $dir = trailingslashit(wpcf7_captcha_tmp_dir());
    if (!is_dir($dir) || !is_readable($dir) || !wp_is_writable($dir)) {
        return false;
    }
    if ($handle = @opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if (!preg_match('/^[0-9]+\\.(php|txt|png|gif|jpeg)$/', $file)) {
                continue;
            }
            $stat = @stat($dir . $file);
            if ($stat['mtime'] + 3600 < time()) {
                // 3600 secs == 1 hour
                @unlink($dir . $file);
            }
        }
        closedir($handle);
    }
}
Exemplo n.º 2
0
function wpcf7_cleanup_captcha_files()
{
    $dir = trailingslashit(wpcf7_captcha_tmp_dir());
    if (!is_dir($dir)) {
        return false;
    }
    if (!is_readable($dir)) {
        return false;
    }
    if (!is_writable($dir)) {
        return false;
    }
    if ($handle = @opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if (!preg_match('/^[0-9]+\\.(php|png|gif|jpeg)$/', $file)) {
                continue;
            }
            $stat = stat($dir . $file);
            if ($stat['mtime'] + 21600 < time()) {
                // 21600 secs == 6 hours
                @unlink($dir . $file);
            }
        }
        closedir($handle);
    }
}