Yet Another Related Posts Plugin (YARPP) - Version 5.9.0

Version Description

(21-September-2020) = * Enhancement: Clarify that "Also display in archives" includes front page and category pages * Enhancement: reference_id parameter support for the YARPP shortcode. For example: [yarpp reference_id=123] to show content related to Post ID 123 (can be used either inside or outside the loop from theme code) * Enhancement: Place warning about comparing using titles and bodies next to the affected inputs, rather than at the top of the page where it could be lost with notices from other plugins * Bugfix: Don't require a category or term, even if set by the admin, on post types that don't use categories or terms (also applies to custom taxonomies)

Download this release

Release Info

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

Code changes from version 5.8.0 to 5.9.0

classes/YARPP_Cache.php CHANGED
@@ -277,12 +277,18 @@ abstract class YARPP_Cache {
277
  // $exclude_tt_ids already ran through wp_parse_id_list
278
  $newsql .= " and bit_or(terms.term_taxonomy_id in (".join(',', $exclude_tt_ids).")) = 0";
279
  }
280
-
 
281
  foreach ((array) $require_tax as $tax => $number) {
282
- $newsql .= $wpdb->prepare(
283
- ' and '.$this->tax_criteria($reference_ID, $tax).' >= %d',
284
- $number
285
- );
 
 
 
 
 
286
  }
287
 
288
  $newsql .= $wpdb->prepare(
277
  // $exclude_tt_ids already ran through wp_parse_id_list
278
  $newsql .= " and bit_or(terms.term_taxonomy_id in (".join(',', $exclude_tt_ids).")) = 0";
279
  }
280
+
281
+ $post_type_taxonomies = get_object_taxonomies($post->post_type, 'names');
282
  foreach ((array) $require_tax as $tax => $number) {
283
+ // Double-check this post type actually uses this taxonomy. If not,
284
+ // we'll never find any related posts, as the reference post doesn't use have any terms in this taxonomy.
285
+ // See https://wordpress.org/support/topic/require-at-least-one-taxonomy-limited-to-taxonomies-available-the-post-type/
286
+ if(in_array($tax, $post_type_taxonomies)){
287
+ $newsql .= $wpdb->prepare(
288
+ ' and '.$this->tax_criteria($reference_ID, $tax).' >= %d',
289
+ $number
290
+ );
291
+ }
292
  }
293
 
294
  $newsql .= $wpdb->prepare(
classes/YARPP_Meta_Box_Display_Web.php CHANGED
@@ -22,7 +22,7 @@ class YARPP_Meta_Box_Display_Web extends YARPP_Meta_Box {
22
  }
23
  echo "</div></div>";
24
 
25
- $this->checkbox( 'auto_display_archive', __( "Also display in archives", 'yarpp' ) );
26
 
27
  $this->textbox( 'limit', __( 'Maximum number of posts:', 'yarpp' ) );
28
 
22
  }
23
  echo "</div></div>";
24
 
25
+ $this->checkbox( 'auto_display_archive', __( "Display on the front page, category and archive pages", 'yarpp' ) );
26
 
27
  $this->textbox( 'limit', __( 'Maximum number of posts:', 'yarpp' ) );
28
 
classes/YARPP_Meta_Box_Relatedness.php CHANGED
@@ -8,6 +8,7 @@ class YARPP_Meta_Box_Relatedness extends YARPP_Meta_Box {
8
 
9
  <?php
10
  $this->textbox( 'threshold', __( 'Match threshold:', 'yarpp' ) );
 
11
  $this->weight( 'title', __( "Titles: ", 'yarpp' ) );
12
  $this->weight( 'body', __( "Bodies: ", 'yarpp' ) );
13
 
@@ -15,4 +16,81 @@ class YARPP_Meta_Box_Relatedness extends YARPP_Meta_Box {
15
  $this->tax_weight( $taxonomy );
16
  }
17
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
8
 
9
  <?php
10
  $this->textbox( 'threshold', __( 'Match threshold:', 'yarpp' ) );
11
+ $this->disabled_warning();
12
  $this->weight( 'title', __( "Titles: ", 'yarpp' ) );
13
  $this->weight( 'body', __( "Bodies: ", 'yarpp' ) );
14
 
16
  $this->tax_weight( $taxonomy );
17
  }
18
  }
