admin管理员组文章数量:1292308
I am developing a plugin that is going to be used internally (inside the admin panel only).
I wonder what is the correct way to build the requests (action, params, etc) and what hook to use to be able to catch those requests. Can somebody help?
I am developing a plugin that is going to be used internally (inside the admin panel only).
I wonder what is the correct way to build the requests (action, params, etc) and what hook to use to be able to catch those requests. Can somebody help?
Share Improve this question asked Oct 31, 2016 at 8:26 user105980user105980 11 bronze badge 1 |2 Answers
Reset to default 1You should post some code examples, explaining what are you trying to do, to get more useful answers.
There are various hooks, and the one you should use depends on what you need. Anyway, here Codex: Actions Run During an Admin Page Request and here Codex: Administrative Actions the codex list the hooks to use for admin panel requests.
Example: If you have to activate something in the admin initialization, you can use the admin_init
action hook, so the code will be: add_action('admin_init', 'your-custom-function');
If you have to operate when a page load in the dashboard, you can use the load-(page)
hook; for example: add_action('load-post.php', 'your-custom-function');
and so on.
You can manage GET and POST requests with $_GET['x']
and $_POST['x']
, where x
is the variable you want to take from the query string. Example:
wp-admin/post.php?post=69
$_GET['post'] == 69
I don't know much, but I like this way.
For forms:
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="POST">
<input type="hidden" name="action" value="my_action">
Backend
add_action( 'admin_post_nopriv_my_action', 'myhandler' );
add_action( 'admin_post_my_action', 'myhandler' );
function myhandler(){
// Do magic :)
print_r($_POST);
}
本文标签: pluginsThe correct way to handle GET or POST requests in the admin panel
版权声明:本文标题:plugins - The correct way to handle GET or POST requests in the admin panel 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741543011a2384432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
admin_init
is your guy orif( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) ) { # catch'em }
– Ismail Commented Oct 31, 2016 at 10:17