Skip to content

Instantly share code, notes, and snippets.

@billsaysthis
Created June 8, 2010 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billsaysthis/430374 to your computer and use it in GitHub Desktop.
Save billsaysthis/430374 to your computer and use it in GitHub Desktop.
class KachingleMedallionWidget extends WP_Widget {
function KachingleMedallionWidget() {
$widget_ops = array('classname' => 'widget_kachingle_medallion', 'description' => __( 'Add your Kachingle Medallions') );
$this->WP_Widget('KachingleMedallion', __('Kachingle Medallions'), $widget_ops);
}
/**
* Widget version of the Medallion code
**/
function widget($args, $instance) {
extract($args);
# Determine if we have a valid Medallion number
$medallion_no = $instance[KEY_KM_MEDALLION_NO];
if ( $medallion_no != KM_MED_NO_DEFAULT && $medallion_no != "") {
$title = apply_filters('widget_title', empty($instance[KEY_KM_HEADING]) ? '' : $instance[KEY_KM_HEADING], $instance, $this->id_base);
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
// TODO When Minis are ready fix following line
$m_style = (KM_STYLE_NARROW == $instance[KEY_KM_STYLE]) ? KM_STYLE_NARROW : KM_STYLE_WIDE;
echo build_km_string($medallion_no, $m_style, ("" != $instance[KEY_KM_MESSAGE]));
echo $after_widget;
} else { // end if $medallion_no test
echo "<!-- Kachingle Medallion / No Medallion number found / should never get here -->\n";
}
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance[KEY_KM_MEDALLION_NO] = strip_tags($new_instance[KEY_KM_MEDALLION_NO]);
$instance[KEY_KM_HEADING] = stripslashes(strip_tags($new_instance[KEY_KM_HEADING]));
$instance[KEY_KM_MESSAGE] = stripslashes(km_msg_filter($new_instance[KEY_KM_MESSAGE]));
$instance[KEY_KM_STYLE] = $new_instance[KEY_KM_STYLE];
return $instance;
}
function form($instance) {
//Defaults
// $defaults = array(KEY_KM_HEADING => KM_HEADING_DEFAULT, KEY_KM_MEDALLION_NO => KM_MED_NO_DEFAULT, KEY_KM_MESSAGE => KM_MESSAGE_DEFAULT, KEY_KM_STYLE => KM_STYLE_DEFAULT);
// $instance = wp_parse_args( (array) $instance, $defaults );
if(isset($instance[KEY_KM_MEDALLION_NO])) {
$medno = $instance[KEY_KM_MEDALLION_NO];
$title = isset($instance[KEY_KM_HEADING]) ? $instance[KEY_KM_HEADING] : '';
$messg = isset($instance[KEY_KM_MESSAGE]) ? $instance[KEY_KM_MESSAGE] : '';
$style = isset($instance[KEY_KM_STYLE]) ? $instance[KEY_KM_STYLE] : KM_STYLE_DEFAULT;
} else {
$title = KM_HEADING_DEFAULT;
$medno = KM_MED_NO_DEFAULT;
$messg = KM_MESSAGE_DEFAULT;
$style = KM_STYLE_DEFAULT;
}
?>
<p>
<label for="<?php echo $this->get_field_id(KEY_KM_HEADING); ?>"><?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id(KEY_KM_HEADING); ?>" name="<?php echo $this->get_field_name(KEY_KM_HEADING); ?>" type="text" value="<?php echo $title; ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id(KEY_KM_MEDALLION_NO); ?>"><?php _e('Medallion Number:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id(KEY_KM_MEDALLION_NO); ?>" name="<?php echo $this->get_field_name(KEY_KM_MEDALLION_NO); ?>" type="text" value="<?php echo $medno; ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id(KEY_KM_MESSAGE); ?>"><?php _e('Marketing Message:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id(KEY_KM_MESSAGE); ?>" name="<?php echo $this->get_field_name(KEY_KM_MESSAGE); ?>" type="text" value="<?php echo $messg; ?>" />
</label>
</p>
<p>
<label for="<?php echo KEY_KM_STYLE ?>"><?php _e('Style'); ?>:</label>
<?php
echo "<select name='".KEY_KM_STYLE."' id='".KEY_KM_STYLE."'>\n";
echo "<option value='".KM_STYLE_WIDE."'";
if(get_option(KEY_KM_STYLE) == KM_STYLE_WIDE)
echo " selected='selected'";
echo ">" . __(KM_STYLE_WIDE) . "</option>\n";
echo "<option value='".KM_STYLE_NARROW."'";
if(get_option(KEY_KM_STYLE) == KM_STYLE_NARROW)
echo " selected='selected'";
echo ">" . __(KM_STYLE_NARROW) . "</option>\n";
echo '<!-- ';
echo "<option value='".KM_STYLE_MINI1."'";
if(get_option(KEY_KM_STYLE) == KM_STYLE_MINI1)
echo " selected='selected'";
echo ">" . __(KM_STYLE_MINI1) . "</option>\n";
echo "<option value='".KM_STYLE_MINI2."'";
if(get_option(KEY_KM_STYLE) == KM_STYLE_MINI2)
echo " selected='selected'";
echo ">" . __(KM_STYLE_MINI2) . "</option>\n";
echo '-->';
echo "</select>\n";
?>
</p>
<?php
}
}
function km_widgets_init() {
if ( !is_blog_installed() )
return;
register_widget('KachingleMedallionWidget');
do_action('widgets_init');
}
add_action('init', 'km_widgets_init', 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment