所以我做了下面这样的事情,但我得到的只是(我期待一个Facebook文本框?)
我希望它不要太乱。我不熟悉设置API。。。
add_action(\'admin_init\', function() {
register_setting(\'elem_opts\', \'elem_opts\', \'elem_validate_opts\');
add_settings_section(\'elem_opts_form\', \'Elements Theme Options\', \'elem_opts_form_cb\', \'elems_opts\');
add_settings_field(\'elem_opts_form\', \'Facebook\', \'elem_opts_social_fb_cb\', \'elems_opts\', \'elem_opts_form\');
});
function elem_opts_social_fb_cb() {
$opts = get_option(\'elem_opts\');
if (empty($opts) || !is_array($opts)) {
$opts = array();
}
?>
<input type="text" name="elem_opts[fb]" value="<?php echo $opts[\'fb\'] ? $opts[\'fb\'] : \'\'; ?>" />
<?php
}
add_action(\'admin_menu\', function() {
add_theme_page(\'Elements Options\', \'Elements Options\', \'manage_options\', \'elem_opts\', \'elem_opts_cb\');
});
function elem_validate_opts($input) {
return $input;
}
function elem_opts_form() {
?>
<p>Enable social network links, by entering your username for the respective social networks</p>
<?php
}
function elem_opts_cb() {
?>
<div class="wrap">
<h2>Elements Theme Options</h2>
<form action="options.php" method="post">
<?php
settings_fields(\'elem_opts\');
do_settings_sections(\'elem_opts\');
?>
<input type="submit" name="Submit" value="Save changes" />
</form>
</div>
<?php
}
最合适的回答,由SO网友:Bainternet 整理而成
您有一些回调函数,但ID混淆了,请尝试以下操作:
add_action(\'admin_init\', function() {
register_setting(\'elem_opts\', \'elem_opts\', \'elem_validate_opts\');
add_settings_section(\'elem_opts_form1\', \'Elements Theme Options\', \'elem_opts_form\', \'elem_opts\');
add_settings_field(\'elem_opts_form\', \'Facebook\', \'elem_opts_social_fb_cb\', \'elem_opts\', \'elem_opts_form1\');
});
function elem_opts_social_fb_cb() {
$opts = get_option(\'elem_opts\');
if (empty($opts) || !is_array($opts)) {
$opts = array();
}
?>
<input type="text" name="elem_opts[fb]" value="<?php echo $opts[\'fb\'] ? $opts[\'fb\'] : \'\'; ?>" />
<?php
}
add_action(\'admin_menu\', function() {
add_theme_page(\'Elements Options\', \'Elements Options\', \'manage_options\', \'elem_opts\', \'elem_opts_cb\');
});
function elem_validate_opts($input) {
return $input;
}
function elem_opts_form() {
?>
<p>Enable social network links, by entering your username for the respective social networks</p>
<?php
}
function elem_opts_cb() {
?>
<div class="wrap">
<h2>Elements Theme Options</h2>
<form action="options.php" method="post">
<?php
settings_fields(\'elem_opts\');
do_settings_sections(\'elem_opts\');
?>
<input type="submit" name="Submit" value="Save changes" />
</form>
</div>
<?php
}
这给了我:
下次尝试为每个函数、回调、节和页段塞使用不同的名称和ID。