我正在编写一个WordPress插件,它使用Settings API来注册一些选项。当我尝试保存我的选项时,他们不保存。页面重新加载时,这些字段为空白,并且没有保存选项的消息。我已经绞尽脑汁几个小时,找不到任何答案。我将非常感谢任何帮助。以下是我的代码页面的代码(稍加修改):
<?php
/**************************************** Register Settings Menu & Page ****************************************/
add_action( 'admin_menu', 'rv_admin_menu' );
function rv_admin_menu() {
// Parent Slug, Page Title, Menu Title, Capability, Menu Slug, Callback Function
add_submenu_page('slug', 'Misc. Options', 'Misc. Options', 'manage_options', 'rv-options-page', 'rv_options_create_page');
}
/**************************************** Register Settings ****************************************/
add_action( 'admin_init', 'rv_admin_init' );
function rv_admin_init() {
/** Add the Settings Group **/
register_setting( 'rv-options-group', 'rv-settings' ); // Option Group & Options Name
/* Add Custom Footer Section & Fields */
// ID, Title, Callback, Menu Page
add_settings_section( 'footer-section', 'Custom Footer', 'custom_footer_section_callback', 'rv-options-page' );
// ID, Title, Callback, Menu Page, Associated Section
add_settings_field( 'footer-content', 'Footer Content', 'custom_footer_callback', 'rv-options-page', 'footer-section' );
/* Add Author Box Section & Fields */
add_settings_section( 'author-box', 'Author Box', 'author_box_section_callback', 'rv-options-page' );
add_settings_field( 'author-box-enable', 'Globally Enable Author Box', 'author_box_enable_callback', 'rv-options-page', 'author-box' );
add_settings_field( 'author-box-title', 'Author Box Title', 'author_box_title_callback', 'rv-options-page', 'author-box' );
}
/**************************************** Footer ****************************************/
/** Custom Footer Section Intro **/
function custom_footer_section_callback() {
echo "Add your footer's custom HTML.";
}
/* Custom Footer Text Area */
function custom_footer_callback() {
$settings = (array) get_option( 'rv-settings' );
$footer = esc_attr( $settings['footer'] );
echo "<textarea rows='12' cols='100' name='rv-settings[footer]' value='$footer'></textarea>";
}
/**************************************** Author Box ****************************************/
/** Author Box Section Intro **/
function author_box_section_callback() {
echo "Customize the Author Box";
}
/* Globally Enable Author Box on Posts */
function author_box_enable_callback() {
$settings = (array) get_option( 'rv-settings' );
$enable_author_box = esc_attr( $settings['enable_author_box'] );
echo "<input type='checkbox' name='rv-settings[enable_author_box]' value='$enable_author_box' />";
}
/* Custom Author Box Title */
function author_box_title_callback() {
$settings = (array) get_option( 'rv-settings' );
$author_box_title = esc_attr( $settings['author_box_title'] );
echo "<input size='100' type='text' name='rv-settings[author_box_title]' value='$author_box_title' />";
}
/**************************************** Create Settings Page ****************************************/
function rv_options_create_page() { ?>
<div class="wrap">
<h2>RV Options</h2>
<form action="options.php" method="POST">
<?php settings_fields( 'rv-options-group' ); // Options Group ?>
<?php do_settings_sections( 'rv-options-page' ); // Menu Page ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
答案 0 :(得分:0)
如果你还没想到这个:http://clicknathan.com/web-design/create-wordpress-theme-settings-page/给了我很多帮助:)