<?php

Class Forest_Jungle_Safari_My_Recent_Posts_Widget extends WP_Widget_Recent_Posts {
  function widget($forest_jungle_safari_args, $forest_jungle_safari_instance) {
      if ( ! isset( $forest_jungle_safari_args['widget_id'] ) ) {
      $forest_jungle_safari_args['widget_id'] = $this->id;
    }
    $forest_jungle_safari_forest_jungle_safari_title = ( ! empty( $forest_jungle_safari_instance['title'] ) ) ? $forest_jungle_safari_instance['title'] : __( 'Recent Posts', 'forest-jungle-safari' );
    /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
    $forest_jungle_safari_forest_jungle_safari_title = apply_filters( 'widget_title', $forest_jungle_safari_forest_jungle_safari_title, $forest_jungle_safari_instance, $this->id_base );
    $forest_jungle_safari_number = ( ! empty( $forest_jungle_safari_instance['number'] ) ) ? absint( $forest_jungle_safari_instance['number'] ) : 5;
    if ( ! $forest_jungle_safari_number )
        $forest_jungle_safari_number = 5;
    $forest_jungle_safari_show_date = isset( $forest_jungle_safari_instance['show_date'] ) ? $forest_jungle_safari_instance['show_date'] : false;
    /**
     * Filter the arguments for the Recent Posts widget.
     *
     * @since 3.4.0
     *
     * @see WP_Query::get_posts()
     *
     * @param array $forest_jungle_safari_args An array of arguments used to retrieve the recent posts.
     */
    $forest_jungle_safari_r = new WP_Query( apply_filters( 'widget_posts_args', array(
        'posts_per_page'      => $forest_jungle_safari_number,
        'no_found_rows'       => true,
        'post_status'         => 'publish',
        'ignore_sticky_posts' => true
    ) ) );
    if ($forest_jungle_safari_r->have_posts()) :
    ?>
    <?php echo $forest_jungle_safari_args['before_widget']; ?>
    <?php if ( $forest_jungle_safari_forest_jungle_safari_title ) {
        echo $forest_jungle_safari_args['before_title'] . esc_html($forest_jungle_safari_forest_jungle_safari_title) . $forest_jungle_safari_args['after_title'];
    } ?>
    <ul>
      <?php while ( $forest_jungle_safari_r->have_posts() ) : $forest_jungle_safari_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">
              <div class="d-flex date-comment align-items-center mb-1">
               <?php 
                  $forest_jungle_safari_archive_year  = get_the_time('Y'); 
                  $forest_jungle_safari_archive_month = get_the_time('m'); 
                  $forest_jungle_safari_archive_day   = get_the_time('d'); 
                ?>
               <a href="<?php echo esc_url( get_day_link( $forest_jungle_safari_archive_year, $forest_jungle_safari_archive_month, $forest_jungle_safari_archive_day)); ?>"><i class="fa-solid fa-calendar-days me-2"></i><?php echo esc_html( get_the_date() ); ?><span class="screen-reader-text"><?php echo esc_html( get_the_date() ); ?></span></a>
               <div class="footer-tags"><i class="fa-solid fa-tag me-2 align-items-center"></i><?php the_tags( '<span>', '</span>' ); ?></div>
              </div>
              <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </div>
          </div>
        </div>
      </li>
      <?php endwhile;
      wp_reset_postdata(); ?>
    </ul>
    <?php echo $forest_jungle_safari_args['after_widget'];
    endif;
  }
}
function forest_jungle_safari_my_recent_widget_registration() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('Forest_Jungle_Safari_My_Recent_Posts_Widget');
}
add_action('widgets_init', 'forest_jungle_safari_my_recent_widget_registration');
