This is a stupid question, but I don't have much experience in the wordpress development. If I have a custom form that need to interact with a custom plugin, how I can get the submitted user data inside the plugin, what is the correct action that I need to set in my form? I'm able to use the admin-post.php
but I don't know if this will work also with plugin.
This is a stupid question, but I don't have much experience in the wordpress development. If I have a custom form that need to interact with a custom plugin, how I can get the submitted user data inside the plugin, what is the correct action that I need to set in my form? I'm able to use the admin-post.php
but I don't know if this will work also with plugin.
admin-post.php is perfect for that.
You have to do three things:
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
<input type="hidden" name="action" value="my_plugin_action" />
admin_post_{$action}
and admin_post_nopriv_{$action}
:add_action( 'admin_post_my_plugin_action', 'my_form_processor' );
add_action( 'admin_post_nopriv_my_plugin_action', 'my_form_processor' );
function my_form_processor() {
// your code that will process form data
}