Automatic post deletion

You can improve by storing the “expiry” time of post as a meta instead of the publish time. This way you can query for posts with meta which is smaller then the current time and draft them, no need to loop over all posts.

Drawback is that you will have to decide how to handle changes to lifespawn time, just ignore this edge case or adjust all posts.