Is it safe to use $_POST directly in my plugin instead of using admin-ajax.php to receive data from ajax?

When we want post data from frontend to WORDPRESS everyone says i must use admin-ajax.php.
But i can add query vars and receive posted data in my plugin file using a global variable, and then i can do anything that i want with that.
This way everything becomes easier for me , but is it safe to receive and store posted data in plugin file ? and why all are using admin-ajax.php in their projects ?

1 Answer
1

First, everyone doesn’t say that. Everyone says to use admin-ajax.php for ajax, which is it’s meant for, not form submissions precisely. It’s not as popular and well covered, but there is actually different endpoint for form submission — admin-post.php.

The reasons are, however, same. What you cannot do in your plugin is reliably load WordPress core. When WordPress core loads plugins it composes coherent reliable environment, but it doesn’t work the other way around.

The point of using core–provided endpoints is precisely to rely on that environment.

Leave a Comment