fields = array( 'title', 'feed_url', 'max_shows' ); $this->checkboxes = array( 'age_limit', 'artist_name', 'country', 'show_name', 'venue_stage', 'show_time', 'ticket_info' ); $this->layouts = array( 'Classic', 'iCal' ); // Future i10n support // load_plugin_textdomain( PLUGIN_LOCALE, false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); } //End of artistdatapress_widget function /** * Back-end widget form. * * @see WP_Widget::form() * * @uses wp_parse_args * @uses esc_attr * @uses get_field_id * @uses get_field_name * @uses checked * * @param array $instance Previously saved values from database. */ function form( $instance ) { $defaults['title'] = 'ArtistDataPress'; $defaults['max_shows'] = ''; $defaults['layout'] = 'Classic'; foreach ( $this->checkboxes as $checkbox ) { $defaults[$checkbox] = 0; } // End of $checkboxes foreach $instance = wp_parse_args( (array) $instance, $defaults ); foreach ( $this->fields as $field ) { $label = ucwords( str_replace( '_', ' ', $field ) ); echo '

'; echo ( $field == 'feed_url' ? '
' . __( '*Overrides the plugin settings feed URL.' ) . '' : '' ); } // End of $fields foreach echo '

'; echo '

'; foreach ( $this->checkboxes as $checkbox ) { $check = ( isset( $instance[$checkbox] ) ? (bool) $instance[$checkbox] : false ); $words = str_replace( '_', ' ', $checkbox ); echo '

'; echo ( $checkbox == 'artist_name' ? '
' . __( '*Requires "Display show name" also' ) . '' : '' ); echo '

'; } // End of $checkboxes foreach } //End of form function /** * Front-end display of widget. * * @see WP_Widget::widget() * * @uses apply_filters * @uses get_widget_layout * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ function widget( $args, $instance ) { extract( $args ); echo $before_widget; $title = ( !empty( $instance['title'] ) ? apply_filters( 'widget_title', $instance['title'] ) : '' ); echo ( !empty( $title ) ? $before_title . $title . $after_title : '' ); echo ''; echo $after_widget; } //End of widget function /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array $instance Updated safe values to be saved. */ function update( $new_instance, $old_instance ) { $instance = $old_instance; // Validate and sanitize text fields foreach ( $this->fields as $field ) { $instance[$field] = strip_tags( $new_instance[$field] ); } // End of $fields foreach // Validate and sanitize checkboxes foreach ( $this->checkboxes as $checkbox ) { $instance[$checkbox] = isset( $new_instance[$checkbox] ); } // End of $checkboxes foreach // Validate and sanitize select $instance['layout'] = strip_tags( $new_instance['layout'] ); return $instance; } //End of update function } // End of class artistdatapress_widget ?>