• Hi Friends,

    First of all thank you for the great support your deliver.
    I would like to extend my current default “Recent Comment Widget” with a date and time. Is that possible?

    wp-includes/default-widgets.php

    /**
    		 * Filter the arguments for the Recent Comments widget.
    		 *
    		 * @since 3.4.0
    		 *
    		 * @see get_comments()
    		 *
    		 * @param array $comment_args An array of arguments used to retrieve the recent comments.
    		 */
    		$comments = get_comments( apply_filters( 'widget_comments_args', array(
    			'number'      => $number,
    			'status'      => 'approve',
    			'post_status' => 'publish'
    		) ) );
    
    		$output .= $args['before_widget'];
    		if ( $title ) {
    			$output .= $args['before_title'] . $title . $args['after_title'];
    		}
    
    		$output .= '<ul id="recentcomments">';
    		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) {
    				$output .= '<li class="recentcomments">';
    				/* translators: comments widget: 1: comment author, 2: post link */
    				$output .= sprintf( _x( '%1$s on %2$s', 'widgets' ),
    					'<span class="comment-author-link">' . get_comment_author_link() . '</span>',
    					'<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>'
    				);
    				$output .= '</li>';
    			}
    		}
    		$output .= '</ul>';
    		$output .= $args['after_widget'];
    
    		echo $output;
    
    		if ( ! $this->is_preview() ) {
    			$cache[ $args['widget_id'] ] = $output;
    			wp_cache_set( 'widget_recent_comments', $cache, 'widget' );
    		}
    	}
    
    	public function update( $new_instance, $old_instance ) {
    		$instance = $old_instance;
    		$instance['title'] = strip_tags($new_instance['title']);
    		$instance['number'] = absint( $new_instance['number'] );
    		$this->flush_widget_cache();
    
    		$alloptions = wp_cache_get( 'alloptions', 'options' );
    		if ( isset($alloptions['widget_recent_comments']) )
    			delete_option('widget_recent_comments');
    
    		return $instance;
    	}
    
    	public function form( $instance ) {
    		$title  = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    		$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
    ?>
    		<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    		<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; ?>" /></p>
    
    		<p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label>
    		<input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
    
    <?php
    	}
    }

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add date & time to Recent Comment Widget’ is closed to new replies.