19
+
20
+ /**
21
+ * If applicable, echos out a warning that the fulltext indexes don't exist and so comparing using titles and bodies
22
+ * must be disabled until some database changes happen.
23
+ */
24
+ protected function disabled_warning(){
25
+ global $yarpp, $wpdb;
26
+ $database_supports_fulltext_indexes = $yarpp->db_schema->database_supports_fulltext_indexes();
27
+ if ( ! $database_supports_fulltext_indexes) $yarpp->disable_fulltext();
28
+ if ( !(bool) yarpp_get_option(YARPP_DB_Options::YARPP_MYISAM_OVERRIDE) && $yarpp->db_options->is_fulltext_disabled()) {
29
+ ?>
30
+ <div class='yarpp-callout yarpp-notice'>
31
+ <p><?php
32
+ esc_html_e('Comparing posts based on titles or bodies is currently disabled','yarpp');
33
+ ?>
34
+ &nbsp;&nbsp;<a href="#" id="yarpp_fulltext_expand"><?php
35
+ printf(
36
+ // translators: icon to expand
37
+ __('Show Details %s','yarpp'),
38
+ '[+]'
39
+ );
40
+ ?>
41
+ </a>
42
+ </p>
43
+ <div id="yarpp_fulltext_details" class="hidden">
44
+ <?php if ( $database_supports_fulltext_indexes ){ ?>
45
+ <p><?php esc_html_e('YARPP can automatically create "full-text indexes" to enable comparing posts based on titles and bodies. To do so, click the button below.');?></p>
46
+ <?php } else { ?>
47
+ <p><?php
48
+ printf(
49
+ esc_html__('Because full-text indexing is not supported by your current table engine, "%1$s", YARPP cannot compare posts based on their titles or bodies.','yarpp'),
50
+ 'InnoDB',
51
+ '5.6.4',
52
+ '<code>' . $wpdb->posts . '</code>',
53
+ 'MyISAM'
54
+ );
55
+ ?>
56
+ </p>
57
+ <p><?php
58
+ printf(
59
+ esc_html__('Please contact your host about updating MySQL to at latest version %1$s, or run the following SQL code on your MySQL client (eg PHPMyAdmin) or terminal:', 'yarpp'),
60
+ '5.6.4'
61
+ );
62
+ ?>
63
+ </p>
64
+ <code class="yarpp_separated">ALTER TABLE `<?php echo $wpdb->posts;?>` ENGINE = MyISAM;</code>
65
+ <p><?php
66
+ esc_html_e('After you have done that, click the button below to enable comparing titles and bodies using full-text indexes."','yarpp');
67
+ ?>
68
+ </p>
69
+ <?php } ?>
70
+ <form method="post" class="yarpp_separated">
71
+ <input type='submit' class='button yarpp_spin_on_click' name='myisam_override' value='Create FULLTEXT indexes'/>
72
+ <span class="spinner"></span>
73
+ </form>
74
+ <p><?php
75
+ esc_html_e(
76
+ 'Note: although no data should be lost, it is always recommended to perform a full database backup before doing this.','yarpp'
77
+ );
78
+ ?>
79
+ </p>
80
+ <?php if( ! $database_supports_fulltext_indexes){ ?>
81
+ <p>
82
+ <?php
83
+ printf(
84
+ esc_html__('See MySQL %1$sstorage engines%2$s documentation for details on MySQL engines.','yarpp'),
85
+ '<a href="https://dev.mysql.com/doc/refman/8.0/en/storage-engines.html" target="_blank">',
86
+ '</a>'
87
+ );
88
+ ?>
89
+ </p>
90
+ <?php } ?>
91
+ </div>
92
+ </div>
93
+ <?php
94
+ }
95
+ }
96
  }
classes/YARPP_Shortcode.php CHANGED
@@ -23,13 +23,19 @@ class YARPP_Shortcode {
23
  * @return string
24
  */
25
  public function render($atts) {
 
 
 
 
 
 
26
  /** @global $yarpp YARPP */
27
  global $yarpp;
28
- $post = get_post();
29
  if($post instanceof WP_Post){
30
  return $yarpp->display_related($post->ID,array('domain' => 'shortcode'), false);
31
  } else {
32
- return '<!-- YARPP shortcode called but no reference post found. It was probably called outside "the loop".-->';
33
  }
34
 
35
  }
23
  * @return string
24
  */
25
  public function render($atts) {
26
+ $atts = shortcode_atts(
27
+ array(
28
+ 'reference_id' => null
29
+ ),
30
+ $atts
31
+ );
32
  /** @global $yarpp YARPP */
33
  global $yarpp;
34
+ $post = get_post((int)$atts['reference_id']);
35
  if($post instanceof WP_Post){
36
  return $yarpp->display_related($post->ID,array('domain' => 'shortcode'), false);
37
  } else {
38
+ return '<!-- YARPP shortcode called but no reference post found. It was probably called outside "the loop" or the reference_id provided was invalid.-->';
39
  }
40
 
41
  }
includes/yarpp_myisam_notice.php CHANGED
@@ -36,73 +36,3 @@ if (isset($_POST['myisam_override'])) {
36
  <?php
37
  }
38
  }
