' . esc_html( $message ) . '
';
}
}
/* File uploading functions */
function wpcf7_init_uploads() {
$dir = wpcf7_upload_tmp_dir();
wp_mkdir_p( $dir );
$htaccess_file = trailingslashit( $dir ) . '.htaccess';
if ( file_exists( $htaccess_file ) ) {
return;
}
if ( $handle = @fopen( $htaccess_file, 'w' ) ) {
fwrite( $handle, "Deny from all\n" );
fclose( $handle );
}
}
function wpcf7_maybe_add_random_dir( $dir ) {
do {
$rand_max = mt_getrandmax();
$rand = zeroise( mt_rand( 0, $rand_max ), strlen( $rand_max ) );
$dir_new = path_join( $dir, $rand );
} while ( file_exists( $dir_new ) );
if ( wp_mkdir_p( $dir_new ) ) {
return $dir_new;
}
return $dir;
}
function wpcf7_upload_tmp_dir() {
if ( defined( 'WPCF7_UPLOADS_TMP_DIR' ) )
return WPCF7_UPLOADS_TMP_DIR;
else
return wpcf7_upload_dir( 'dir' ) . '/wpcf7_uploads';
}
add_action( 'template_redirect', 'wpcf7_cleanup_upload_files', 20 );
function wpcf7_cleanup_upload_files() {
if ( is_admin() || 'GET' != $_SERVER['REQUEST_METHOD']
|| is_robots() || is_feed() || is_trackback() ) {
return;
}
$dir = trailingslashit( wpcf7_upload_tmp_dir() );
if ( ! is_dir( $dir ) || ! is_readable( $dir ) || ! wp_is_writable( $dir ) ) {
return;
}
if ( $handle = @opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file == "." || $file == ".." || $file == ".htaccess" ) {
continue;
}
$mtime = @filemtime( $dir . $file );
if ( $mtime && time() < $mtime + 60 ) { // less than 60 secs old
continue;
}
wpcf7_rmdir_p( path_join( $dir, $file ) );
}
closedir( $handle );
}
}