title = __( 'Linkify Categories', $this->textdomain ); $this->config = array( // input can be 'checkbox', 'multiselect', 'select', 'short_text', 'text', 'textarea', 'hidden', or 'none' // datatype can be 'array' or 'hash' // can also specify input_attributes 'title' => array( 'input' => 'text', 'default' => __( 'Categories', $this->textdomain ), 'label' => __( 'Title', $this->textdomain ) ), 'categories' => array( 'input' => 'text', 'default' => '', 'label' => __( 'Categories', $this->textdomain ), 'help' => __( 'A single category ID/slug, or multiple category IDs/slugs defined via a comma-separated and/or space-separated string.', $this->textdomain ) ), 'before' => array( 'input' => 'text', 'default' => '', 'label' => __( 'Before text', $this->textdomain ), 'help' => __( 'Text to display before all categories.', $this->textdomain ) ), 'after' => array( 'input' => 'text', 'default' => '', 'label' => __( 'After text', $this->textdomain ), 'help' => __( 'Text to display after all categories.', $this->textdomain ) ), 'between' => array( 'input' => 'text', 'default' => ', ', 'label' => __( 'Between categories', $this->textdomain ), 'help' => __( 'Text to appear between categories.', $this->textdomain ) ), 'before_last' => array( 'input' => 'text', 'default' => '', 'label' => __( 'Before last category', $this->textdomain ), 'help' => __( 'Text to appear between the second-to-last and last element, if not specified, \'between\' value is used.', $this->textdomain ) ), 'none' => array( 'input' => 'text', 'default' => '', 'label' => __( 'None text', $this->textdomain ), 'help' => __( 'Text to appear when no categories have been found. If blank, then the entire function doesn\'t display anything.', $this->textdomain ) ) ); foreach ( $this->config as $key => $value ) $this->defaults[$key] = $value['default']; $widget_ops = array( 'classname' => 'widget_' . $this->widget_id, 'description' => __( 'Converts a list of categories (by slug or ID) into links to those categories.', $this->textdomain ) ); $control_ops = array(); //array( 'width' => 400, 'height' => 350, 'id_base' => $this->widget_id ); $this->WP_Widget( $this->widget_id, $this->title, $widget_ops, $control_ops ); } public function widget( $args, $instance ) { extract( $args ); /* Settings */ foreach ( array_keys( $this->config ) as $key ) $$key = apply_filters( 'linkify_categories_widget_'.$key, $instance[$key] ); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; // Widget content c2c_linkify_categories( $categories, $before, $after, $between, $before_last, $none ); echo $after_widget; } public function update( $new_instance, $old_instance ) { $instance = $old_instance; foreach ( $new_instance as $key => $value ) $instance[$key] = $value; return $instance; } public function form( $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults ); $i = $j = 0; foreach ( $instance as $opt => $value ) { if ( $opt == 'submit' ) 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 "
$label
"; echo "'; } continue; } if ( $input == 'checkbox' ) { $checked = ( $value == 1 ) ? 'checked=checked ' : ''; $value = 1; } else { $checked = ''; }; if ( $input == 'multiselect' ) { // Do nothing since it needs the values as an array } 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 ); $value = esc_attr( $value ); if ( $label && ( $input != 'multiselect' ) ) echo " "; if ( $input == 'textarea' ) { echo "'; } elseif ( $input == 'select' ) { echo ""; } elseif ( $input == 'multiselect' ) { echo '
'; } elseif ( !empty( $input ) ) { // If no input defined, then not valid input if ( $input == 'short_text' ) { $tclass = ''; $tstyle = 'width:25px;'; $input = 'text'; } else { $tclass = 'widefat'; $tstyle = ''; } echo "config[$opt]['input_attributes']} />"; } if ( $this->config[$opt]['help'] ) echo "