39
-
40
- $database_supports_fulltext_indexes = $yarpp->db_schema->database_supports_fulltext_indexes();
41
- if ( ! $database_supports_fulltext_indexes) $yarpp->disable_fulltext();
42
- if ( !(bool) yarpp_get_option(YARPP_DB_Options::YARPP_MYISAM_OVERRIDE) && $yarpp->db_options->is_fulltext_disabled()) {
43
- ?>
44
- <div class='notice notice-warning'>
45
- <p><?php
46
- esc_html_e('Comparing posts based on titles or bodies is currently disabled','yarpp');
47
- ?>
48
- &nbsp;&nbsp;<a href="#" id="yarpp_fulltext_expand"><?php
49
- printf(
50
- // translators: icon to expand
51
- __('Show Details %s','yarpp'),
52
- '[+]'
53
- );
54
- ?>
55
- </a>
56
- </p>
57
- <div id="yarpp_fulltext_details" class="hidden">
58
- <?php if ( $database_supports_fulltext_indexes ){ ?>
59
- <p><?php esc_html_e('YARPP can automatically create "full-text indexes" to enable comparing posts based on titles and bodies. To do so, click the button below.');?></p>
60
- <?php } else { ?>
61
- <p><?php
62
- printf(
63
- esc_html__('Because full-text indexing is not supported by your current table engine, "%1$s", YARPP cannot compare posts based on their titles or bodies.','yarpp'),
64
- 'InnoDB',
65
- '5.6.4',
66
- '<code>' . $wpdb->posts . '</code>',
67
- 'MyISAM'
68
- );
69
- ?>
70
- </p>
71
- <p><?php
72
- printf(
73
- esc_html__('Please contact your host about updating MySQL to at latest version %1$s, or run the following SQL code on your MySQL client (eg PHPMyAdmin) or terminal:', 'yarpp'),
74
- '5.6.4'
75
- );
76
- ?>
77
- </p>
78
- <code class="yarpp_separated">ALTER TABLE `<?php echo $wpdb->posts;?>` ENGINE = MyISAM;</code>
79
- <p><?php
80
- esc_html_e('After you have done that, click the button below to enable comparing titles and bodies using full-text indexes."','yarpp');
81
- ?>
82
- </p>
83
- <?php } ?>
84
- <form method="post" class="yarpp_separated">
85
- <input type='submit' class='button yarpp_spin_on_click' name='myisam_override' value='Create FULLTEXT indexes'/>
86
- <span class="spinner"></span>
87
- </form>
88
- <p><?php
89
- esc_html_e(
90
- 'Note: although no data should be lost by altering the table’s engine, it is always recommended to perform a full database backup before doing this.','yarpp'
91
- );
92
- ?>
93
- </p>
94
- <?php if( ! $database_supports_fulltext_indexes){ ?>
95
- <p>
96
- <?php
97
- printf(
98
- esc_html__('See MySQL %1$sstorage engines%2$s documentation for details on MySQL engines.','yarpp'),
99
- '<a href="https://dev.mysql.com/doc/refman/8.0/en/storage-engines.html" target="_blank">',
100
- '</a>'
101
- );
102
- ?>
103
- </p>
104
- <?php } ?>
105
- </div>
106
- </div>
107
- <?php
108
- }
36
  <?php
37
  }
