wpcf7_cleanup_upload_files()CF7 1.0

Cleans up files in the temporary directory for uploaded files.

Хуков нет.

Возвращает

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() CF7 5.6.4

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 );
	}
}