Yet Another Related Posts Plugin (YARPP) - Version 5.10.1

Version Description

(23-October-2020) = * Critical Bugfix: Reverts query changes from the v5.10.0 update as it caused 500 fatal errors on some WordPress installations. We sincerely apologies for any issues it may have caused. We did test the release for weeks, but each environment is just a bit different. We are actively testing a bug fix with those affected that volunteered before we release it again.

Download this release

Release Info

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

Code changes from version 5.10.0 to 5.10.1

classes/YARPP_Cache.php CHANGED
@@ -1,18 +1,7 @@
1
  <?php
2
  abstract class YARPP_Cache {
3
  protected $core;
4
- /**
5
- * During "YARPP Time", we add a bunch of filters to modify WP_Query
6
- * @var bool
7
- */
8
  protected $yarpp_time = false;
9
-
10
- /**
11
- * Keep track of when we're calculating, so YARPP core can know when to back off from initiating calculating
12
- * related again.
13
- * @var bool
14
- */
15
- protected $discovering_keywords = false;
16
  public $score_override = false;
17
  public $online_limit = false;
18
  public $last_sql;
@@ -202,7 +191,7 @@ abstract class YARPP_Cache {
202
  }
203
  }
204
 
205
- $newsql .= ',4) as score';
206
 
207
  $newsql .= "\n from $wpdb->posts \n";
208
 
@@ -361,16 +350,16 @@ abstract class YARPP_Cache {
361
  return apply_filters('yarpp_title_keywords', $this->extract_keywords(get_the_title($ID), $max, $ID), $max, $ID);
362
  }
363
  protected function body_keywords( $ID, $max = 20 ) {
 
 
 
 
 
364
  $post = get_post( $ID );
365
  if ( empty( $post ) ) {
366
  return '';
367
  }
368
- $this->discovering_keywords = true;
369
- $body_content = apply_filters( 'the_content', $post->post_content );
370
- $this->discovering_keywords = false;
371
- $keywords = apply_filters( 'yarpp_body_keywords', $this->extract_keywords( $body_content, $max, $ID ), $max, $ID );
372
-
373
- return $keywords;
374
  }
375
 
376
  private function extract_keywords( $html, $max = 20, $ID = 0 ) {
@@ -464,13 +453,4 @@ abstract class YARPP_Cache {
464
  $types = array_slice($types, 0, $max);
465
  return implode(' ', $types);
466
  }
467
-
468
- /**
469
- * Returns whether or not we're currently discovering the keywords on a reference post.
470
- * (This is a very bad time to start looking for related posts! So YARPP core should be able to detect this.)
471
- * @return bool
472
- */
473
- public function discovering_keywords(){
474
- return $this->discovering_keywords;
475
- }
476
  }
1
  <?php
2
  abstract class YARPP_Cache {
3
  protected $core;
 
 
 
 
4
  protected $yarpp_time = false;
 
 
 
 
 
 
 
5
  public $score_override = false;
6
  public $online_limit = false;
7
  public $last_sql;
191
  }
192
  }
193
 
194
+ $newsql .= ',1) as score';
195
 
196
  $newsql .= "\n from $wpdb->posts \n";
197
 
350
  return apply_filters('yarpp_title_keywords', $this->extract_keywords(get_the_title($ID), $max, $ID), $max, $ID);
351
  }
352
  protected function body_keywords( $ID, $max = 20 ) {
353
+ global $wp_current_filter;
354
+ $filter_count = array_count_values( $wp_current_filter );
355
+ if ( ! empty( $filter_count['the_content'] ) && $filter_count['the_content'] > 1 ) {
356
+ return '';
357
+ }
358
  $post = get_post( $ID );
359
  if ( empty( $post ) ) {
360
  return '';
361
  }
362
+ return apply_filters( 'yarpp_body_keywords', $this->extract_keywords( apply_filters( 'the_content', $post->post_content ), $max, $ID ), $max, $ID );
 
 
 
 
 
363
  }
364
 
365
  private function extract_keywords( $html, $max = 20, $ID = 0 ) {
453
  $types = array_slice($types, 0, $max);
454
  return implode(' ', $types);
455
  }
 
 
 
 
 
 
 
 
 
456
  }
