• I’m working my way through the documentation on how to create an options page for a plugin, but there are huge gaps in my understanding (and perhaps in the documentation).

    I understand that the whole register_settings thing is supposed to do most of the work for me, but despite hours on the codex and other sites, I still can’t get my options to save. They show up all right, but they don’t save when I update. What am I missing? There is no error message.

    <?php
    
    if ( is_admin() ){ // admin actions
    	add_action( 'admin_menu', 'adminMenu' );
    	add_action( 'admin_init', 'registerSettings' );
    }
    
    register_activation_hook(__FILE__,'registerSettings');
    register_deactivation_hook( __FILE__, 'eraseSettngs' ); 
    
    function adminMenu() {
    add_options_page('Donut Settings', 'You have options', 'administrator', 'donut', 'donut_settings');
    }
    
    function registerSettings() {
      register_setting( 'donutOptions', 'optn1' );
      register_setting( 'donutOptions', 'optn2' );
    }
    
    function eraseSettings() {
      unregister_setting( 'donutOptions', 'optn1' );
      unregister_setting( 'donutOptions', 'optn2' );
    }
    
    function donut_settings() {
    ?>
    <form method="post" action="options.php">
    <?php settings_fields( 'donutOptions' ); ?>
    
    Option 1
    <input name="optn1" type="text" id="optn1ID"
    value="<?php echo get_option('optn1'); ?>" />	
    
    Option 2:
    <input name="optn2" type="text" id="optn2ID"
    value="<?php echo get_option('optn2'); ?>"  />
    <input type="submit" value="<?php _e('Save Changes') ?>" />
    
    </form>
    <?php
    }
    ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Creating an options / settings page for plug ins’ is closed to new replies.