Created
June 3, 2014 18:48
-
-
Save wpmark/d960bd3bfc5578348e0c to your computer and use it in GitHub Desktop.
Widget Starter Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/****************************************************************************************** | |
* Class sensl_whistles_widget | |
* Builds the widget for adding post content to widgetized area extending WP_Widget | |
******************************************************************************************/ | |
class MDW_Widget extends WP_Widget { | |
function mdw_widget() { | |
$widget_ops = array( | |
'classname' => 'mdw_widget', | |
'description' => __( "Description of widget apearing on widgets page in admin.") | |
); | |
$this->WP_Widget( | |
'mdw_widget', | |
__( 'Widget Display Title in Admin', 'mdw_widget' ), | |
$widget_ops | |
); | |
} | |
/************************************************************* | |
* build the widget output to the widget area | |
*************************************************************/ | |
function widget( $args, $instance ) { | |
extract( $args ); | |
/* output the before widget content declared when sidebar is registered */ | |
echo $before_widget; | |
// widget front end output here | |
/* output the after widget content declared when sidebar is registered */ | |
echo $after_widget; | |
} // end widget output | |
/************************************************************* | |
* widget update function | |
*************************************************************/ | |
function update( $new_instance, $old_instance ) { | |
$instance = $old_instance; | |
$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] ); | |
/************************************************************* | |
* repeat the above for any other form fields you have used | |
*************************************************************/ | |
return $instance; | |
} | |
/************************************************************* | |
* widget dashboard output | |
*************************************************************/ | |
function form( $instance ) { | |
if( isset( $instance[ 'title' ] ) ) { | |
$title = esc_attr( $instance[ 'title' ] ); | |
} else { | |
$title = ''; | |
} | |
/************************************************************* | |
* repeat the above for any other form fields you have used | |
*************************************************************/ | |
/************************************************************* | |
* html markup to output widget form in admin | |
*************************************************************/ | |
?> | |
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"> | |
<?php _e( 'Title for whistle:' ); ?> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'title'); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></label></p> | |
<?php | |
} | |
} // ends class | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment