Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I just started learning the Wordpress Settings API and things are not as easy as I first tought.I have created a section and two fields and it seems that the fields are not saving the data.Each time I click on the field the data gets deleted.Here is my code:

<?php
    function thanathos_theme_menu(){
        add_menu_page(
                        'Thanathos',
                        'Thanathos',
                        'administrator',
                        'thanathos_menu_id',
                        'thanathos_menu_display_callback'
                     );
        add_submenu_page(
                        'thanathos_menu_id',
                        'Blog Page',
                        'Blog Page',
                        'administrator',
                        'thanathos_social_logo_options',
                        'thanathos_menu_display_callback'
                     );
    }
    add_action('admin_menu' , 'thanathos_theme_menu');

    function thanathos_menu_display_callback(){
?>      <div class="wrap">
            <div id="icon-themes" class="icon32"></div>
            <h2>Thanathos Theme Options</h2>
            <?php settings_errors(); ?>
            <form method="post" action="options.php">
                 <?php settings_fields( 'thanathos_social_logo_options' ); ?> 
                 <?php do_settings_sections( 'thanathos_social_logo_options' ); ?>
                <?php  submit_button(); ?>
            </form>  
        </div>
<?php }?>
<?php
    function thanathos_initialize_social_logo_options(){
        if(false == get_option('thanathos_social_logo_options')){
            add_option('thanathos_social_logo_options');
        }       
        add_settings_section(
                    'logo_social_section',
                    'Logo & Social Options',
                    'logo_social_section_callback',
                    'thanathos_social_logo_options'
                );
        add_settings_field(
                    'logo_field',
                    'Logo URL',
                    'logo_field_callback',
                    'thanathos_social_logo_options',
                    'logo_social_section'
                );
        add_settings_field(
                    'facebook_field',
                    'Facebook URL',
                    'facebook_field_callback',
                    'thanathos_social_logo_options',
                    'logo_social_section'
                );
        register_setting(
                    'thanathos_social_logo_options',
                    'thanathos_social_logo_options'
                );
    }
    add_action( 'admin_init', 'thanathos_initialize_social_logo_options' );
    function logo_social_section_callback(){}

    function logo_field_callback(){
        $option = get_option('thanathos_social_logo_options'); 
        echo '<input type="text" id="logo" name="thanathos_social_logo_options[logo_field]" value="' . $options['logo_field'] . '" />';
    }
     function facebook_field_callback(){
        $option = get_option('thanathos_social_logo_options'); 
        echo '<input type="text" id="facebook" name="thanathos_social_logo_options[facebook_field]" value="' . $options['facebook_field'] . '" />';
    }
?>
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Well , actually the error is pretty minor , on your callbacks you have wrote

function logo_field_callback(){
        $option = get_option('thanathos_social_logo_options'); 
        echo '<input type="text" id="logo" name="thanathos_social_logo_options[logo_field]" value="' . $options['logo_field'] . '" />';
    }
     function facebook_field_callback(){
        $option = get_option('thanathos_social_logo_options'); 
        echo '<input type="text" id="facebook" name="thanathos_social_logo_options[facebook_field]" value="' . $options['facebook_field'] . '" />';
    }

as you can see, you load as $option but print as $options, that is your only issue

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.