The admin_post_nopriv WordPress PHP action fires when a non-authenticated user submits a request to the admin-ajax.php file without specifying an action.
Usage
add_action('admin_post_nopriv', 'my_custom_function'); function my_custom_function() { // Your custom code here }
Parameters
- No specific parameters for this action.
More information
See WordPress Developer Resources: admin_post_nopriv
Examples
Handle Contact Form Submission
Handle a contact form submission for non-authenticated users.
add_action('admin_post_nopriv', 'handle_contact_form'); function handle_contact_form() { // Process form data and send an email // Redirect user to thank you page }
Submit a Guest Post
Allow non-authenticated users to submit a guest post from the frontend.
add_action('admin_post_nopriv', 'submit_guest_post'); function submit_guest_post() { // Process form data and create a draft post // Notify admin about the new submission }
Custom Login for Non-authenticated Users
Create a custom login for non-authenticated users.
add_action('admin_post_nopriv', 'custom_login'); function custom_login() { // Authenticate user and log them in // Redirect user to the dashboard or custom page }
Non-authenticated User Poll Submission
Allow non-authenticated users to submit their votes in a poll.
add_action('admin_post_nopriv', 'submit_poll_vote'); function submit_poll_vote() { // Process and store user's vote // Show updated poll results }
Custom Registration for Non-authenticated Users
Create a custom registration form for non-authenticated users.
add_action('admin_post_nopriv', 'custom_registration'); function custom_registration() { // Process form data and create a new user // Send a confirmation email to the user }