Preserve options when using multiple pages and the settings api

See my previous paste for the whole class (minus this) http://kuttler.eu/code/wordpress-plugintheme-options-page/

<?php

class Foo {

  [...]

    /**   
     * Whitelist the Foo options
     *
     * @return none
     */
    function register_settings () {
        register_setting( 'Foo_options' , 'Foo', array( &$this, 'merge_options' ) );
    }

  /**
   * Preserve options when using multiple pages
   *
   * @return merged data
   */
    function merge_options( $data ) {
        $existing = $this->options; // this contains get_option( 'Foo' );
        if ( !is_array( $existing ) || !is_array( $data ) ) // something went wrong
            return $data;
        return array_merge( $existing, $data );
    }
}
?>

1 comment

  1. avatar
    wrote this comment on
    This is what I was looking for. To use merge_options function before the end of validation before saving options to preserve existing options. Thank youuuuu

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.