admin-post.php is perfect for that.
You have to do three things:
1. Set action for your form to admin-post.php
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
2. Add hidden input with name=action
<input type="hidden" name="action" value="my_plugin_action" />
3. Register your callbacks for 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
}
Related Posts:
- shortcode doesn’t work
- How to trigger $_GET request within admin plugin page?
- Using a custom plugin to capture input data via Ajax and PHP
- submit form data to wordpress existing database table using my plugin
- Undefined variable _POST
- What are the differences between WPINC and ABSPATH?
- Problems with autoloading classes via sp_autoload_register / maybe interfering WP-specific autoloader
- Using require_once in a Plugin?
- Simple form that saves to database
- How to Loop Plugin Option Field Set?
- Rename existing old uploaded images containing accented French characters (not during upload)
- How to Create a Directory in a Plugin Folder?
- Create plugin that works in background
- Checking for user role in a custom plugin
- HELP: Integrating WP with raw PHP code once published button is hit
- Loading class files via autoload method
- I would like to use create a function in my custom plugin to tell WP to use a different header
- Getting media library popup in custom plugin admin page
- jQuery function didn’t work in my plugin
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Escape when echoed
- Scope for PHP Variables Assigned in functions.php or a plugin
- Plugin Development sqlite or WordPress’ database
- WooCommerce get_price returning wrong price when used via ajax
- Open Post Thumbnail in New Child Theme File in WordPress
- Redirecting to home page after login as custom role WordPress
- Add keywords meta to index.php page
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- WP Post Template – Templates in own folder
- wp_create_nonce function doesn’t work inside a plugin?
- New User Form – Custom Menu Page
- wordpress plugin is not activating from widget
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Image upload and download from front-end
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- What are the specifics of WordPress development I need to know? [closed]
- Ajax call returning 0
- Checkbox conflict in my custom plugin admin page
- How to replace WordPress Media Upload Window with user’s device window?
- How to create a custom post type that contains another custom post type?
- WP Plugins – Use includes to display page content
- Setup wp_schedule_event within a custom plugin
- Issue running db create table query from static method
- execute function after one completed
- Submit Form data to another page via Ajax (WordPress Way)
- How to make multiple admin pages for one plugin?
- Integrating boxtal PHP library into a custom WordPress Plugin
- Why is it important to check for isset and is_array before checking in_array in this example?
- How to add/change (woocommerce) product tab icon
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- I want to generate the pdf and save it in library?
- Wp Debug Enabled True Notices and Warning
- How to call external functions from a PHP script in a WordPress plugin?
- How to write to a separate PHP file in plugin settings
- Create “new pages” within the admin section of plugin
- More gentle way to hook WordPress custom url
- How to display results from a data table with an encrypted user id?
- How to add custom function to pluggable.php
- How to displaying Custom image, text and default image logo from Redux Framework option panel
- How to Call Specific .PHP file on add_submenu_page selection in Plugin Development?
- How to Add text value in Automatically in this conditions?
- Checkbox show / hide output result
- User loggedin as Subscriber form not sending
- save_post_product action not firing
- How to get the custom field value using SQL query
- admin_notices show after load completed
- Prevent WordPress from sending set-cookie http header
- How use wp_insert_post and add og:custom tags?
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Hide content for specific users with id
- adding dynamic/multiple slug values in ‘option_none_value’
- How to change “Read More” text?
- How can I see $post object in frontend from functions.php?
- Move plugin pages from dashboard to front-end
- Using id to show item
- 500 Internal server error wp_handle_upload_prefilter
- Can’t access 3rd party API, code works on local server but not on wordpress
- Generate and send ICS file through WordPress
- Get post content inside plugin class method
- Is admin section completely customizable in terms of styling?
- Ajax call to php function doesn’t work PHP code
- Change pricing in Woocommerce based on Category and Product [closed]
- WordPress environment not loading properly
- WordPress not displaying information on post sent from custom admin form
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- Creating a user ‘add custom field’ section
- I created a custom form in HTML/CSS and now I need it to submit … should I create custom PHP or is there a plugin I can use?
- How do I convince this button to do something when it is clicked?
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- How to add a handler for a button in plugin?
- Doing action based on input from options menu
- Load my plugin before cache
- My wordpress website admin panel loads very slow, what can i do about that? [closed]
- wordpress select multiple options and illegal string offset ‘timeslot’ [closed]
- Displaying Category Feature image on loop
- how to show selected options drop down menu values in attributes field in after saving post.php
- How to trigger plugin migration code when plugin updates?
- How to Save Category and Delete Category in same Function
- Accessing Correct Database to Create REST API Endpoint