我尝试为我的插件创建自定义设置页面,但是我无法让页面显示自定义设置页面,为了简单起见我只想显示节标题。
这就是我所拥有的。
private function add_hooks() {
add_action('admin_menu', array($this,'register_menu'));
add_action("admin_init", array($this,"display_options"));
}
public function register_menu() {
add_menu_page('Feed','API FEED','manage_options','adt-feed',array($this,'include_admin_page'),'dashicons-format-image');
}
public function include_admin_page() {
return include_once( PLUGIN_PATH 'admin/view/config-page.php' );
}
public function display_options()
{
//section name, display name, callback to print description of section, page to which section is attached.
add_settings_section("adt_general_section", "Header Options", array($this, "display_header_options_content"), "adt-feed");
}
public function display_header_options_content() { //THIS NEVER GETS CALLED
echo "PLUGIN HEADER SECTION";
}
他们在我的config-page.php中我有:
<div class="wrap">
<div id="icon-options-general" class="icon32"></div>
<h1>ADT Feed Options</h1>
<form method="post" action="options.php">
<?php
//add_settings_section callback is displayed here. For every new section we need to call settings_fields.
settings_fields("adt_general_section");
// Add the submit button to serialize the options
submit_button();
?>
</form>
</div>
使用一些“die()”调用我设法发现display_header_options_content永远不会被调用,如果我在add_settings_section中更改“general”的“adt-feed”,我可以看到消息:“PLUGIN HEADER SECTION”中的常规设置页面。
提前感谢您的帮助!
答案 0 :(得分:0)
您需要致电
do_settings_sections( 'adt-feed' );
在config-page.php。
中放置这个的好地方就在调用submit_button();
之前