<?php

Class Chartered_Accountant_My_Recent_Posts_Widget extends WP_Widget_Recent_Posts {
  function widget($chartered_accountant_args, $chartered_accountant_instance) {
      if ( ! isset( $chartered_accountant_args['widget_id'] ) ) {
      $chartered_accountant_args['widget_id'] = $this->id;
    }
    $chartered_accountant_title = ( ! empty( $chartered_accountant_instance['title'] ) ) ? $chartered_accountant_instance['title'] : __( 'Recent Posts', 'chartered-accountant' );
    /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
    $chartered_accountant_title = apply_filters( 'widget_title', $chartered_accountant_title, $chartered_accountant_instance, $this->id_base );
    $chartered_accountant_number = ( ! empty( $chartered_accountant_instance['number'] ) ) ? absint( $chartered_accountant_instance['number'] ) : 5;
    if ( ! $chartered_accountant_number )
        $chartered_accountant_number = 5;
    $chartered_accountant_show_date = isset( $chartered_accountant_instance['show_date'] ) ? $chartered_accountant_instance['show_date'] : false;
    /**
     * Filter the arguments for the Recent Posts widget.
     *
     * @since 3.4.0
     *
     * @see WP_Query::get_posts()
     *
     * @param array $chartered_accountant_args An array of arguments used to retrieve the recent posts.
     */
    $chartered_accountant_r = new WP_Query( apply_filters( 'widget_posts_args', array(
        'posts_per_page'      => $chartered_accountant_number,
        'no_found_rows'       => true,
        'post_status'         => 'publish',
        'ignore_sticky_posts' => true
    ) ) );
    if ($chartered_accountant_r->have_posts()) :
    ?>
    <?php echo $chartered_accountant_args['before_widget']; ?>
    <?php if ( $chartered_accountant_title ) {
        echo $chartered_accountant_args['before_title'] . esc_html($chartered_accountant_title) . $chartered_accountant_args['after_title'];
    } ?>
    <ul>
      <?php while ( $chartered_accountant_r->have_posts() ) : $chartered_accountant_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 ( $chartered_accountant_show_date ) : ?>
                <p class="post-date"><?php the_date(); ?></p>
               <?php endif; ?>
               <div class="date-comment1"><?php comments_number( __('0 Comment', 'chartered-accountant'), __('0 Comments', 'chartered-accountant'), __('% Comments', 'chartered-accountant') ); ?></div>
              </div>
            </div>
          </div>
        </div>
      </li>
      <?php endwhile;
      wp_reset_postdata(); ?>
    </ul>

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

    endif;
  }
}
function chartered_accountant_my_recent_widget_registration() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('Chartered_Accountant_My_Recent_Posts_Widget');
}
add_action('widgets_init', 'chartered_accountant_my_recent_widget_registration');
