$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - Custom form action to handle data inside a plugin|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Custom form action to handle data inside a plugin

matteradmin7PV0评论

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.

Share Improve this question asked Mar 17, 2019 at 18:33 ZWPDevZWPDev 1162 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

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
}
Post a comment

comment list (0)

  1. No comments so far