Why does WordPress stores widget options in a multidimensional array?

Widgets can be used multiple times. Your options will be passed to the widget directly and automatically, as part of the $instance variable. You should not be getting the options directly using get_option.

The widget() function declaration in a WP_Widget derived class looks like this:


function widget( $args, $instance )

The $instance variable will be your options, without the [2]. Each instance of the widget will get its own options.

Similarly, the form() function to display the form for the widget looks like this:


function form( $instance )

Same deal. Finally, the update() function gets two copies of the instanced data, like so:


function update( $new_instance, $old_instance )

The update function should validate the options in $new_instance, and using the options from $old_instance if they are invalid. The function should then return the resulting combined array of the valid options. This will then become the new set of the instanced options for use elsewhere.

Look at the widgets in the core, such as WP_Text_Widget, for examples.

TL;DR: WordPress handles the database stuff for widgets automatically. Don’t call get_option, let the underlying WP_Widget class do the grunt work.