Advertisement
iamdangavin

Register A Widget

Jul 11th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.70 KB | None | 0 0
  1. /* ---------------------------------------------------------------------*/
  2. /* Follow Me Widget */
  3.  
  4. class dg_followWidget extends WP_Widget {
  5.     /** constructor */
  6.     function dg_followWidget() {
  7.         $followwidget_ops = array( 'classname' => 'widget_text', 'description' => __('Link to your twitter page for viewers to follow you.'));
  8.         $control_ops = array('width' => 200);
  9.         parent::WP_Widget(false, $name = 'Follow Me', $followwidget_ops, $control_ops);
  10.     }
  11.  
  12.     /** @see WP_Widget::widget */
  13.     function widget($args, $instance) {    
  14.         extract( $args );
  15.         $title = apply_filters('widget_title', $instance['title']);
  16.         $username = apply_filters('widget_text', $instance['username']);
  17.         ?>
  18.         <li id="follow-me" class="widget-container">
  19.         <?php if ( $title ) echo $before_title . $title . $after_title; ?>
  20.        
  21.         <?php if ( $title ) ?>
  22.         <div class="follow-username">
  23.         <span class="twit-icon" style="margin-right: 5px;">
  24.             <img src="http://twitter-badges.s3.amazonaws.com/t_mini-b.png" height="15px" width="15px"/>
  25.         </span>
  26.             <a href="http://www.twitter.com/#!/<?php echo $username; ?>" target="_blank"><?php echo $username; ?></a>
  27.         </div>
  28.        
  29.         </li>
  30.        
  31.        
  32.  <?php
  33.  
  34.      }
  35.  
  36.     /** @see WP_Widget::update */
  37.     function update($new_instance, $old_instance) {            
  38.         $instance = $old_instance;
  39.         $instance['title'] = strip_tags($new_instance['title']);
  40.         $instance['username'] = strip_tags($new_instance['username']);
  41.         return $instance;
  42.     }
  43.  
  44.     /** @see WP_Widget::form */
  45.     function form($instance) {             
  46.         $title = esc_attr($instance['title']);
  47.         $username = esc_attr($instance['username']);
  48.         ?>
  49.        
  50.             <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  51.             <br/>
  52.             <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; ?>" />
  53.             <br/>
  54.             <br/>
  55.         <label for="<?php echo $this->get_field_id('username'); ?>"><?php _e('Username:'); ?></label>
  56.         <br/>
  57.         <input class="code widefat" id="<?php echo $this->get_field_id('username'); ?>" name="<?php echo $this->get_field_name('username'); ?>" type="text" value="<?php echo $username; ?>" />
  58.         <span class="description">without @</span>
  59.    
  60.        
  61.         <?php
  62.     }
  63.  
  64. } // class quoteWidget
  65. // register quoteWidget widget
  66. add_action('widgets_init', create_function('', 'return register_widget("dg_followWidget");'));
  67.  
  68. /* ---------------------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement