【问题标题】:wordpress theme options not savingwordpress 主题选项不保存
【发布时间】:2014-08-02 09:01:26
【问题描述】:

我正在编写一个 WordPress 插件,它使用设置 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 
}

【问题讨论】:

    标签: php wordpress plugins options


    【解决方案1】:

    如果您还没有弄清楚这一点:http://clicknathan.com/web-design/create-wordpress-theme-settings-page/ 对我有很大帮助:)

    【讨论】:

      猜你喜欢
      • 2012-08-13
      • 2012-11-10
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多