Recent Posts Widget Extended - Version 0.9.7

Version Description

  • 9/13/2014 =
  • Add: Relative date option eg: 4 days ago. Props George Venios
  • Add: Featured Video Plus plugin support.
  • Add: Hide widget if no posts exist.
  • Add: Fallback to the image attachment if no image url exist in the resizer script.
  • Fix: Compatibility issue if the user theme use the same code library(Aqua Resizer) and causing blank screen.
Download this release

Release Info

Developer satrya
Plugin Icon 128x128 Recent Posts Widget Extended
Version 0.9.7
Comparing to
See all releases

Code changes from version 0.9.6 to 0.9.7

classes/widget.php CHANGED
@@ -47,23 +47,29 @@ class Recent_Posts_Widget_Extended extends WP_Widget {
47
  function widget( $args, $instance ) {
48
  extract( $args );
49
 
50
- // Output the theme's $before_widget wrapper.
51
- echo $before_widget;
52
 
53
- // If both title and title url is not empty, display it.
54
- if ( ! empty( $instance['title_url'] ) && ! empty( $instance['title'] ) ) {
55
- echo $before_title . '<a href="' . esc_url( $instance['title_url'] ) . '" title="' . esc_attr( $instance['title'] ) . '">' . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . '</a>' . $after_title;
56
 
57
- // If the title not empty, display it.
58
- } elseif ( ! empty( $instance['title'] ) ) {
59
- echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
60
- }
 
 
 
 
 
 
 
 
 
 
61
 
62
- // Get the recent posts query.
63
- echo rpwe_get_recent_posts( $instance );
64
 
65
- // Close the theme's widget wrapper.
66
- echo $after_widget;
67
 
68
  }
69
 
@@ -104,6 +110,7 @@ class Recent_Posts_Widget_Extended extends WP_Widget {
104
  $instance['excerpt'] = isset( $new_instance['excerpt'] ) ? (bool) $new_instance['excerpt'] : false;
105
  $instance['length'] = (int)( $new_instance['length'] );
106
  $instance['date'] = isset( $new_instance['date'] ) ? (bool) $new_instance['date'] : false;
 
107
  $instance['readmore'] = isset( $new_instance['readmore'] ) ? (bool) $new_instance['readmore'] : false;
108
  $instance['readmore_text'] = strip_tags( $new_instance['readmore_text'] );
109
 
47
  function widget( $args, $instance ) {
48
  extract( $args );
49
 
50
+ $recent = rpwe_get_recent_posts( $instance );
 
51
 
52
+ if ( $recent ) {
 
 
53
 
54
+ // Output the theme's $before_widget wrapper.
55
+ echo $before_widget;
56
+
57
+ // If both title and title url is not empty, display it.
58
+ if ( ! empty( $instance['title_url'] ) && ! empty( $instance['title'] ) ) {
59
+ echo $before_title . '<a href="' . esc_url( $instance['title_url'] ) . '" title="' . esc_attr( $instance['title'] ) . '">' . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . '</a>' . $after_title;
60
+
61
+ // If the title not empty, display it.
62
+ } elseif ( ! empty( $instance['title'] ) ) {
63
+ echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
64
+ }
65
+
66
+ // Get the recent posts query.
67
+ echo $recent;
68
 
69
+ // Close the theme's widget wrapper.
70
+ echo $after_widget;
71
 
72
+ }
 
73
 
74
  }
75
 
110
  $instance['excerpt'] = isset( $new_instance['excerpt'] ) ? (bool) $new_instance['excerpt'] : false;
111
  $instance['length'] = (int)( $new_instance['length'] );
112
  $instance['date'] = isset( $new_instance['date'] ) ? (bool) $new_instance['date'] : false;
113
+ $instance['date_relative'] = isset( $new_instance['date_relative'] ) ? (bool) $new_instance['date_relative'] : false;
114
  $instance['readmore'] = isset( $new_instance['readmore'] ) ? (bool) $new_instance['readmore'] : false;
115
  $instance['readmore_text'] = strip_tags( $new_instance['readmore_text'] );
116
 
includes/form.php CHANGED
@@ -189,7 +189,7 @@
189
 
190
  <p>
191
  <label class="rpwe-block" for="<?php echo $this->get_field_id( 'thumb_height' ); ?>">
192
- <?php _e( 'Thumbnail (width,height,align)', 'rpwe' ); ?>
193
  </label>
194
  <input class= "small-input" id="<?php echo $this->get_field_id( 'thumb_height' ); ?>" name="<?php echo $this->get_field_name( 'thumb_height' ); ?>" type="number" step="1" min="0" value="<?php echo (int)( $instance['thumb_height'] ); ?>" />
195
  <input class="small-input" id="<?php echo $this->get_field_id( 'thumb_width' ); ?>" name="<?php echo $this->get_field_name( 'thumb_width' ); ?>" type="number" step="1" min="0" value="<?php echo (int)( $instance['thumb_width'] ); ?>"/>
@@ -244,6 +244,12 @@
244
  <?php _e( 'Display Date', 'rpwe' ); ?>
245
  </label>
246
  </p>
 
 
 
 
 
 
247
 
248
  </div>
249
 
@@ -253,6 +259,6 @@
253
  <label for="<?php echo $this->get_field_id( 'css' ); ?>">
254
  <?php _e( 'Custom CSS', 'rpwe' ); ?>
255
  </label>
256
- <textarea class="widefat" id="<?php echo $this->get_field_id( 'css' ); ?>" name="<?php echo $this->get_field_name( 'css' ); ?>" style="height:150px;"><?php echo $instance['css']; ?></textarea>
257
  <small><?php _e( 'If you turn off the default styles, you can use these css code to customize the recent posts style.', 'rpwe' ); ?></small>
258
  </p>
189
 
190
  <p>
191
  <label class="rpwe-block" for="<?php echo $this->get_field_id( 'thumb_height' ); ?>">
192
+ <?php _e( 'Thumbnail (height,width,align)', 'rpwe' ); ?>
193
  </label>
194
  <input class= "small-input" id="<?php echo $this->get_field_id( 'thumb_height' ); ?>" name="<?php echo $this->get_field_name( 'thumb_height' ); ?>" type="number" step="1" min="0" value="<?php echo (int)( $instance['thumb_height'] ); ?>" />
195
  <input class="small-input" id="<?php echo $this->get_field_id( 'thumb_width' ); ?>" name="<?php echo $this->get_field_name( 'thumb_width' ); ?>" type="number" step="1" min="0" value="<?php echo (int)( $instance['thumb_width'] ); ?>"/>
244
  <?php _e( 'Display Date', 'rpwe' ); ?>
245
  </label>
246
  </p>
247
+ <p>
248
+ <input id="<?php echo $this->get_field_id( 'date_relative' ); ?>" name="<?php echo $this->get_field_name( 'date_relative' ); ?>" type="checkbox" <?php checked( $instance['date_relative'] ); ?> />
249
+ <label for="<?php echo $this->get_field_id( 'date_relative' ); ?>">
250
+ <?php _e( 'Use Relative Date. eg: 5 days ago', 'rpwe' ); ?>
251
+ </label>
252
+ </p>
253
 
254
  </div>
255
 
259
  <label for="<?php echo $this->get_field_id( 'css' ); ?>">
260
  <?php _e( 'Custom CSS', 'rpwe' ); ?>
261
  </label>
262
+ <textarea class="widefat" id="<?php echo $this->get_field_id( 'css' ); ?>" name="<?php echo $this->get_field_name( 'css' ); ?>" style="height:180px;"><?php echo $instance['css']; ?></textarea>
263
  <small><?php _e( 'If you turn off the default styles, you can use these css code to customize the recent posts style.', 'rpwe' ); ?></small>
264
  </p>
includes/functions.php CHANGED
@@ -41,6 +41,7 @@ function rpwe_get_default_args() {
41
  'thumb_default' => 'http://placehold.it/45x45/f0f0f0/ccc',
42
  'thumb_align' => 'rpwe-alignleft',
43
  'date' => true,
 
44
  'readmore' => false,
45
  'readmore_text' => __( 'Read More &raquo;', 'rpwe' ),
46
 
@@ -107,12 +108,14 @@ function rpwe_get_recent_posts( $args = array() ) {
107
 
108
  while ( $posts->have_posts() ) : $posts->the_post();
109
 
110
- // Experiment!
111
- // Cropping image using Aqua Resizer
112
- $thumb_id = get_post_thumbnail_id();
113
- $img_url = wp_get_attachment_url( $thumb_id, 'full' ); // Get img URL.
114
- $image = aq_resize( $img_url, $args['thumb_width'], $args['thumb_height'], true ); // Resize & crop img.
115
 
 
 
 
 
116
  $html .= '<li class="rpwe-li rpwe-clearfix">';
117
 
118
  if ( $args['thumb'] ) :
@@ -120,28 +123,32 @@ function rpwe_get_recent_posts( $args = array() ) {
120
  // Check if post has post thumbnail.
121
  if ( has_post_thumbnail() ) :
122
  $html .= '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">';
123
- $html .= '<img class="' . $args['thumb_align'] . ' rpwe-thumb get-the-image" src="' . esc_url( $image ) . '" alt="' . esc_attr( get_the_title() ) . '">';
 
 
 
 
124
  $html .= '</a>';
125
 
126
  // If no post thumbnail found, check if Get The Image plugin exist and display the image.
127
  elseif ( function_exists( 'get_the_image' ) ) :
128
  $html .= get_the_image( array(
129
- 'height' => $args['thumb_height'],
130
- 'width' => $args['thumb_width'],
131
- 'image_class' => $args['thumb_align'] . ' rpwe-thumb get-the-image',
132
  'image_scan' => true,
133
- 'default_image' => $args['thumb_default']
134
  ) );
135
 
136
  // Display default image.
137
  elseif ( ! empty( $args['thumb_default'] ) ) :
138
  $html .= sprintf( '<a href="%1$s" rel="bookmark"><img class="%2$s rpwe-thumb rpwe-default-thumb" src="%3$s" alt="%4$s" width="%5$s" height="%6$s"></a>',
139
  esc_url( get_permalink() ),
140
- $args['thumb_align'],
141
- $args['thumb_default'],
142
  esc_attr( get_the_title() ),
143
- $args['thumb_width'],
144
- $args['thumb_height']
145
  );
146
 
147
  endif;
@@ -151,7 +158,11 @@ function rpwe_get_recent_posts( $args = array() ) {
151
  $html .= '<h3 class="rpwe-title"><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'rpwe' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">' . esc_attr( get_the_title() ) . '</a></h3>';
152
 
153
  if ( $args['date'] ) :
154
- $html .= '<time class="rpwe-time published" datetime="' . esc_html( get_the_date( 'c' ) ) . '">' . esc_html( get_the_date() ) . '</time>';
 
 
 
 
155
  endif;
156
 
157
  if ( $args['excerpt'] ) :
41
  'thumb_default' => 'http://placehold.it/45x45/f0f0f0/ccc',
42
  'thumb_align' => 'rpwe-alignleft',
43
  'date' => true,
44
+ 'date_relative' => false,
45
  'readmore' => false,
46
  'readmore_text' => __( 'Read More &raquo;', 'rpwe' ),
47
 
108
 
109
  while ( $posts->have_posts() ) : $posts->the_post();
110
 
111
+ // Thumbnails
112
+ $thumb_id = get_post_thumbnail_id(); // Get the featured image id.
113
+ $img_url = wp_get_attachment_url( $thumb_id ); // Get img URL.
 
 
114
 
115
+ // Display the image url and crop using the resizer.
116
+ $image = rpwe_resize( $img_url, $args['thumb_width'], $args['thumb_height'], true );
117
+
118
+ // Start recent posts markup.
119
  $html .= '<li class="rpwe-li rpwe-clearfix">';
120
 
121
  if ( $args['thumb'] ) :
123
  // Check if post has post thumbnail.
124
  if ( has_post_thumbnail() ) :
125
  $html .= '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">';
126
+ if ( $image ) :
127
+ $html .= '<img class="' . esc_attr( $args['thumb_align'] ) . ' rpwe-thumb" src="' . esc_url( $image ) . '" alt="' . esc_attr( get_the_title() ) . '">';
128
+ else :
129
+ $html .= '<img class="' . esc_attr( $args['thumb_align'] ) . ' rpwe-thumb" src="' . esc_url( $img_url ) . '" alt="' . esc_attr( get_the_title() ) . '" height="' . $args['thumb_height'] . '" width="' . $args['thumb_width'] . '">';
130
+ endif;
131
  $html .= '</a>';
132
 
133
  // If no post thumbnail found, check if Get The Image plugin exist and display the image.
134
  elseif ( function_exists( 'get_the_image' ) ) :
135
  $html .= get_the_image( array(
136
+ 'height' => (int) $args['thumb_height'],
137
+ 'width' => (int) $args['thumb_width'],
138
+ 'image_class' => esc_attr( $args['thumb_align'] ) . ' rpwe-thumb get-the-image',
139
  'image_scan' => true,
140
+ 'default_image' => esc_url( $args['thumb_default'] )
141
  ) );
142
 
143
  // Display default image.
144
  elseif ( ! empty( $args['thumb_default'] ) ) :
145
  $html .= sprintf( '<a href="%1$s" rel="bookmark"><img class="%2$s rpwe-thumb rpwe-default-thumb" src="%3$s" alt="%4$s" width="%5$s" height="%6$s"></a>',
146
  esc_url( get_permalink() ),
147
+ esc_attr( $args['thumb_align'] ),
148
+ esc_url( $args['thumb_default'] ),
149
  esc_attr( get_the_title() ),
150
+ (int) $args['thumb_width'],
151
+ (int) $args['thumb_height']
152
  );
153
 
154
  endif;
158
  $html .= '<h3 class="rpwe-title"><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'rpwe' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">' . esc_attr( get_the_title() ) . '</a></h3>';
159
 
160
  if ( $args['date'] ) :
161
+ $date = get_the_date();
162
+ if ( $args['date_relative'] ) :
163
+ $date = sprintf( __( '%s ago', 'rpwe' ), human_time_diff( get_the_date( 'U' ), current_time( 'timestamp' ) ) );
164
+ endif;
165
+ $html .= '<time class="rpwe-time published" datetime="' . esc_html( get_the_date( 'c' ) ) . '">' . esc_html( $date ) . '</time>';
166
  endif;
167
 
168
  if ( $args['excerpt'] ) :
includes/{aq_resizer.php → resizer.php} RENAMED
@@ -9,6 +9,8 @@
9
  * License : WTFPL - http://sam.zoy.org/wtfpl/
10
  * Documentation : https://github.com/sy4mil/Aqua-Resizer/
11
  *
 
 
12
  * @param string $url - (required) must be uploaded using wp media uploader
13
  * @param int $width - (required)
14
  * @param int $height - (optional)
@@ -22,8 +24,8 @@
22
  * @return str|array
23
  */
24
 
25
- if(!class_exists('Aq_Resize')) {
26
- class Aq_Resize
27
  {
28
  /**
29
  * The singleton instance
@@ -41,7 +43,7 @@ if(!class_exists('Aq_Resize')) {
41
  private function __clone() {}
42
 
43
  /**
44
- * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
45
  */
46
  static public function getInstance() {
47
  if(self::$instance == null) {
@@ -59,7 +61,7 @@ if(!class_exists('Aq_Resize')) {
59
  if ( ! $url || ( ! $width && ! $height ) ) return false;
60
 
61
  // Caipt'n, ready to hook.
62
- if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
63
 
64
  // Define upload path & dir.
65
  $upload_info = wp_upload_dir();
@@ -139,7 +141,7 @@ if(!class_exists('Aq_Resize')) {
139
  }
140
 
141
  // Okay, leave the ship.
142
- if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
143
 
144
  // Return the output.
145
  if ( $single ) {
@@ -160,7 +162,7 @@ if(!class_exists('Aq_Resize')) {
160
  /**
161
  * Callback to overwrite WP computing of thumbnail measures
162
  */
163
- function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
164
  if ( ! $crop ) return null; // Let the wordpress default function handle this.
165
 
166
  // Here is the point we allow to use larger image size than the original one.
@@ -193,15 +195,15 @@ if(!class_exists('Aq_Resize')) {
193
 
194
 
195
 
196
- if(!function_exists('aq_resize')) {
197
 
198
  /**
199
  * This is just a tiny wrapper function for the class above so that there is no
200
  * need to change any code in your own WP themes. Usage is still the same :)
201
  */
202
- function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
203
- $aq_resize = Aq_Resize::getInstance();
204
- return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
205
  }
206
  }
207
 
9
  * License : WTFPL - http://sam.zoy.org/wtfpl/
10
  * Documentation : https://github.com/sy4mil/Aqua-Resizer/
11
  *
12
+ * I changed the function and class name for compatibility purpose. It somtimes conflicted with a theme which uses the same library.
13
+ *
14
  * @param string $url - (required) must be uploaded using wp media uploader
15
  * @param int $width - (required)
16
  * @param int $height - (optional)
24
  * @return str|array
25
  */
26
 
27
+ if(!class_exists('Rpwe_Resize')) {
28
+ class Rpwe_Resize
29
  {
30
  /**
31
  * The singleton instance
43
  private function __clone() {}
44
 
45
  /**
46
+ * For your custom default usage you may want to initialize an Rpwe_Resize object by yourself and then have own defaults
47
  */
48
  static public function getInstance() {
49
  if(self::$instance == null) {
61
  if ( ! $url || ( ! $width && ! $height ) ) return false;
62
 
63
  // Caipt'n, ready to hook.
64
+ if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'rpwe_upscale'), 10, 6 );
65
 
66
  // Define upload path & dir.
67
  $upload_info = wp_upload_dir();
141
  }
142
 
143
  // Okay, leave the ship.
144
+ if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'rpwe_upscale' ) );
145
 
146
  // Return the output.
147
  if ( $single ) {
162
  /**
163
  * Callback to overwrite WP computing of thumbnail measures
164
  */
165
+ function rpwe_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
166
  if ( ! $crop ) return null; // Let the wordpress default function handle this.
167
 
168
  // Here is the point we allow to use larger image size than the original one.
195
 
196
 
197
 
198
+ if(!function_exists('rpwe_resize')) {
199
 
200
  /**
201
  * This is just a tiny wrapper function for the class above so that there is no
202
  * need to change any code in your own WP themes. Usage is still the same :)
203
  */
204
+ function rpwe_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
205
+ $rpwe_resize = Rpwe_Resize::getInstance();
206
+ return $rpwe_resize->process( $url, $width, $height, $crop, $single, $upscale );
207
  }
208
  }
209
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://satrya.me/donate/
4
  Tags: recent posts, random posts, popular posts, thumbnails, widget, widgets, sidebar, excerpt, category, post tag, taxonomy, post type, post status, shortcode, multiple widgets
5
  Requires at least: 3.7
6
  Tested up to: 4.0
7
- Stable tag: 0.9.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -42,6 +42,7 @@ This plugin will enable a custom, flexible and super advanced recent posts, you
42
 
43
  * [Get the Image](http://wordpress.org/plugins/get-the-image/).
44
  * [Page Builder by SiteOrigin](http://wordpress.org/plugins/siteorigin-panels/).
 
45
 
46
  = Support =
47
 
@@ -249,9 +250,9 @@ after=""
249
 
250
  == Changelog ==
251
 
252
- = 0.9.6 - 9/09/2014 =
253
- * **Add:** Now, you can display posts from multiple post types.
254
- * **Fix:** **Limit to Category** and **Limit to Tag** not working issue.
255
- * **Improve:** Change multi select with checkbox for **Limit to Category** and **Limit to Tag** option for better user experience.
256
- * **Experiment:** Better image cropping using [Aqua Resizer](https://github.com/syamilmj/Aqua-Resizer). It should fixed thumbnail not cropping correctly issue.
257
- * **Update:** Language
4
  Tags: recent posts, random posts, popular posts, thumbnails, widget, widgets, sidebar, excerpt, category, post tag, taxonomy, post type, post status, shortcode, multiple widgets
5
  Requires at least: 3.7
6
  Tested up to: 4.0
7
+ Stable tag: 0.9.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
42
 
43
  * [Get the Image](http://wordpress.org/plugins/get-the-image/).
44
  * [Page Builder by SiteOrigin](http://wordpress.org/plugins/siteorigin-panels/).
45
+ * [Featured Video Plus](http://wordpress.org/plugins/featured-video-plus/).
46
 
47
  = Support =
48
 
250
 
251
  == Changelog ==
252
 
253
+ = 0.9.7 - 9/13/2014 =
254
+ * **Add:** Relative date option `eg: 4 days ago`. Props [George Venios](https://github.com/veniosg)
255
+ * **Add:** [Featured Video Plus](http://wordpress.org/plugins/featured-video-plus/) plugin support.
256
+ * **Add:** Hide widget if no posts exist.
257
+ * **Add:** Fallback to the image attachment if no image url exist in the resizer script.
258
+ * **Fix:** Compatibility issue if the user theme use the same code library(Aqua Resizer) and causing blank screen.
rpwe.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Recent Posts Widget Extended
4
  * Plugin URI: http://satrya.me/wordpress-plugins/recent-posts-widget-extended/
5
  * Description: Enables advanced widget that gives you total control over the output of your site’s most recent Posts.
6
- * Version: 0.9.6
7
  * Author: Satrya
8
  * Author URI: http://satrya.me/
9
  * Author Email: satrya@satrya.me
@@ -96,7 +96,7 @@ class RPW_Extended {
96
  * @since 0.1
97
  */
98
  public function includes() {
99
- require_once( RPWE_INCLUDES . 'aq_resizer.php' );
100
  require_once( RPWE_INCLUDES . 'functions.php' );
101
  require_once( RPWE_INCLUDES . 'shortcode.php' );
102
  }
3
  * Plugin Name: Recent Posts Widget Extended
4
  * Plugin URI: http://satrya.me/wordpress-plugins/recent-posts-widget-extended/
5
  * Description: Enables advanced widget that gives you total control over the output of your site’s most recent Posts.
6
+ * Version: 0.9.7
7
  * Author: Satrya
8
  * Author URI: http://satrya.me/
9
  * Author Email: satrya@satrya.me
96
  * @since 0.1
97
  */
98
  public function includes() {
99
+ require_once( RPWE_INCLUDES . 'resizer.php' );
100
  require_once( RPWE_INCLUDES . 'functions.php' );
101
  require_once( RPWE_INCLUDES . 'shortcode.php' );
102
  }
screenshot-1.png CHANGED
Binary file