set_defaults(); } /** * Sets fields data */ function set_fields($fields){ $this->fields = $fields; } /** * Generates default ids and values */ protected function set_defaults(){ // store fields id and values in $default var foreach ($this->fields as $field) { $this->defaults[$field["id"]] = $field["value"]; } } /*--------------------------------------------------*/ /* Widget API Functions /*--------------------------------------------------*/ /** * Outputs the content of the widget. * * @param array args The array of form elements * @param array instance The current instance of the widget */ function widget( $args, $instance ) { } /** * Processes the widget's options to be saved. * * @param array new_instance The new instance of values to be generated via the update. * @param array old_instance The previous instance of values before the update. */ function update( $new_instance, $old_instance ) { $instance = $old_instance; foreach ($this->fields as $field) { $id = $field["id"]; $instance[$id] = strip_tags($new_instance[$id]); } return $instance; } /** * Generates the administration form for the widget. * * @param array instance The array of keys and values for the widget. */ function form( $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults ); // get_field_id (string $field_name) // creates id attributes for fields to be saved by update() foreach ($this->fields as $field) { $id = $field['id']; switch ($field['type']) { case 'textbox': echo '
', '', '', '
'; break; case 'select': echo '', '', '', '
'; break; default: break; } } } } // end widget class endif;