wpcf7_cleanup_upload_files() CF7 1.0
Хуков нет.
Возвращает
Null. Ничего.
Использование
wpcf7_cleanup_upload_files( $seconds, $max );
Код wpcf7_cleanup_upload_files() wpcf7 cleanup upload files CF7 5.3.2
function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {
if ( is_admin()
or 'GET' != $_SERVER['REQUEST_METHOD']
or is_robots()
or is_feed()
or is_trackback() ) {
return;
}
$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 );
}
}