I dont think my plugin is obsolete 🙂
Its primary function is to handle validation, but it also does the exact same thing as your code internally, and also includes the workaround for the front-end forms. Definitely something you can do in your functions.php or elsewhere; I was responding to this post as this code in the Validated Field plugin to enable different advanced functionality.