Advertisement
miriamdepaula

WordPress: Sidebar Comment Form Widget

Jun 22nd, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. <?php
  2. /**
  3.  * wpmidia custom Widgets - Sidebar Comment Form Widget
  4.  *
  5.  * @package WordPress
  6.  * @subpackage wpmidia
  7.  * @author Miriam de Paula - http://wpmidia.com.br
  8.  * @since 22/06/2012 - v1
  9.  */
  10. class sidebar_commentform_Widget extends WP_Widget
  11. {
  12.    
  13.         function sidebar_commentform_Widget(){
  14.             $widget_ops = array( 'description' => 'Exibe o formulário de comentários na sidebar' );
  15.             $control_ops = array( 'width' => 250, 'height' => 200 );
  16.             parent::WP_Widget( false, $name = 'Sidebar Comment Form', $widget_ops, $control_ops );
  17.         }
  18.  
  19.         /* Displays the Widget in the front-end */
  20.         function widget( $args, $instance ){
  21.            
  22.             if(is_single()) {
  23.                
  24.                 extract($args);
  25.                
  26.                 global $post;
  27.                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? 'Comentários' : esc_html( $instance['title'] ) );
  28.                    
  29.                 echo $before_widget;
  30.                
  31.                 if ( ! empty( $title ) )
  32.                     echo $before_title . $title . $after_title;
  33.                
  34.                 comments_template( '', true );
  35.                
  36.                 echo $after_widget;
  37.            
  38.             }
  39.         }
  40.        
  41.         /*Saves the settings. */
  42.         function update( $new_instance, $old_instance ){
  43.             $instance = $old_instance;
  44.             $instance['title'] = strip_tags( $new_instance['title'] );
  45.  
  46.             return $instance;
  47.         }  
  48.        
  49.         /*Creates the form for the widget in the back-end. */
  50.         function form( $instance ){
  51.             //Defaults
  52.             $instance = wp_parse_args( (array) $instance, array( 'title' => 'Comentários', 'qtd_agenda' => 5 ) );
  53.    
  54.             $title = esc_attr( $instance['title'] );
  55.                
  56.             # Title
  57.             echo '<p><label for="' . $this->get_field_id('title') . '">' . 'Título:' . '</label><input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></p>';
  58.            
  59.            
  60.         }
  61.  
  62. }
  63.  
  64. function sidebar_commentform_Widget_Init() {
  65.     register_widget('sidebar_commentform_Widget');
  66. }
  67.  
  68. add_action('widgets_init', 'sidebar_commentform_Widget_Init');
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement