简体   繁体   中英

Post data from non-admin user in WordPress

I'm speaking of "post" as in the html method, not a blog post. This overlap in terminology is probably a good part of the reason I can't find what I'm looking for.

I have some admin pages set up with forms, using add_action('admin_post_something', 'my_function'); to handle saving the form data to the database. That all works marvelously.

Now I have a client-side piece that requires the user to be logged in to post data, but not necessarily be an admin. The admin_post_something hook will not work (returns page not found) because the user is not an admin. This is expected behavior.

What hook action should I use to process and store information coming from the client-facing portion of my site, and where should this function be located? Examples or links to documentation are appreciated.

Thanks

Inside your function which processes the POST data, you could have a conditional check to see if the form has been submitted. For example:

if ( isset( $_POST['a-hidden-field-name-in-your-form'] ) ) { 
    // do something here because the form has been submitted 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM