我是wordpress的新手,我已经构建了一个只在管理菜单上保存设置的插件。
但是当我点击“保存”按钮时,它只会将我带到options.php页面并且没有做任何事情。我已经查看了几次我的代码,而且我似乎无法找到为什么它不能保存,而只是停留在options.php页面上。
任何帮助都会非常感激!!感谢
function fflOptionsMenuLink(){
add_options_page("Facebook Footer Link Options", "Facebook Footer Link","manage_options","ffl-options","fflOptionsContent" );
}
function fflOptionsContent(){
$opt = get_option("ffl_settings");
$output = "<div class='wrap'>
<h2>Facebook footer link settings </h2>
<form method='post' action='options.php' id='ffl_settings_group'>";
settings_fields('ffl_settings_group');
$output .= "<table class='form-table'>
<tbody>
<tr>
<th scope='row'><label for='ffl_settings[enable]'>Enable</label> </th>
<td><input name='ffl_settings[enable]' type='checkbox' id='ffl_settings[enable]' value='1' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[facebook_url]'>Facebook Profile </label> </th>
<td><input name='ffl_settings[facebook_url]' type='text' id='ffl_settings[facebook_url]' value='{$opt["ffl_settings"]}' class='regular-text' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[link_color]'>Enter color or hex value</label> </th>
<td><input name='ffl_settings[link_color]' type='text' id='ffl_settings[link_color]' value='{$opt["link_color"]}' class='regular-text' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[show_in_feed]'>Show in feed</label> </th>
<td><input name='ffl_settings[show_in_feed]' type='checkbox' id='ffl_settings[show_in_feed]' value='1' ></td>
</tr>
</tbody>
</table>
<p class='submit'><input type='submit' name='submit' id='submit' class='button button-primary' value='Submit'> </p>
";
$output .= "</form>";
$output.="</div>";
echo $output;
}
add_action("admin_menu","fflOptionsMenuLink");
//Register Settings
function fflRegisterSetting(){
register_setting("ffl_settings_group","ffl_settings");
}
add_action("admin_init","ffl_register_setting");
答案 0 :(得分:0)
少数事情......
fflRegisterSetting
而不是ffl_register_setting
的功能名称。facebook_url
字段的值错误为$opt["link_color"]
,但由于复选框尚未就绪,因此我将此视为WIP;)所以你的代码看起来应该是这样的 -
function fflOptionsMenuLink(){
add_options_page("Facebook Footer Link Options", "Facebook Footer Link","manage_options","ffl-options","fflOptionsContent" );
}
function fflOptionsContent(){
$opt = get_option("ffl_settings");
echo "<div class='wrap'>
<h2>Facebook footer link settings </h2>
<form method='post' action='options.php' id='ffl_settings_group'>";
settings_fields('ffl_settings_group');
echo "<table class='form-table'>
<tbody>
<tr>
<th scope='row'><label for='ffl_settings[enable]'>Enable</label> </th>
<td><input name='ffl_settings[enable]' type='checkbox' id='ffl_settings[enable]' value='1' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[facebook_url]'>Facebook Profile </label> </th>
<td><input name='ffl_settings[facebook_url]' type='text' id='ffl_settings[facebook_url]' value='{$opt["facebook_url"]}' class='regular-text' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[link_color]'>Enter color or hex value</label> </th>
<td><input name='ffl_settings[link_color]' type='text' id='ffl_settings[link_color]' value='{$opt["link_color"]}' class='regular-text' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[show_in_feed]'>Show in feed</label> </th>
<td><input name='ffl_settings[show_in_feed]' type='checkbox' id='ffl_settings[show_in_feed]' value='1' ></td>
</tr>
</tbody>
</table>
";
submit_button(); // Get the submit button from this function
echo "</form>";
echo "</div>";
}
add_action("admin_menu","fflOptionsMenuLink");
//Register Settings
function fflRegisterSetting(){
register_setting("ffl_settings_group","ffl_settings");
}
add_action("admin_init","fflRegisterSetting");