How to create a WP-CLI command with $_POST?

The main problem is that your wp_reset_init() method deals with too many things. It’s looking at the $_POST request, it’s performing database queries, and it’s performing redirects.

You need to separate your concerns so you end up with a new method which only performs the database reset, and which accepts parameters rather than using $_POST directly. You can then call this more tightly-focused method from your WP-CLI command (using the values from $assoc_args) and from your current wp_reset_init() method (using the values from $_POST).

Leave a Comment