Advertisement
Daniel_Dropik

MyFirstWidget_error

Jan 15th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.34 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class cals_twitterfetcher extends WP_Widget {
  5.  
  6.    
  7.  
  8.    
  9.  
  10.     //Constructor--initiate the widget
  11.         function cals_twitterfetcher(){
  12.        
  13.           parent::WP_Widget(false, $name = __('Cals WP Twitterfetcher Widget', 'cals-twitterfetcher') );
  14.         }
  15.  
  16.     /**
  17.      *
  18.      * Widget form creation--create the widget form in the administration
  19.      */
  20.  
  21. // widget form creation
  22. function form($instance) {
  23.         // Check values
  24.             if( $instance) {
  25.              $title = esc_attr($instance['title']);
  26.              $text = esc_attr($instance['text']);
  27.              $textarea = esc_textarea($instance['textarea']);
  28.              $checkbox = esc_attr($instance['checkbox']);
  29.         } else {
  30.              $title = '';
  31.              $text = '';
  32.              $textarea = '';
  33.              $checkbox = '';
  34.         }
  35.         ?>
  36.         <p>
  37.         <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'cals-twitterfetcher'); ?></label>
  38.         <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
  39.         </p>
  40.         <p>
  41.         <label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text:', 'cals-twitterfetcher'); ?></label>
  42.         <input id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" type="text" value="<?php echo $text; ?>" />
  43.         </p>
  44.         <p>
  45.         <label for="<?php echo $this->get_field_id('textarea'); ?>"><?php _e('Textarea:', 'cals-twitterfetcher'); ?></label>
  46.         <textarea id="<?php echo $this->get_field_id('textarea'); ?>" name="<?php echo $this->get_field_name('textarea'); ?>"><?php echo $textarea; ?></textarea>
  47.         </p>
  48.         <p>
  49.         <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 ); ?> />
  50.         <label for="<?php echo $this->get_field_id('checkbox'); ?>"><?php _e('Checkbox', 'cals-twitterfetcher'); ?></label>
  51.         </p>
  52. <?php
  53. }
  54.  
  55.  
  56.     /**
  57.      *Update--save widget data during edition
  58.      */
  59.    
  60.         function update($new_instance, $old_instance) {
  61.       $instance = $old_instance;
  62.       // Fields
  63.       $instance['title'] = strip_tags($new_instance['title']);
  64.       $instance['text'] = strip_tags($new_instance['text']);
  65.       $instance['textarea'] = strip_tags($new_instance['textarea']);
  66.       $instance['checkbox'] = strip_tags($new_instance['checkbox']);
  67.      return $instance;
  68. }
  69.  
  70.  
  71.  
  72.     /**
  73.      * widget--display the widget content on the front-end
  74.      */
  75.  
  76. function widget($args, $instance) {
  77.    extract( $args );
  78.    // these are the widget options
  79.    $title = apply_filters('widget_title', $instance['title']);
  80.    $text = $instance['text'];
  81.    $textarea = $instance['textarea'];
  82.    echo $before_widget;
  83.    // Display the widget
  84.    echo '<div>';
  85.  
  86.    // Check if title is set
  87.    if ( $title ) {
  88.       echo $before_title . $title . $after_title;
  89.    }
  90.  
  91.    // Check if text is set
  92.    if( $text ) {
  93.       echo '<p>'.$text.'</p>';
  94.    }
  95.    // Check if textarea is set
  96.    if( $textarea ) {
  97.      echo '<p>'.$textarea.'</p>';
  98.    }
  99.    // Check if checkbox is checked
  100.    if( $checkbox == true ) {
  101.      echo 'THis message is displayed if checkd';
  102.    }
  103.    echo '</div>';
  104.    echo $after_widget;
  105. }
  106.  
  107. }
  108.    
  109.  
  110.  
  111. // register idget, enables use in the wordpress dashboard
  112.  
  113. add_action('widgets_init', create_function('', 'return register_widget("cals_twitterfetcher");'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement