How to handle $instance when you have a lot of widget options
-
Hi All,
I am assuming there is a more compact way to handle a widget with many options.
My widget has about 20 options.
In each subclass of WP_Widget, they need to be defined/used. The instance param, as I can understand it, is a list of every option (not sure why this is not an array) and is used in the following subclasses:
function widget($args, $instance) function update($new_instance, $old_instance) function form($instance)
For example, in function widget:
$param1=$instance['param1']; $param2=$instance['param2'] etc...
In function update:
$instance['param1']=strip_tags($new_instance['param1']); $instance['param2']=strip_tags($new_instance['param2']); etc...
In function form:
$param1=esc_attr($instance['param1']); $param2=esc_attr($instance['param2']); etc...
The code gets very bulky. Is there a better, more compact way to handle this? A standard way to loop through instances and get the names?
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘How to handle $instance when you have a lot of widget options’ is closed to new replies.