Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class cals_twitterfetcher extends WP_Widget {
- //Constructor--initiate the widget
- function cals_twitterfetcher(){
- parent::WP_Widget(false, $name = __('Cals WP Twitterfetcher Widget', 'cals-twitterfetcher') );
- }
- /**
- *
- * Widget form creation--create the widget form in the administration
- */
- // widget form creation
- function form($instance) {
- // Check values
- if( $instance) {
- $title = esc_attr($instance['title']);
- $text = esc_attr($instance['text']);
- $textarea = esc_textarea($instance['textarea']);
- $checkbox = esc_attr($instance['checkbox']);
- } else {
- $title = '';
- $text = '';
- $textarea = '';
- $checkbox = '';
- }
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'cals-twitterfetcher'); ?></label>
- <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text:', 'cals-twitterfetcher'); ?></label>
- <input id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" type="text" value="<?php echo $text; ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('textarea'); ?>"><?php _e('Textarea:', 'cals-twitterfetcher'); ?></label>
- <textarea id="<?php echo $this->get_field_id('textarea'); ?>" name="<?php echo $this->get_field_name('textarea'); ?>"><?php echo $textarea; ?></textarea>
- </p>
- <p>
- <input id="<?php echo $this->get_field_id('checkbox'); ?>" name="<?php echo $this->get_field_name('checkbox'); ?>" type="checkbox" value="1" <?php checked( '1', $checkbox ); ?> />
- <label for="<?php echo $this->get_field_id('checkbox'); ?>"><?php _e('Checkbox', 'cals-twitterfetcher'); ?></label>
- </p>
- <?php
- }
- /**
- *Update--save widget data during edition
- */
- function update($new_instance, $old_instance) {
- $instance = $old_instance;
- // Fields
- $instance['title'] = strip_tags($new_instance['title']);
- $instance['text'] = strip_tags($new_instance['text']);
- $instance['textarea'] = strip_tags($new_instance['textarea']);
- $instance['checkbox'] = strip_tags($new_instance['checkbox']);
- return $instance;
- }
- /**
- * widget--display the widget content on the front-end
- */
- function widget($args, $instance) {
- extract( $args );
- // these are the widget options
- $title = apply_filters('widget_title', $instance['title']);
- $text = $instance['text'];
- $textarea = $instance['textarea'];
- echo $before_widget;
- // Display the widget
- echo '<div>';
- // Check if title is set
- if ( $title ) {
- echo $before_title . $title . $after_title;
- }
- // Check if text is set
- if( $text ) {
- echo '<p>'.$text.'</p>';
- }
- // Check if textarea is set
- if( $textarea ) {
- echo '<p>'.$textarea.'</p>';
- }
- // Check if checkbox is checked
- if( $checkbox == true ) {
- echo 'THis message is displayed if checkd';
- }
- echo '</div>';
- echo $after_widget;
- }
- }
- // register idget, enables use in the wordpress dashboard
- add_action('widgets_init', create_function('', 'return register_widget("cals_twitterfetcher");'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement