Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

test2

delete files directory

// Scheduled Action Hook
function delete_files( ) {
	$file = '*';
	$directory = '/wp-content/uploads/test';
	wp_delete_file_from_directory( string $file, string $directory )
}
add_action( 'delete_files', 'delete_files' );

// Schedule Cron Job Event
function custom_cron_job() {
	if ( ! wp_next_scheduled( 'delete_files' ) ) {
		wp_schedule_event( current_time( 'timestamp' ), 'daily', 'delete_files' );
	}
}
add_action( 'wp', 'custom_cron_job' );