wpcf7_cleanup_upload_files()
Cleans up files in the temporary directory for uploaded files.
Хуков нет.
Возвращает
null. Ничего (null).
Использование
wpcf7_cleanup_upload_files( $seconds, $max );
- $seconds(int)
- Files older than this are removed.
По умолчанию:60 - $max(int)
- Maximum number of files to be removed in a function call.
По умолчанию:100
Код wpcf7_cleanup_upload_files() wpcf7 cleanup upload files CF7 6.1.5
function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {
$dir = trailingslashit( wpcf7_upload_tmp_dir() );
if (
! is_dir( $dir ) or
! is_readable( $dir ) or
! wp_is_writable( $dir )
) {
return;
}
$seconds = absint( $seconds );
$max = absint( $max );
$count = 0;
if ( $handle = opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( '.' === $file or '..' === $file or '.htaccess' === $file ) {
continue;
}
$mtime = @filemtime( path_join( $dir, $file ) );
if ( $mtime and time() < $mtime + $seconds ) { // less than $seconds old
continue;
}
wpcf7_rmdir_p( path_join( $dir, $file ) );
$count += 1;
if ( $max <= $count ) {
break;
}
}
closedir( $handle );
}
}