38
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/yarpp_options.php CHANGED
@@ -72,7 +72,7 @@ if (current_user_can('update_plugins')) {
72
  /* MyISAM Check */
73
  include 'yarpp_myisam_notice.php';
74
 
75
- /* This is not a yarpp pluging update, it is an yarpp option update */
76
  if (isset($_POST['update_yarpp']) && check_admin_referer('update_yarpp', 'update_yarpp-nonce')) {
77
  $new_options = array();
78
  foreach ($yarpp->default_options as $option => $default) {
72
  /* MyISAM Check */
73
  include 'yarpp_myisam_notice.php';
74
 
75
+ /* This is not a yarpp plugin update, it is an yarpp option update */
76
  if (isset($_POST['update_yarpp']) && check_admin_referer('update_yarpp', 'update_yarpp-nonce')) {
77
  $new_options = array();
78
  foreach ($yarpp->default_options as $option => $default) {
readme.txt CHANGED
@@ -5,7 +5,7 @@ Requires at least: 3.7
5
  Requires PHP: 5.3
6
  License: GPLv2 or later
7
  Tested up to: 5.5
8
- Stable tag: 5.8.0
9
 
10
  The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
11
 
@@ -69,7 +69,8 @@ YARPP adds a REST API endpoint for fetching related posts. The JSON results from
69
 
70
  You can place YARPP manually wherever you’d like in your theme within [The Loop](http://codex.wordpress.org/The_Loop) where you want to display the related posts. Simply insert the following shortcode:
71
 
72
- `[yarpp]`
 
73
 
74
  == Frequently Asked Questions ==
75
 
@@ -282,6 +283,12 @@ add_action(
282
  `
283
 
284
  == Changelog ==
 
 
 
 
 
 
285
  = 5.8.0 (08-September-2020) =
286
  * Enhancement: Code hygiene upgrade with usage of `WPDB->prepare` everywhere possible and related improvements
287
  * [Bugfix](https://wordpress.org/support/topic/i-need-to-ad-yarpp-to-my-sidebar-but-it-wont-let-me-upgrade-to-pro/): Since there is no YARPP Pro currently, removed mention of it from the widget form
@@ -1012,6 +1019,6 @@ After a break of many years, the plugin is 100% supported now that the baton has
1012
  * Initial upload
1013
 
1014
  == Upgrade Notice ==
1015
- = 5.8.0 =
1016
  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!
1017
 
5
  Requires PHP: 5.3
6
  License: GPLv2 or later
7
  Tested up to: 5.5
8
+ Stable tag: 5.9.0
9
 
10
  The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
11
 
69
 
70
  You can place YARPP manually wherever you’d like in your theme within [The Loop](http://codex.wordpress.org/The_Loop) where you want to display the related posts. Simply insert the following shortcode:
71
 
72
+ `[yarpp]` to show content related to the current post
73
+ `[yarpp reference_id=123]` to show content related to post 123 (can be used either inside or outside the loop from theme code)
74
 
75
  == Frequently Asked Questions ==
76
 
283
  `
284
 
285
  == Changelog ==
286
+ = 5.9.0 (21-September-2020) =
287
+ * Enhancement: Clarify that "Also display in archives" includes front page and category pages
288
+ * Enhancement: `reference_id` parameter support for the YARPP shortcode. For example: `[yarpp reference_id=123]` to show content related to Post ID 123 (can be used either inside or outside the loop from theme code)
289
+ * Enhancement: Place warning about comparing using titles and bodies next to the affected inputs, rather than at the top of the page where it could be lost with notices from other plugins
290
+ * [Bugfix](https://wordpress.org/support/topic/require-at-least-one-taxonomy-limited-to-taxonomies-available-the-post-type/): Don't require a category or term, even if set by the admin, on post types that don't use categories or terms (also applies to custom taxonomies)
291
+
292
  = 5.8.0 (08-September-2020) =
293
  * Enhancement: Code hygiene upgrade with usage of `WPDB->prepare` everywhere possible and related improvements
294
  * [Bugfix](https://wordpress.org/support/topic/i-need-to-ad-yarpp-to-my-sidebar-but-it-wont-let-me-upgrade-to-pro/): Since there is no YARPP Pro currently, removed mention of it from the widget form
1019
  * Initial upload
1020
 
1021
  == Upgrade Notice ==
1022
+ = 5.9.0 =
1023
  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!
1024
 
style/options_basic.css CHANGED
@@ -388,4 +388,14 @@ body.rtl #yarpp-optin-learnmore {
388
  .yarpp_separated{
389
  display:inline-block;
390
  margin:1.5em 1em
 
 
 
 
 
 
 
 
 
 
391
  }
388
  .yarpp_separated{
389
  display:inline-block;
390
  margin:1.5em 1em
391
+ }
392
+
393
+ .yarpp-callout{
394
+ margin: 5px 0 15px;
395
+ border: 1px solid #ccd0d4;
396
+ border-left-width:4px;
397
+ padding:1px 12px;
398
+ }
399
+ .yarpp-notice{
400
+ border-left-color:#ffb900;;
401
  }
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.8.0
6
  Author: YARPP
7
  Author URI: https://yarpp.com/
8
  Plugin URI: https://yarpp.com/
@@ -23,7 +23,7 @@ if(!defined('WP_CONTENT_DIR')){
23
  define('WP_CONTENT_DIR', substr($tr,0,strrpos($tr,'/')));
24
  }
25
 
26
- define('YARPP_VERSION', '5.8.0');
27
 
28
  define('YARPP_DIR', dirname(__FILE__));
29
  /**
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.9.0
6
  Author: YARPP
7
  Author URI: https://yarpp.com/
8
  Plugin URI: https://yarpp.com/
23
  define('WP_CONTENT_DIR', substr($tr,0,strrpos($tr,'/')));
24
  }
25
 
26
+ define('YARPP_VERSION', '5.9.0');
27
 
28
  define('YARPP_DIR', dirname(__FILE__));
29
  /**