1. class RegisteredSettingsTest {
  2.     private $page;
  3.     private $name = 'test-option';
  4.     private $options;
  5.     function __construct() {
  6.         add_action( 'admin_init', array( $this, 'admin_init' ) );
  7.         add_action( 'admin_menu', array( $this, 'admin_menu' ) );
  8.     }
  9.     function admin_init() {
  10.         register_setting( 'setting_ref', $this->name, array( $this, 'update_option' ) );
  11.         $this->options = get_option( $this->name );
  12.     }
  13.     function admin_menu() {
  14.         // change the following line to add_dashboard_page() instead of add_options_page() and the default "Settings saved" message will not appear on submit.
  15.         $this->page = add_options_page( 'Test','Test','manage_options','translatable_demo', array( &$this , 'load' ) );
  16.     }
  17.     function update_option( $data ) {
  18.         $clean = array_map( 'absint', $data );
  19.         unset($data);
  20.         return $clean;
  21.     }
  22.     function load() {
  23.         ?>
  24.         <div class="wrap">
  25.             <?php screen_icon('index'); ?>
  26.             <h2>Test</h2>
  27.             <form action="options.php" method="post">
  28.                 <?php settings_fields( 'setting_ref' ); ?>
  29.                 <p><label for="<?php $this->field_name( 'fieldone') ?>">Field one <input value="<?php $this->get_option( 'fieldone') ?>" name="<?php $this->field_name( 'fieldone') ?>" type="text" /></label></p>
  30.                 <p><label for="<?php $this->field_name( 'fieldtwo') ?>">Field two <input value="<?php $this->get_option( 'fieldtwo') ?>" name="<?php $this->field_name( 'fieldtwo') ?>" type="text" /></label></p>
  31.                 <p class="submit"><input type="submit" name="Submit" class="button-secondary action" value="Save" /></p>
  32.             </form>
  33.             <!-- Output options data, so we can see how it currently looks -->
  34.             <pre><?php print_r( $this->options ) ?></pre>
  35.         </div>
  36.         <?php
  37.     }
  38.     function field_name( $name, $echo = true ) {
  39.         $name = "{$this->name}[$name]";
  40.         if( $echo )
  41.             echo $name;
  42.         else
  43.             return $name;
  44.     }
  45.     function get_option( $name, $echo = true ) {
  46.         $val = '';
  47.         if( is_array( $this->options ) && isset( $this->options[$name] ) )
  48.             $val = $this->options[$name];
  49.  
  50.         if( $echo )
  51.             echo $val;
  52.         else
  53.             return $val;
  54.     }
  55. }
  56. $r = new RegisteredSettingsTest;