Using widget options ‘outside’ the widget

@JonathonByrd’s answer is probably ‘best’ – certainly you should using get_option if at all possible, since there’s no guarantee the option name will stay the same between WordPress versions.

Similarly – @JonathonByrd also relies on using a global variable which may be removed/renamed (though perhaps very unlikely).

Unfortunately there are no public wrappers which we can reliably use. The closest is the get_settings method of your Widget class. Let’s suppose you’re widget class is My_Widget_Class, then:

 $dummy = new My_Widget_Class();
 $settings = $dummy->get_settings();

$settings is then an array of the form array(instance number => settings). Typically your widget will have any ID like my-widget-class-3 – and the ‘instance number’ here is 3, and so

 $settings[3]

gives the settings (as an array) for the widget my-widget-class-3. This I feel is a more reliable and future proof method.

Leave a Comment