Yet Another Related Posts Plugin (YARPP) - Version 5.27.5

Version Description

(15-September-2021) = * New: Add support for "show_sticky_posts" and "generate_missing_thumbnails" to the yarpp_related() function * New: Add support for "recent" in YARPP shortcode + For example, to limit results to those published in the past 12 months: [yarpp recent="12 month"] * Enhancement: Use dropdown select for thumbnail sizes instead of radio buttons

Download this release

Release Info

Developer jeffparker
Plugin Icon 128x128 Yet Another Related Posts Plugin (YARPP)
Version 5.27.5
Comparing to
See all releases

Code changes from version 5.27.4 to 5.27.5

classes/YARPP_Cache.php CHANGED
@@ -199,6 +199,8 @@ abstract class YARPP_Cache {
199
  'exclude',
200
  'recent',
201
  'limit',
 
 
202
  );
203
  extract( $this->core->parse_args( $args, $options ) );
204
  // The maximum number of items we'll ever want to cache
@@ -294,8 +296,10 @@ abstract class YARPP_Cache {
294
  );
295
  $newsql .= ' and post_type IN (' . implode( ',', $sanitized_post_types ) . ')';
296
  $post_ids_to_exclude = array( (int) $reference_ID );
297
- $include_sticky_posts = $this->core->get_option( 'include_sticky_posts' );
298
- if ( 1 !== (int) $include_sticky_posts ) {
 
 
299
  $get_sticky_posts = get_option( 'sticky_posts' );
300
  $post_ids_to_exclude = wp_parse_args( $get_sticky_posts, $post_ids_to_exclude );
301
  }
199
  'exclude',
200
  'recent',
201
  'limit',
202
+ 'include_sticky_posts',
203
+ 'show_sticky_posts'
204
  );
205
  extract( $this->core->parse_args( $args, $options ) );
206
  // The maximum number of items we'll ever want to cache
296
  );
297
  $newsql .= ' and post_type IN (' . implode( ',', $sanitized_post_types ) . ')';
298
  $post_ids_to_exclude = array( (int) $reference_ID );
299
+ // Check if include_sticky_posts or show_sticky_posts is being passed in args.
300
+ $include_sticky_posts = isset($show_sticky_posts) ? $show_sticky_posts : $include_sticky_posts;
301
+ $include_sticky_posts = ( isset( $include_sticky_posts ) ) ? $include_sticky_posts : $this->core->get_option( 'include_sticky_posts' );
302
+ if ( ! $include_sticky_posts ) {
303
  $get_sticky_posts = get_option( 'sticky_posts' );
304
  $post_ids_to_exclude = wp_parse_args( $get_sticky_posts, $post_ids_to_exclude );
305
  }
classes/YARPP_Cache_Bypass.php CHANGED
@@ -106,6 +106,8 @@ class YARPP_Cache_Bypass extends YARPP_Cache {
106
  'exclude',
107
  'recent',
108
  'limit',
 
 
109
  );
110
  $this->args = $this->core->parse_args( $args, $options );
111
 
106
  'exclude',
107
  'recent',
108
  'limit',
109
+ 'include_sticky_posts',
110
+ 'show_sticky_posts'
111
  );
112
  $this->args = $this->core->parse_args( $args, $options );
113
 