classes/YARPP_Cache_Bypass.php CHANGED
@@ -55,21 +55,9 @@ class YARPP_Cache_Bypass extends YARPP_Cache {
55
  /*
56
  * Only order by score if the score function is added in fields_filter,
57
  * which only happens if there are related posts in the post-data.
58
- * If ordering by score also order by post ID to keep them consistent in cases where the score is the same
59
- * for multiple posts.
60
  */
61
  if ($this->score_override && is_array($this->related_postdata) && count($this->related_postdata)) {
62
- return str_replace(
63
- array(
64
- "$wpdb->posts.post_date ASC",
65
- "$wpdb->posts.post_date DESC"
66
- ),
67
- array(
68
- "score ASC, yarpp.ID ASC",
69
- "score DESC, yarpp.ID ASC"
70
- ),
71
- $arg
72
- );
73
  }
74
 
75
  return $arg;
55
  /*
56
  * Only order by score if the score function is added in fields_filter,
57
  * which only happens if there are related posts in the post-data.
 
 
58
  */
59
  if ($this->score_override && is_array($this->related_postdata) && count($this->related_postdata)) {
60
+ return str_replace("$wpdb->posts.post_date","score",$arg);
 
 
 
 
 
 
 
 
 
 
61
  }
62
 
63
  return $arg;
classes/YARPP_Cache_Postmeta.php CHANGED
@@ -78,25 +78,11 @@ class YARPP_Cache_Postmeta extends YARPP_Cache {
78
 
79
  public function orderby_filter($arg) {
80
  global $wpdb;
81
- /*
82
- * Only order by score if the score function is added in fields_filter,
83
- * which only happens if there are related posts in the post-data.
84
- * If ordering by score also order by post ID to keep them consistent in cases where the score is the same
85
- * for multiple posts.
86
- */
87
  if ($this->score_override &&
88
  is_array($this->related_postdata) && count($this->related_postdata))
89
- return str_replace(
90
- array(
91
- "$wpdb->posts.post_date ASC",
92
- "$wpdb->posts.post_date DESC"
93
- ),
94
- array(
95
- "score ASC, yarpp.ID ASC",
96
- "score DESC, yarpp.ID ASC"
97
- ),
98
- $arg
99
- );
100
  return $arg;
101
  }
102
 
78
 
79
  public function orderby_filter($arg) {
80
  global $wpdb;
81
+ // only order by score if the score function is added in fields_filter, which only happens
82
+ // if there are related posts in the postdata
 
 
 
 
83
  if ($this->score_override &&
84
  is_array($this->related_postdata) && count($this->related_postdata))
85
+ return str_replace("$wpdb->posts.post_date","score",$arg);
 
 
 
 
 
 
 
 
 
 
86
  return $arg;
87
  }
88
 
classes/YARPP_Cache_Tables.php CHANGED
@@ -134,20 +134,8 @@ class YARPP_Cache_Tables extends YARPP_Cache {
134
 
135
  public function orderby_filter($arg) {
136
  global $wpdb;
137
- // If ordering by score also order by post ID to keep them consistent in cases where the score is the same
138
- // for multiple posts.
139
  if ($this->yarpp_time and $this->score_override)
140
- $arg = str_replace(
141
- array(
142
- "$wpdb->posts.post_date ASC",
143
- "$wpdb->posts.post_date DESC"
144
- ),
145
- array(
146
- "score ASC, yarpp.ID ASC",
147
- "score DESC, yarpp.ID ASC"
148
- ),
149
- $arg
150
- );
151
  return $arg;
152
  }
153
 
134
 
135
  public function orderby_filter($arg) {
136
  global $wpdb;
 
 
137
  if ($this->yarpp_time and $this->score_override)
138
+ $arg = str_replace("$wpdb->posts.post_date","yarpp.score",$arg);
 
 
 
 
 
 
 
 
 
 
139
  return $arg;
140
  }
141
 
classes/YARPP_Core.php CHANGED
@@ -15,13 +15,7 @@ class YARPP {
15
  public $default_hidden_metaboxes = array();
16
  public $debug = false;
17
  public $yarppPro = null;
18
- /**
19
- * @var YARPP_Cache_Bypass
20
- */
21
  public $cache_bypass;
22
- /**
23
- * @var YARPP_Cache
24
- */
25
  public $cache;
26
  public $admin;
27
  /**
@@ -29,9 +23,6 @@ class YARPP {
29
  */
30
  public $db_schema;
31
 
32
- /**
33
- * @var YARPP_Cache
34
- */
35
  private $active_cache;
36
  private $storage_class;
37
  private $default_dimensions = array(
@@ -864,7 +855,7 @@ class YARPP {
864
 
865
  return wp_list_pluck( $this->post_types, $field );
866
  }
867
-
868
  private function post_type_filter($post_type) {
869
  if ($post_type->public) return true;
870
  if (isset($post_type->yarpp_support)) return $post_type->yarpp_support;
@@ -1088,12 +1079,10 @@ class YARPP {
1088
  * @return string
1089
  */
1090
  public function display_related($reference_ID = null, $args = array(), $echo = true) {
1091
-
1092
- // If YARPP cache is already finding the current post's content, don't ask it to do it again.
1093
- // Avoid infinite recursion here.
1094
- if ( $this->active_cache_busy()) return false;
1095
  $this->enforce();
1096
-
1097
  wp_enqueue_style('yarppRelatedCss', plugins_url('/style/related.css', YARPP_MAIN_FILE));
1098
  $output = null;
1099
 
@@ -1122,9 +1111,7 @@ class YARPP {
1122
  extract($this->parse_args($args, $options));
1123
 
1124
  $cache_status = $this->active_cache->enforce($reference_ID);
1125
- if ($cache_status === YARPP_DONT_RUN){
1126
- return;
1127
- }
1128
  if ($cache_status !== YARPP_NO_RELATED) $this->active_cache->begin_yarpp_time($reference_ID, $args);
1129
 
1130
  $this->save_post_context();
@@ -1219,12 +1206,10 @@ class YARPP {
1219
  * @param (array) $args
1220
  */
1221
  public function get_related($reference_ID = null, $args = array()) {
1222
- // If YARPP cache is already finding the current post's content, don't ask it to do it again.
1223
- // Avoid infinite recursion here.
1224
- if ( $this->active_cache_busy()) return false;
1225
  $this->enforce();
1226
 
1227
-
1228
  if (is_numeric($reference_ID)) {
1229
  $reference_ID = (int) $reference_ID;
1230
  } else {
@@ -1242,9 +1227,7 @@ class YARPP {
1242
  extract($this->parse_args($args, $options));
1243
 
1244
  $cache_status = $this->active_cache->enforce($reference_ID);
1245
- if ($cache_status === YARPP_DONT_RUN || $cache_status === YARPP_NO_RELATED) {
1246
- return array();
1247
- }
1248
 
1249
  /* Get ready for YARPP TIME! */
1250
  $this->active_cache->begin_yarpp_time($reference_ID, $args);
@@ -1261,15 +1244,16 @@ class YARPP {
1261
 
1262
  $related_query->posts = apply_filters(
1263
  'yarpp_results',
1264
- $related_query->posts, array(
1265
-
1266
- 'function' => 'get_related',
1267
  'args' => $args,
1268
  'related_ID' => $reference_ID
1269
  )
1270
  );
1271
 
1272
  $this->active_cache->end_yarpp_time();
 
1273
  return $related_query->posts;
1274
  }
1275
 
@@ -1278,9 +1262,9 @@ class YARPP {
1278
  * @param (array) $args
1279
  */
1280
  public function related_exist($reference_ID = null, $args = array()) {
1281
- // If YARPP cache is already finding the current post's content, don't ask it to do it again.
1282
- // Avoid infinite recursion here.
1283
- if ($this->active_cache_busy()) return false;
1284
  $this->enforce();
1285
 
1286
  if (is_numeric($reference_ID)) {
@@ -1296,9 +1280,7 @@ class YARPP {
1296
 
1297
  $cache_status = $this->active_cache->enforce($reference_ID);
1298
 
1299
- if ($cache_status === YARPP_NO_RELATED) {
1300
- return false;
1301
- }
1302
 
1303
  /* Get ready for YARPP TIME! */
1304
  $this->active_cache->begin_yarpp_time($reference_ID, $args);
@@ -1323,6 +1305,7 @@ class YARPP {
1323
  unset($related_query);
1324
 
1325
  $this->active_cache->end_yarpp_time();
 
1326
  return $return;
1327
  }
1328
 
@@ -1332,8 +1315,7 @@ class YARPP {
1332
  * @return string
1333
  */
1334
  public function display_demo_related($args = array(), $echo = true) {
1335
- // If YARPP cache is already finding the current post's content, don't ask it to do it again.
1336
- // Avoid infinite recursion here.
1337
  if ($this->cache_bypass->demo_time) return false;
1338
 
1339
  $options = array(
@@ -1484,15 +1466,15 @@ class YARPP {
1484
  */
1485
 
1486
  public function the_content($content) {
1487
- // If the cache is currently finding a post's keywords, don't start adding YARPP related posts to it. That's
1488
- // unnecessarily recursion.
1489
- if (is_feed() || $this->active_cache_busy()) return $content;
1490
 
1491
  /* If the content includes <!--noyarpp-->, don't display */
1492
  if (!stristr($content, '<!--noyarpp-->')) {
1493
  $content .= $this->display_basic();
1494
  $content .= $this->display_pro('website');
1495
  }
 
1496
  return $content;
1497
  }
1498
 
@@ -1647,7 +1629,7 @@ class YARPP {
1647
  return $text;
1648
  }
1649
 
1650
- /*
1651
  * Gets the list of valid interval units used by YARPP and MySQL interval statements.
1652
  *
1653
  * @return array keys are valid values for recent units, and for MySQL interval
@@ -1660,13 +1642,4 @@ class YARPP {
1660
  'month' => __('month(s)','yarpp')
1661
  );
1662
  }
1663
-
1664
- /**
1665
- * Detects if the active cache is currently discovering post keywords. If so, it's a bad time
1666
- * to start calculating related posts yet again.
1667
- * @return bool
1668
- */
1669
- protected function active_cache_busy(){
1670
- return $this->active_cache instanceof YARPP_Cache && $this->active_cache->discovering_keywords();
1671
- }
1672
  }
15
  public $default_hidden_metaboxes = array();
16
  public $debug = false;
17
  public $yarppPro = null;
 
 
 
18
  public $cache_bypass;
 
 
 
19
  public $cache;
20
  public $admin;
21
  /**
23
  */
24
  public $db_schema;
25
 
 
 
 
26
  private $active_cache;
27
  private $storage_class;
28
  private $default_dimensions = array(
855
 
856
  return wp_list_pluck( $this->post_types, $field );
857
  }
858
+
859
  private function post_type_filter($post_type) {
860
  if ($post_type->public) return true;
861
  if (isset($post_type->yarpp_support)) return $post_type->yarpp_support;
1079
  * @return string
1080
  */
1081
  public function display_related($reference_ID = null, $args = array(), $echo = true) {
1082
+
1083
+ /* If we're already in a YARPP loop, stop now. */
1084
+ if ($this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time()) return false;
 
1085
  $this->enforce();
 
1086
  wp_enqueue_style('yarppRelatedCss', plugins_url('/style/related.css', YARPP_MAIN_FILE));
1087
  $output = null;
1088
 
1111
  extract($this->parse_args($args, $options));
1112
 
1113
  $cache_status = $this->active_cache->enforce($reference_ID);
1114
+ if ($cache_status === YARPP_DONT_RUN) return;
 
 
1115
  if ($cache_status !== YARPP_NO_RELATED) $this->active_cache->begin_yarpp_time($reference_ID, $args);
1116
 
1117
  $this->save_post_context();
1206
  * @param (array) $args
1207
  */
1208
  public function get_related($reference_ID = null, $args = array()) {
1209
+ /* If we're already in a YARPP loop, stop now. */
1210
+ if ($this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time()) return false;
 
1211
  $this->enforce();
1212
 
 
1213
  if (is_numeric($reference_ID)) {
1214
  $reference_ID = (int) $reference_ID;
1215
  } else {
1227
  extract($this->parse_args($args, $options));
1228
 
1229
  $cache_status = $this->active_cache->enforce($reference_ID);
1230
+ if ($cache_status === YARPP_DONT_RUN || $cache_status === YARPP_NO_RELATED) return array();
 
 
1231
 
1232
  /* Get ready for YARPP TIME! */
1233
  $this->active_cache->begin_yarpp_time($reference_ID, $args);
1244
 
1245
  $related_query->posts = apply_filters(
1246
  'yarpp_results',
1247
+ $related_query->posts,
1248
+ array(
1249
+ 'function' => 'get_related',
1250
  'args' => $args,
1251
  'related_ID' => $reference_ID
1252
  )
1253
  );
1254
 
1255
  $this->active_cache->end_yarpp_time();
1256
+
1257
  return $related_query->posts;
1258
  }
1259
 
1262
  * @param (array) $args
1263
  */
1264
  public function related_exist($reference_ID = null, $args = array()) {
1265
+ /* if we're already in a YARPP loop, stop now. */
1266
+ if ($this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time()) return false;
1267
+
1268
  $this->enforce();
1269
 
1270
  if (is_numeric($reference_ID)) {
1280
 
1281
  $cache_status = $this->active_cache->enforce($reference_ID);
1282
 
1283
+ if ($cache_status === YARPP_NO_RELATED) return false;
 
 
1284
 
1285
  /* Get ready for YARPP TIME! */
1286
  $this->active_cache->begin_yarpp_time($reference_ID, $args);
1305
  unset($related_query);
1306
 
1307
  $this->active_cache->end_yarpp_time();
1308
+
1309
  return $return;
1310
  }
1311
 
1315
  * @return string
1316
  */
1317
  public function display_demo_related($args = array(), $echo = true) {
1318
+ /* if we're already in a demo YARPP loop, stop now. */
 
1319
  if ($this->cache_bypass->demo_time) return false;
1320
 
1321
  $options = array(
1466
  */
1467
 
1468
  public function the_content($content) {
1469
+ /* this filter doesn't handle feeds */
1470
+ if (is_feed()) return $content;
 
1471
 
1472
  /* If the content includes <!--noyarpp-->, don't display */
1473
  if (!stristr($content, '<!--noyarpp-->')) {
1474
  $content .= $this->display_basic();
1475
  $content .= $this->display_pro('website');
1476
  }
1477
+
1478
  return $content;
1479
  }
1480
 
1629
  return $text;
1630
  }
1631
 
1632
+ /**
1633
  * Gets the list of valid interval units used by YARPP and MySQL interval statements.
1634
  *
1635
  * @return array keys are valid values for recent units, and for MySQL interval
1642
  'month' => __('month(s)','yarpp')
1643
  );
1644
  }
 
 
 
 
 
 
 
 
 
1645
  }
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.10.0
9
 
10
  The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
11
 
@@ -295,6 +295,9 @@ add_action(
295
  `
296
 
297
  == Changelog ==
 
 
 
298
  = 5.10.0 (22-October-2020) =
299
  * Enhancement: Faster queries and a speed boost ⚡️
300
  * [Enhancement](https://wordpress.org/support/topic/yarp-page-break/): On posts with page breaks, show YARPP only on the last page
@@ -1040,5 +1043,5 @@ After a break of many years, the plugin is 100% supported now that the baton has
1040
  * Initial upload
1041
 
1042
  == Upgrade Notice ==
1043
- = 5.10.0 =
1044
  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!
5
  Requires PHP: 5.3
6
  License: GPLv2 or later
7
  Tested up to: 5.5
8
+ Stable tag: 5.10.1
9
 
10
  The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
11
 
295
  `
296
 
297
  == Changelog ==
298
+ = 5.10.1 (23-October-2020) =
299
+ * [Critical Bugfix](https://wordpress.org/support/topic/version-5-10-0-generated-error-500/): Reverts query changes from the v5.10.0 update as it caused 500 fatal errors on some WordPress installations. We sincerely apologies for any issues it may have caused. We did test the release for weeks, but each environment is just a bit different. We are actively testing a bug fix with those affected that volunteered before we release it again.
300
+
301
  = 5.10.0 (22-October-2020) =
302
  * Enhancement: Faster queries and a speed boost ⚡️
303
  * [Enhancement](https://wordpress.org/support/topic/yarp-page-break/): On posts with page breaks, show YARPP only on the last page
1043
  * Initial upload
1044
 
1045
  == Upgrade Notice ==
1046
+ = 5.10.1 =
1047
  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.10.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.10.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.10.1
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.10.1');
27
 
28
  define('YARPP_DIR', dirname(__FILE__));
29
  /**