widget_id = $widget_id; $this->widget_file = $widget_file; if ( ! $textdomain ) $textdomain = $widget_id; $this->textdomain = $textdomain; $this->load_textdomain(); $this->load_config(); // input can be 'checkbox', 'multiselect', 'select', 'short_text', 'text', 'textarea', 'hidden', or 'none' // datatype can be 'array' or 'hash' // can also specify input_attributes $this->config = apply_filters( $this->get_hook( 'config' ), $this->config ); if ( empty( $this->hook_prefix ) ) $this->hook_prefix = $this->widget_id; foreach ( $this->config as $key => $value ) $this->defaults[$key] = isset( $value['default'] ) ? $value['default'] : ''; $widget_ops = array( 'classname' => 'widget_' . $this->widget_id, 'description' => $this->description ); $widget_ops = apply_filters( $this->get_hook( 'widget_ops' ), $widget_ops ); $control_ops = apply_filters( $this->get_hook( 'control_ops' ), $control_ops ); $this->WP_Widget( $this->widget_id, $this->title, $widget_ops, $control_ops ); } /** * Outputs the widget * * Simply override this function if you want full control over widget. Otherwise, you can hook into just the body. * * @param array $args Widget args * @param array $instance Widget instance * @return void (Text is echoed.) */ public function widget( $args, $instance ) { extract( $args ); /* Settings */ $settings = array(); foreach ( array_keys( $this->config ) as $key ) $settings[$key] = apply_filters( $this->get_hook( 'config_item_'.$key ), $instance[$key], $this ); $title = $settings['title']; echo $before_widget; if ( ! empty( $title ) ) echo $before_title . $title . $after_title; $this->widget_body( $args, $instance, $settings ); echo $after_widget; } /** * Save and validate updates to widget values * * @param array $new_instance New instance * @param array $old_instance Old instance * @return array Updated instance */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; foreach ( array_keys( $this->config ) as $key ) $instance[$key] = isset( $new_instance[$key] ) ? $new_instance[$key] : ''; return $this->validate( $instance ); } /** * Draws the widget input form * @param array $instance Widget instance * @param array|null $exclude_options (optional) The options that should not be drawn in the form. * @return void */ public function form( $instance, $exclude_options = null ) { $exclude_options = apply_filters( $this->get_hook( 'excluded_form_options' ), $exclude_options ); $instance = wp_parse_args( (array) $instance, $this->defaults ); $i = $j = 0; foreach ( $instance as $opt => $value ) { if ( $opt == 'submit' || in_array( $opt, (array) $exclude_options ) ) continue; foreach ( array( 'datatype', 'default', 'help', 'input', 'input_attributes', 'label', 'no_wrap', 'options' ) as $attrib ) { if ( ! isset( $this->config[$opt][$attrib] ) ) $this->config[$opt][$attrib] = ''; } $input = $this->config[$opt]['input']; $label = $this->config[$opt]['label']; if ( $input == 'none' ) { if ( $opt == 'more' ) { $i++; $j++; // echo "
"; echo "'; } continue; } if ( $input == 'multiselect' ) { // Do nothing since it needs the values as an array $value = (array) $value; } elseif ( $this->config[$opt]['datatype'] == 'array' ) { if ( ! is_array( $value ) ) $value = ''; else $value = implode( ( 'textarea' == $input ? "\n" : ', ' ), $value ); } elseif ( $this->config[$opt]['datatype'] == 'hash' ) { if ( ! is_array( $value ) ) $value = ''; else { $new_value = ''; foreach ( $value AS $shortcut => $replacement ) $new_value .= "$shortcut => $replacement\n"; $value = $new_value; } } echo "
"; $input_id = $this->get_field_id( $opt ); $input_name = $this->get_field_name( $opt ); if ( $input == 'multiselect' ) $input_name .= '[]'; $attribs = "name='$input_name' id='$input_id' " . $this->config[$opt]['input_attributes']; if ( $label && ( $input != 'multiselect' ) ) echo " "; if ( $input == '' ) { } elseif ( $input == 'textarea' ) { echo "'; } elseif ( $input == 'select' ) { echo ""; } elseif ( $input == 'multiselect' ) { echo '
'; } elseif ( $input == 'checkbox' ) { echo ""; } else { if ( $input == 'short_text' ) { $tclass = ''; $tstyle = 'width:25px;'; } else { $tclass = 'widefat'; $tstyle = ''; } echo ""; } if ( $this->config[$opt]['help'] ) echo "