classes/YARPP_Core.php CHANGED
@@ -10,11 +10,12 @@ class YARPP {
10
  * sans the yarpp_ prefix, split up into binary options and value options. These arrays are used in updating
11
  * settings (yarpp_options.php) and other tasks.
12
  */
13
- public $default_options = array();
14
- public $pro_default_options = array();
15
- public $default_hidden_metaboxes = array();
16
- public $debug = false;
17
- public $yarppPro = null;
 
18
  /**
19
  * @var YARPP_Cache_Bypass
20
  */
@@ -560,6 +561,9 @@ class YARPP {
560
  }
561
 
562
  public function diagnostic_generate_thumbnails() {
 
 
 
563
  return ( defined( 'YARPP_GENERATE_THUMBNAILS' ) && YARPP_GENERATE_THUMBNAILS ) || (bool) $this->get_option( 'generate_missing_thumbnails' );
564
  }
565
 
@@ -1504,7 +1508,9 @@ class YARPP {
1504
  if ( $cache_status !== YARPP_NO_RELATED ) {
1505
  $this->active_cache->end_yarpp_time();
1506
  }
1507
-
 
 
1508
  // Be careful to avoid infinite recursion, because those templates might show each related posts' body or
1509
  // excerpt, which would trigger finding its related posts, which would show its related posts body or excerpt...
1510
  $this->rendering_related_content = true;
10
  * sans the yarpp_ prefix, split up into binary options and value options. These arrays are used in updating
11
  * settings (yarpp_options.php) and other tasks.
12
  */
13
+ public $default_options = array();
14
+ public $pro_default_options = array();
15
+ public $default_hidden_metaboxes = array();
16
+ public $debug = false;
17
+ public $yarppPro = null;
18
+ public $generate_missing_thumbnails = null;
19
  /**
20
  * @var YARPP_Cache_Bypass
21
  */
561
  }
562
 
563
  public function diagnostic_generate_thumbnails() {
564
+ if ( is_bool( $this->generate_missing_thumbnails ) ) {
565
+ return $this->generate_missing_thumbnails;
566
+ }
567
  return ( defined( 'YARPP_GENERATE_THUMBNAILS' ) && YARPP_GENERATE_THUMBNAILS ) || (bool) $this->get_option( 'generate_missing_thumbnails' );
568
  }
569
 
1508
  if ( $cache_status !== YARPP_NO_RELATED ) {
1509
  $this->active_cache->end_yarpp_time();
1510
  }
1511
+ if ( isset( $args['generate_missing_thumbnails'] ) ) {
1512
+ $this->generate_missing_thumbnails = $args['generate_missing_thumbnails'];
1513
+ }
1514
  // Be careful to avoid infinite recursion, because those templates might show each related posts' body or
1515
  // excerpt, which would trigger finding its related posts, which would show its related posts body or excerpt...
1516
  $this->rendering_related_content = true;
classes/YARPP_Meta_Box.php CHANGED
@@ -71,7 +71,17 @@ class YARPP_Meta_Box {
71
 
72
  include YARPP_DIR . '/includes/phtmls/yarpp_meta_box_tax_weight.phtml';
73
  }
74
-
 
 
 
 
 
 
 
 
 
 
75
  /* MARK: Last cleaning spot */
76
  public function weight( $option, $desc ) {
77
  $weight = (int) yarpp_get_option( "weight[$option]" );
71
 
72
  include YARPP_DIR . '/includes/phtmls/yarpp_meta_box_tax_weight.phtml';
73
  }
74
+ /**
75
+ * Render the select options.
76
+ *
77
+ * @param string $name Select option name.
78
+ * @param array $options Array of option value.
79
+ * @param string $desc label description.
80
+ * @param array $args Array of additional argument.
81
+ */
82
+ public function yarpp_select_option( $name, $options, $desc = '', $args = '' ) {
83
+ include YARPP_DIR . '/includes/phtmls/yarpp_meta_box_select.phtml';
84
+ }
85
  /* MARK: Last cleaning spot */
86
  public function weight( $option, $desc ) {
87
  $weight = (int) yarpp_get_option( "weight[$option]" );
classes/YARPP_Meta_Box_Display_Web.php CHANGED
@@ -67,14 +67,7 @@ class YARPP_Meta_Box_Display_Web extends YARPP_Meta_Box {
67
  echo '>';
68
  echo '<div class="yarpp_form_row"><div>' . $this->template_text . '</div></div>';
69
  $this->template_file( false );
70
- echo '<div class="yarpp_form_row yarpp_form_radio_label">';
71
- echo '<div class="yarpp_form_label">' . esc_html( 'Thumbnail Size', 'yet-another-related-posts-plugin' ) . '</div><div>';
72
- foreach ( $get_image_sizes as $key => $_size ) {
73
- /* translators: %s: thumbnail key's name */
74
- $name = sprintf( __( '%1$s (%2$sx%3$s)', 'yet-another-related-posts-plugin' ), $key, $_size['width'], $_size['height'] );
75
- $this->radio( 'custom_theme_thumbnail_size_display', $name, '', $key );
76
- }
77
- echo '</div></div>';
78
  echo '</div>';
79
 
80
  echo "<div class='yarpp_subbox template_options_thumbnails'";
@@ -84,14 +77,7 @@ class YARPP_Meta_Box_Display_Web extends YARPP_Meta_Box {
84
  echo '>';
85
  $this->textbox( 'thumbnails_heading', __( 'Heading:', 'yet-another-related-posts-plugin' ), 40 );
86
  $this->textbox( 'thumbnails_default', __( 'Default image (URL):', 'yet-another-related-posts-plugin' ), 40 );
87
- echo '<div class="yarpp_form_row yarpp_form_radio_label">';
88
- echo '<div class="yarpp_form_label">' . esc_html__( 'Thumbnail Size', 'yet-another-related-posts-plugin' ) . '</div><div>';
89
- foreach ( $get_image_sizes as $key => $_size ) {
90
- /* translators: %s: thumbnail key's name */
91
- $name = sprintf( __( '%1$s (%2$sx%3$s)', 'yet-another-related-posts-plugin' ), $key, $_size['width'], $_size['height'] );
92
- $this->radio( 'thumbnail_size_display', $name, '', $key );
93
- }
94
- echo '</div></div>';
95
  echo '</div>';
96
  echo '<div class="generate_missing_thumbnails">';
97
  $this->checkbox( 'generate_missing_thumbnails', __( 'Generate missing thumbnail sizes: ', 'yet-another-related-posts-plugin' ) . "<span class='yarpp_help dashicons dashicons-editor-help' data-help='" . '<p>' . esc_attr( __( 'When enabled, missing thumbnail sizes will be automatically generated on the fly. Doing this type of processing on the fly may not scale well for larger sites.', 'yet-another-related-posts-plugin' ) ) . '</p><p>' . sprintf( __( 'For larger sites, we recommend the %1$s or %2$s to generate missing thumbnail sizes in a batch process.', 'yet-another-related-posts-plugin' ), '<a href="https://wordpress.org/plugins/regenerate-thumbnails/" target="_blank">Regenerate Thumbnails plugin</a>', '<a href="https://developer.wordpress.org/cli/commands/media/regenerate/" target="_blank">WP-CLI</a>' ) . '</p><p>' . esc_attr( __( 'New images should continue to automatically get all active thumbnail sizes generated when they are uploaded.', 'yet-another-related-posts-plugin' ) ) . '</p>' . "'>&nbsp;</span>&nbsp;&nbsp;", 'yarpp', $yarpp_args );
67
  echo '>';
68
  echo '<div class="yarpp_form_row"><div>' . $this->template_text . '</div></div>';
69
  $this->template_file( false );
70
+ $this->yarpp_select_option( 'custom_theme_thumbnail_size_display', $get_image_sizes, 'Thumbnail Size' );
 
 
 
 
 
 
 
71
  echo '</div>';
72
 
73
  echo "<div class='yarpp_subbox template_options_thumbnails'";
77
  echo '>';
78
  $this->textbox( 'thumbnails_heading', __( 'Heading:', 'yet-another-related-posts-plugin' ), 40 );
79
  $this->textbox( 'thumbnails_default', __( 'Default image (URL):', 'yet-another-related-posts-plugin' ), 40 );
80
+ $this->yarpp_select_option( 'thumbnail_size_display', $get_image_sizes, 'Thumbnail Size' );
 
 
 
 
 
 
 
81
  echo '</div>';
82
  echo '<div class="generate_missing_thumbnails">';
83
  $this->checkbox( 'generate_missing_thumbnails', __( 'Generate missing thumbnail sizes: ', 'yet-another-related-posts-plugin' ) . "<span class='yarpp_help dashicons dashicons-editor-help' data-help='" . '<p>' . esc_attr( __( 'When enabled, missing thumbnail sizes will be automatically generated on the fly. Doing this type of processing on the fly may not scale well for larger sites.', 'yet-another-related-posts-plugin' ) ) . '</p><p>' . sprintf( __( 'For larger sites, we recommend the %1$s or %2$s to generate missing thumbnail sizes in a batch process.', 'yet-another-related-posts-plugin' ), '<a href="https://wordpress.org/plugins/regenerate-thumbnails/" target="_blank">Regenerate Thumbnails plugin</a>', '<a href="https://developer.wordpress.org/cli/commands/media/regenerate/" target="_blank">WP-CLI</a>' ) . '</p><p>' . esc_attr( __( 'New images should continue to automatically get all active thumbnail sizes generated when they are uploaded.', 'yet-another-related-posts-plugin' ) ) . '</p>' . "'>&nbsp;</span>&nbsp;&nbsp;", 'yarpp', $yarpp_args );
classes/YARPP_Shortcode.php CHANGED
@@ -28,6 +28,7 @@ class YARPP_Shortcode {
28
  'reference_id' => null,
29
  'template' => null,
30
  'limit' => null,
 
31
  ),
32
  $atts
33
  );
@@ -46,7 +47,10 @@ class YARPP_Shortcode {
46
  $yarpp_args['template'] .= '.php';
47
  }
48
  }
49
-
 
 
 
50
  if ( isset( $atts['limit'] ) && $atts['limit'] ) {
51
  // Normalize parameter.
52
  $atts['limit'] = trim( $atts['limit'] );
28
  'reference_id' => null,
29
  'template' => null,
30
  'limit' => null,
31
+ 'recent' => null,
32
  ),
33
  $atts
34
  );
47
  $yarpp_args['template'] .= '.php';
48
  }
