Twitter_Widget

The Responsive Minimal Twitter Widget class.

Defined (1)

The class is defined in the following location(s).

/functions/widgets.php  
  1. class Twitter_Widget extends WP_Widget { 
  2.  
  3. /*** Widget setup.*/ 
  4. function Twitter_Widget() { 
  5. /** Widget settings. */ 
  6. $widget_ops = array( 'classname' => 'twitter', 'description' => __('Select the twitter account to show.', 'twitter') ); 
  7.  
  8. /** Widget control settings. */ 
  9. $control_ops = array( 'width' => 200, 'height' => 350, 'id_base' => 'twitter-widget' ); 
  10.  
  11. /** Create the widget. */ 
  12. $this->WP_Widget( 'twitter-widget', __('Shock Twitter', 'twitter'), $widget_ops, $control_ops ); 
  13.  
  14. /** 
  15. * How to display the widget on the screen. 
  16. */ 
  17. function widget( $args, $instance ) { 
  18. extract( $args ); 
  19.  
  20. /** Our variables from the widget settings. */ 
  21. $title = apply_filters('widget_title', $instance['title'] ); 
  22. $name = $instance['name']; 
  23. $tw_num = $instance['tweet_num']; 
  24.  
  25. /** Before widget (defined by themes). */ 
  26. echo $before_widget; 
  27.  
  28. /** Display the widget title if one was input (before and after defined by themes). */ 
  29. echo $before_title . $title . $after_title; 
  30.  
  31. printf(__('<ul id="twitter_update_list"><li>Twitter feed loading...</li></ul>')); 
  32. printf(__('<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>')); 
  33. printf(__('<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/'.$name.'.json?callback=twitterCallback2&count='.$tw_num.'"></script>')); 
  34.  
  35. /** After widget (defined by themes). */ 
  36. echo $after_widget; 
  37. /** 
  38. * Update the widget settings. 
  39. */ 
  40. function update( $new_instance, $old_instance ) { 
  41. $instance = $old_instance; 
  42.  
  43. /** Strip tags for title and name to remove HTML (important for text inputs). */ 
  44. $instance['title'] = strip_tags( $new_instance['title'] ); 
  45. $instance['name'] = strip_tags( $new_instance['name'] ); 
  46. $instance['tweet_num'] = $new_instance['tweet_num']; 
  47.  
  48. return $instance; 
  49.  
  50. /** 
  51. * Displays the widget settings controls on the widget panel. 
  52. * Make use of the get_field_id() and get_field_name() function 
  53. * when creating your form elements. 
  54. */ 
  55. function form( $instance ) { 
  56.  
  57. /** Set up some default widget settings. */ 
  58. $defaults = array( 'title' => __('Twitter feed', 'twitter'), 'name' => __('Tweet name', 'twitter'), 'tweet_num' => '3'); 
  59. $instance = wp_parse_args( (array) $instance, $defaults ); ?> 
  60. <p> 
  61. <label for="<?php echo $this->get_field_id( 'title' ); ?>"> 
  62. <?php _e('Title:', 'hybrid'); ?> 
  63. </label> 
  64. <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" /> 
  65. </p> 
  66. <p> 
  67. <label for="<?php echo $this->get_field_id( 'name' ); ?>"> 
  68. <?php _e('Twitter Name:', 'twitter'); ?> 
  69. </label> 
  70. <input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:100%;" /> 
  71. </p> 
  72. <p> 
  73. <label for="<?php echo $this->get_field_id( 'tweet_num' ); ?>"> 
  74. <?php _e('Number of tweets:', 'twitter'); ?> 
  75. </label> 
  76. <select id="<?php echo $this->get_field_id( 'tweet_num' ); ?>" name="<?php echo $this->get_field_name( 'tweet_num' ); ?>" class="widefat" style="width:100%;"> 
  77. <option <?php if ( '3' == $instance['tweet_num'] ) echo 'selected="selected"'; ?>>3</option> 
  78. <option <?php if ( '4' == $instance['tweet_num'] ) echo 'selected="selected"'; ?>>4</option> 
  79. <option <?php if ( '5' == $instance['tweet_num'] ) echo 'selected="selected"'; ?>>5</option> 
  80. <option <?php if ( '6' == $instance['tweet_num'] ) echo 'selected="selected"'; ?>>6</option> 
  81. </select> 
  82. </p> 
  83. <?php