我正在开发一个插件(用于我自己的网站)。我最近在管理页面上添加了一个按钮,可以生成一些文本,效果很好。这就是我使用的(从示例中窃取):
if (!current_user_can(\'manage_options\')) {
wp_die( __(\'You do not have sufficient galooph to access this page.\') );
}
if ($_POST[\'plugin_button\'] == \'thing\' && check_admin_referer(\'thing_button_clicked\')) {
plugin_thing_button();
}
echo \'<form action="options-general.php?page=plugin-list" method="post">\';
wp_nonce_field(\'thing_button_clicked\');
echo \'<input type="hidden" value="thing" name="plugin_button" />\';
submit_button(\'Generate new thing\');
echo \'</form>\';
这可以很好地工作,并按其应该的方式调用函数。现在我想要第二个按钮来做一些完全无关的事情。
以下是我尝试的,基本上是从上面复制的:
if (!current_user_can(\'manage_options\')) {
wp_die( __(\'You do not have sufficient galooph to access this page.\') );
}
if ($_POST[\'plugin_button\'] == \'thing\' && check_admin_referer(\'thing_button_clicked\')) {
plugin_thing_button();
}
if ($_POST[\'plugin_button2\'] == \'thing2\' && check_admin_referer(\'thing2_button_clicked\')) {
plugin_thing2_button();
}
echo \'<form action="options-general.php?page=plugin-list" method="post">\';
wp_nonce_field(\'thing_button_clicked\');
echo \'<input type="hidden" value="thing" name="plugin_button" />\';
submit_button(\'Generate new thing\');
wp_nonce_field(\'thing2_button_clicked\');
echo \'<input type="hidden" value="thing2" name="plugin_button2" />\';
submit_button(\'Generate new new thing\');
echo \'</form>\';
2个按钮的代码返回“;您访问的链接已过期"E;对于两个按钮,即单独工作的按钮现在也不工作。我的错在哪里?提前感谢您!