49
  }
50
+ // Can ignore validation of the "recent" attribute here as it is validated in the SQL function of the YARPP_Cache class.
51
+ if ( isset( $atts['recent'] ) && $atts['recent'] ) {
52
+ $yarpp_args['recent'] = trim( $atts['recent'] );
53
+ }
54
  if ( isset( $atts['limit'] ) && $atts['limit'] ) {
55
  // Normalize parameter.
56
  $atts['limit'] = trim( $atts['limit'] );
includes/phtmls/yarpp_meta_box_select.phtml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="yarpp_form_row yarpp_form_select_label">
2
+ <div class="yarpp_form_label"><?php esc_html_e( $desc, 'yet-another-related-posts-plugin' ); ?></div>
3
+ <div>
4
+ <select name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $name ); ?>">
5
+ <?php foreach ( $options as $key => $val ) { ?>
6
+ <?php
7
+ /* translators: 1: thumbnail size name, 2: width (in pixels), 3: height (in pixels) */
8
+ $option_name = sprintf( __( '%1$s (%2$sx%3$s)', 'yet-another-related-posts-plugin' ), $key, $val['width'], $val['height'] );
9
+ ?>
10
+ <option
11
+ value="<?php echo esc_attr( $key ); ?>"
12
+ <?php selected( yarpp_get_option_thumbnail( $name, 'thumbnail' ), $key ); ?>>
13
+ <?php echo esc_html( $option_name ); ?>
14
+ </option>
15
+ <?php } ?>
16
+ </select>
17
+ </div>
18
+ </div>
readme.txt CHANGED
@@ -6,7 +6,7 @@ Requires at least: 3.7
6
  Requires PHP: 5.3
