<?php

Class Virtual_Assistant_My_Recent_Posts_Widget extends WP_Widget_Recent_Posts {
  function widget($virtual_assistant_args, $virtual_assistant_instance) {
      if ( ! isset( $virtual_assistant_args['widget_id'] ) ) {
      $virtual_assistant_args['widget_id'] = $this->id;
    }
    $virtual_assistant_title = ( ! empty( $virtual_assistant_instance['title'] ) ) ? $virtual_assistant_instance['title'] : __( 'Recent Posts', 'virtual-assistant' );
    /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
    $virtual_assistant_title = apply_filters( 'widget_title', $virtual_assistant_title, $virtual_assistant_instance, $this->id_base );
    $virtual_assistant_number = ( ! empty( $virtual_assistant_instance['number'] ) ) ? absint( $virtual_assistant_instance['number'] ) : 5;
    if ( ! $virtual_assistant_number )
        $virtual_assistant_number = 5;
    $virtual_assistant_show_date = isset( $virtual_assistant_instance['show_date'] ) ? $virtual_assistant_instance['show_date'] : false;
    /**
     * Filter the arguments for the Recent Posts widget.
     *
     * @since 3.4.0
     *
     * @see WP_Query::get_posts()
     *
     * @param array $virtual_assistant_args An array of arguments used to retrieve the recent posts.
     */
    $virtual_assistant_r = new WP_Query( apply_filters( 'widget_posts_args', array(
        'posts_per_page'      => $virtual_assistant_number,
        'no_found_rows'       => true,
        'post_status'         => 'publish',
        'ignore_sticky_posts' => true
    ) ) );
    if ($virtual_assistant_r->have_posts()) :
    ?>
    <?php echo $virtual_assistant_args['before_widget']; ?>
    <?php if ( $virtual_assistant_title ) {
        echo $virtual_assistant_args['before_title'] . esc_html($virtual_assistant_title) . $virtual_assistant_args['after_title'];
    } ?>
    <ul>
      <?php while ( $virtual_assistant_r->have_posts() ) : $virtual_assistant_r->the_post(); ?>
      <li>
        <div class="recent-post-box">
          <div class="media post-thumb">
            <?php if(has_post_thumbnail()) { the_post_thumbnail(); } ?>
            <div class="media-body post-content">
              <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
              <div class="d-flex date-comment">
               <?php if ( $virtual_assistant_show_date ) : ?>
                <p class="post-date"><?php the_date(); ?></p>
               <?php endif; ?>
               <div class="date-comment1"><?php comments_number( __('0 Comment', 'virtual-assistant'), __('0 Comments', 'virtual-assistant'), __('% Comments', 'virtual-assistant') ); ?></div>
              </div>
            </div>
          </div>
        </div>
      </li>
      <?php endwhile;
      wp_reset_postdata(); ?>
    </ul>

    <?php echo $virtual_assistant_args['after_widget'];

    endif;
  }
}
function virtual_assistant_my_recent_widget_registration() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('Virtual_Assistant_My_Recent_Posts_Widget');
}
add_action('widgets_init', 'virtual_assistant_my_recent_widget_registration');
