我正在为Wordpress构建一个插件,该插件的页面是根据以下代码创建的:
public function menu_html()
{
?>
<form method="post" action="options.php">
<?php settings_fields('zero_polls') ?>
<?php do_settings_sections('zero_polls') ?>
<?php submit_button(); ?>
</form><?php
}
所以上面我实例化了字段名称&#34; zero_polls&#34;这是在这里创建的:
public function register_settings()
{
register_setting('zero_polls', 'zero_polls_question');
register_setting('zero_polls', 'zero_polls_add');
add_settings_section('polls_section', 'Sondage', array($this, 'section_html'), 'zero_polls');
add_settings_field('zero_polls_question', "Question:", array($this, 'question_html'), 'zero_polls', 'polls_section');
add_settings_field('zero_polls_add', 'Add a new answer:', array($this, 'add_html'), 'zero_polls', 'polls_section');
}
当Wordpress使用以下命令更新菜单时调用menu_html函数:
public function add_admin_menu()
{
$hook = add_submenu_page('options-general.php', 'Sondages', 'Sondages', 'manage_options', 'zero_polls', array($this, 'menu_html'));
add_action('load-'.$hook, array($this, 'process_action'));
}
正如您在上面所看到的,我在此处添加了一个重定向process_action()
功能的操作:
function process_action(){
global $wpdb;
$wpdb->query("INSERT INTO wp_poll_options(id, label) VALUES('','YOUPI')");
}
问题是我提交表单后我的表wp_poll_options没有得到更新(YOUPI没有出现)。 我想我在理解Wordpress工作流程时遗漏了一些东西,请帮忙,谢谢。