Why is the $old_instance needed for the widget update function?

As the comment says, you should validate the values of the new instance. What happens if one of these values is invalid? You can either set a predefined default value or use the value from the old instance, because that must be valid.

So a very simple update code could look like this:

function update( $new_instance, $old_instance )
{
    return array_merge( $old_instance, $new_instance );
}

There is no better way to get this information, so WordPress just passes it along in case you need it. But you are free to ignore it completely.

Leave a Comment