7
  License: GPLv2 or later
8
  Tested up to: 5.8
9
- Stable tag: 5.27.4
10
 
11
  The best WordPress plugin for displaying related posts. Simple and flexible, with a powerful proven algorithm and inbuilt caching.
12
 
@@ -138,6 +138,10 @@ To specify maximum number of posts to show, use the "limit" attribute like so:
138
 
139
  `[yarpp template="list" limit=3]`
140
 
 
 
 
 
141
  To add YARPP shortcode to your theme files (eg. single.php), use:
142
 
143
  `<?php echo do_shortcode('[yarpp]'); ?>`
@@ -182,8 +186,9 @@ yarpp_related(
182
  array(
183
  // Pool options: these determine the "pool" of entities which are considered
184
  'post_type' => array('post', 'page', 'wc_product', ...), // post types to include in results
185
- 'show_pass_post' => false, // show password-protected posts
186
- 'past_only' => false, // show only posts which were published before the reference post
 
187
  'exclude' => array(), // a list of term_taxonomy_ids. entities with any of these terms will be excluded from consideration.
188
  'recent' => false, // to limit to entries published recently, set to like '15 day', '20 week', or '12 month' (https://www.mysqltutorial.org/mysql-interval/)
189
 
@@ -209,6 +214,7 @@ yarpp_related(
209
  'limit' => 5, // maximum number of results
210
  'order' => 'score DESC', // column on "wp_posts" to order by, then a space, and whether to order in ascending ("ASC") or descending ("DESC") order
211
  'promote_yarpp' => true, // boolean indicating whether to add 'Powered by YARPP' below related posts
 
212
  ),
213
  $reference_ID, // second argument: (optional) the post ID. If not included, will use the current post.
214
  true // third argument: (optional) true to echo the HTML block; false to return it
@@ -529,6 +535,12 @@ Beginning with version 4.0.7, YARPP includes clean uninstall functionality. If y
529
 
530
 
531
  == Changelog ==
 
 
 
 
 
 
532
  = 5.27.4 (25-August-2021) =
533
  * [Bugfix](https://wordpress.org/support/topic/php-8-deprecated-required-parameter-follows-optional/): PHP 8 compatibility by making `$args` optional on `YARPP::get_template_content()`
534
 
@@ -1416,5 +1428,5 @@ After a break of many years, the plugin is 100% supported now that the baton has
1416
  * Initial upload
1417
 
1418
  == Upgrade Notice ==
1419
- = 5.27.4 =
1420
  We update this plugin regularly so we can make it better for you. Update to the latest version for all of the available features and improvements. Thank you for using YARPP!
6
  Requires PHP: 5.3
7
  License: GPLv2 or later
8
  Tested up to: 5.8
9
+ Stable tag: 5.27.5
10
 
11
  The best WordPress plugin for displaying related posts. Simple and flexible, with a powerful proven algorithm and inbuilt caching.
12
 
138
 
139
  `[yarpp template="list" limit=3]`
140
 
141
+ To only show recent posts, use the "recent" attribute (provide it with a number, a space, and then either "day", "week" or "month")
142
+
143
+ `[yarpp recent="6 month"]`
144
+
145
  To add YARPP shortcode to your theme files (eg. single.php), use:
146
 
147
  `<?php echo do_shortcode('[yarpp]'); ?>`
186
  array(
187
  // Pool options: these determine the "pool" of entities which are considered
188
  'post_type' => array('post', 'page', 'wc_product', ...), // post types to include in results
189
+ 'show_pass_post' => true, // show password-protected posts
190
+ 'show_sticky_posts' => true, // show sticky posts
191
+ 'past_only' => true, // show only posts which were published before the reference post
192
  'exclude' => array(), // a list of term_taxonomy_ids. entities with any of these terms will be excluded from consideration.
193
  'recent' => false, // to limit to entries published recently, set to like '15 day', '20 week', or '12 month' (https://www.mysqltutorial.org/mysql-interval/)
194
 
214
  'limit' => 5, // maximum number of results
215
  'order' => 'score DESC', // column on "wp_posts" to order by, then a space, and whether to order in ascending ("ASC") or descending ("DESC") order
216
  'promote_yarpp' => true, // boolean indicating whether to add 'Powered by YARPP' below related posts
217
+ 'generate_missing_thumbnails' => true, // automatically generate missing thumbnail sizes on the fly
218
  ),
219
  $reference_ID, // second argument: (optional) the post ID. If not included, will use the current post.
220
  true // third argument: (optional) true to echo the HTML block; false to return it
535
 
536
 
537
  == Changelog ==
538
+ = 5.27.5 (15-September-2021) =
539
+ * New: Add support for "show_sticky_posts" and "generate_missing_thumbnails" to the [yarpp_related() function](https://wordpress.org/plugins/yet-another-related-posts-plugin/#installation)
540
+ * New: Add support for "recent" in [YARPP shortcode](https://wordpress.org/plugins/yet-another-related-posts-plugin/#installation)
541
+ + For example, to limit results to those published in the past 12 months: `[yarpp recent="12 month"]`
542
+ * Enhancement: Use dropdown select for thumbnail sizes instead of radio buttons
543
+
544
  = 5.27.4 (25-August-2021) =
545
  * [Bugfix](https://wordpress.org/support/topic/php-8-deprecated-required-parameter-follows-optional/): PHP 8 compatibility by making `$args` optional on `YARPP::get_template_content()`
546
 
1428
  * Initial upload
1429
 
1430
  == Upgrade Notice ==
1431
+ = 5.27.5 =
1432
  We update this plugin regularly so we can make it better for you. Update to the latest version for all of the available features and improvements. Thank you for using YARPP!
yarpp.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Yet Another Related Posts Plugin (YARPP)
4
  Description: Adds related posts to your site and in RSS feeds, based on a powerful, customizable algorithm.
5
- Version: 5.27.4
6
  Author: YARPP
7
  Author URI: https://yarpp.com/
8
  Plugin URI: https://yarpp.com/
@@ -25,7 +25,7 @@ if ( ! defined( 'WP_CONTENT_DIR' ) ) {
25
  define( 'WP_CONTENT_DIR', substr( $tr, 0, strrpos( $tr, '/' ) ) );
26
  }
27
 
28
- define( 'YARPP_VERSION', '5.27.4' );
29
 
30
  define( 'YARPP_DIR', dirname( __FILE__ ) );
31
  /**
2
  /*
3
  Plugin Name: Yet Another Related Posts Plugin (YARPP)
4
  Description: Adds related posts to your site and in RSS feeds, based on a powerful, customizable algorithm.
5
+ Version: 5.27.5
6
  Author: YARPP
7
  Author URI: https://yarpp.com/
8
  Plugin URI: https://yarpp.com/
25
  define( 'WP_CONTENT_DIR', substr( $tr, 0, strrpos( $tr, '/' ) ) );
26
  }
27
 
28
+ define( 'YARPP_VERSION', '5.27.5' );
29
 
30
  define( 'YARPP_DIR', dirname( __FILE__ ) );
31
  /**