'awp_recent_comments awp_widget', 'description' => __('Widget to display recent comments.', 'awp'));
$control_ops = array('width' => 200, 'height' => 250);
parent::__construct(false, $name = __('AWP Recent Comments', 'awp'), $widget_ops, $control_ops );
$this->alt_option_name = 'widget_recent_comments';
if ( is_active_widget(false, false, $this->id_base) )
add_action( 'comment_post', array($this, 'flush_widget_cache') );
add_action( 'edit_comment', array($this, 'flush_widget_cache') );
add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
}
function widget( $args, $instance ) {
global $comments, $comment,$image,$com;
extract($args, EXTR_SKIP);
$output = '';
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments', 'awp' );
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
if ( ! $number )
$number = 5;
$comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) );
$output .= $before_widget;
if ( $title )
$output .= $before_title . $title . $after_title;
$output .= '
';
if ( $comments ) {
// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
foreach ( (array) $comments as $comment) {
$posttitle=get_the_title($comment->comment_post_ID);
if($instance['show_comment']){
$com=get_comment_text();
}
if($instance['show_gravatar']){
$comm=get_comment_ID();
$id = get_comment($comm);
$image=get_avatar($id,'32');
}
$output .= '- ' .sprintf(_x('%1$s %2$s on %3$s %4$s', 'awp'), '' ,'') . '
';
}
}
$output .= $after_widget;
echo $output;
$cache[$args['widget_id']] = $output;
wp_cache_set('widget_recent_comments', $cache, 'widget');
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = absint( $new_instance['number'] );
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset($alloptions['widget_recent_comments']) )
delete_option('widget_recent_comments');
$instance['show_comment']=strip_tags($new_instance['show_comment']);
$instance['show_gravatar']=strip_tags($new_instance['show_gravatar']);
return $instance;
}
function form( $instance ) {
$defaults=array('title'=>'Recent Comments','show_comment'=>'0','number'=>'5','show_gravatar'=>'0');
$instance = wp_parse_args( (array) $instance, $defaults );
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
?>
id="get_field_id('show_comment'); ?>" name="get_field_name('show_comment'); ?>" />
id="get_field_id('show_gravatar'); ?>" name="get_field_name('show_gravatar'); ?>" />