What is this instance variable doing in the Widgets class

$instance holds the data stored for this widget instance as an array. You could use the same widget multiple times, and each would get different data.

get_field_name() and get_field_id() returns name/id attributes for that widget. They are unique for each widget, but do not depend on the data. That’s why they do not have to know anything about the $instance:

function get_field_name($field_name) {
    return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
}

Leave a Comment