Yet Another Related Posts Plugin (YARPP) - Version 5.14.0

Version Description

(9-March-2021) = * Enhancement: Improve pageload speed by avoiding checking YARPP database requirements on frontend requests

Download this release

Release Info

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

Code changes from version 5.13.0 to 5.14.0

classes/YARPP_Admin.php CHANGED
@@ -69,9 +69,25 @@ class YARPP_Admin {
69
  add_action('wp_ajax_yarpp_optin_disable', array($this, 'ajax_optin_disable'));
70
  add_action('wp_ajax_yarpp_set_display_code', array($this, 'ajax_set_display_code'));
71
  add_action('wp_ajax_yarpp_switch', array($this, 'ajax_switch'));
 
72
  }
73
  }
74
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  /**
76
  * Check review notice status for current user
77
  *
@@ -509,6 +525,15 @@ class YARPP_Admin {
509
  wp_enqueue_script('postbox');
510
  wp_enqueue_script('wp-pointer');
511
  wp_enqueue_script('yarpp_options', plugins_url('js/options_basic.js', dirname(__FILE__)), array('jquery'), $version );
 
 
 
 
 
 
 
 
 
512
  }
513
 
514
  $metabox_post_types = $this->core->get_option('auto_display_post_types');
69
  add_action('wp_ajax_yarpp_optin_disable', array($this, 'ajax_optin_disable'));
70
  add_action('wp_ajax_yarpp_set_display_code', array($this, 'ajax_set_display_code'));
71
  add_action('wp_ajax_yarpp_switch', array($this, 'ajax_switch'));
72
+ add_action('wp_ajax_yarpp_clear_cache', array($this, 'ajax_clear_cache'));
73
  }
74
  }
75
+ /**
76
+ * Ajax callback for clearing the YARPP cache
77
+ *
78
+ * @since 5.13.0
79
+ */
80
+ public function ajax_clear_cache() {
81
+ if( false === check_ajax_referer( 'clear_cache_yarpp', false, false ) ) {
82
+ echo 'nonce_fail';
83
+ } else if ( current_user_can( 'manage_options' ) ) {
84
+ $this->core->cache->flush();
85
+ echo 'success';
86
+ } else {
87
+ echo 'forbidden';
88
+ }
89
+ wp_die();
90
+ }
91
  /**
92
  * Check review notice status for current user
93
  *
525
  wp_enqueue_script('postbox');
526
  wp_enqueue_script('wp-pointer');
527
  wp_enqueue_script('yarpp_options', plugins_url('js/options_basic.js', dirname(__FILE__)), array('jquery'), $version );
528
+ // Localize the script with messages
529
+ $translation_strings = array(
530
+ 'alert_message' => __( 'This will delete all cache for YARPP.

Are you sure?', 'yarpp' ),
531
+ 'success' => __( 'Cache cleared successfully!', 'yarpp' ),
532
+ 'forbidden' => __( 'You are not allowed to do this!', 'yarpp' ),
533
+ 'nonce_fail' => __( 'You left this page open for too long. Please refresh the page and try again!', 'yarpp' ),
534
+ 'error' => __( 'There is some error!', 'yarpp' ),
535
+ );
536
+ wp_localize_script( 'yarpp_options', 'yarpp_messages', $translation_strings );
537
  }
538
 
539
  $metabox_post_types = $this->core->get_option('auto_display_post_types');
classes/YARPP_Cache.php CHANGED
@@ -65,7 +65,9 @@ abstract class YARPP_Cache {
65
  if ($status === YARPP_DONT_RUN) return YARPP_DONT_RUN;
66
 
67
  // If not cached, process now:
68
- if ($status === YARPP_NOT_CACHED || $force) $status = $this->update((int) $reference_ID); // status now will be YARPP_NO_RELATED | YARPP_RELATED
 
 
69
  // There are no related posts
70
  if ($status === YARPP_NO_RELATED) return YARPP_NO_RELATED;
71
 
@@ -451,6 +453,36 @@ abstract class YARPP_Cache {
451
  }
452
 
453
  /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
  * Returns whether or not we're currently discovering the keywords on a reference post.
455
  * (This is a very bad time to start looking for related posts! So YARPP core should be able to detect this.)
456
  * @return bool
65
  if ($status === YARPP_DONT_RUN) return YARPP_DONT_RUN;
66
 
67
  // If not cached, process now:
68
+ if ($status === YARPP_NOT_CACHED || $force) $status = $this->update((int) $reference_ID);
69
+ // Despite our earlier check, somehow the database doesn't seem to be setup properly
70
+ if ($status === YARPP_DONT_RUN) return YARPP_DONT_RUN;
71
  // There are no related posts
72
  if ($status === YARPP_NO_RELATED) return YARPP_NO_RELATED;
73
 
453
  }
454
 
455
  /**
456
+ * Does a database query without emitting any warnings if there's an SQL error. (Although they will still show up
457
+ * in the Query Monitor plugin, which is a feature.)
458
+ * Throws an exception if there is an error.
459
+ * @param string $wpdb_method method on WPDB to call
460
+ * @param array $args array of arguments to pass it.
461
+ *
462
+ * @return mixed
463
+ * @throws Exception
464
+ */
465
+ protected function query_safely($wpdb_method, $args) {
466
+ global $wpdb;
467
+ $last_error = $wpdb->last_error;
468
+ $wpdb->last_error = null;
469
+ ob_start();
470
+ $value = call_user_func_array(
471
+ array( $wpdb, $wpdb_method ),
472
+ $args
473
+ );
474
+ if ( $wpdb->last_error ) {
475
+ ob_clean();
476
+
477
+ return new WP_Error( 'yarpp_bad_db', $wpdb->last_error );
478
+ }
479
+ ob_flush();
480
+ $wpdb->last_error = $last_error;
481
+
482
+ return $value;
483
+ }
484
+
485
+ /*
486
  * Returns whether or not we're currently discovering the keywords on a reference post.
487
  * (This is a very bad time to start looking for related posts! So YARPP core should be able to detect this.)
488
  * @return bool
classes/YARPP_Cache_Bypass.php CHANGED
@@ -205,8 +205,14 @@ class YARPP_Cache_Bypass extends YARPP_Cache {
205
  return;
206
  }
207
 
208
- $results = $wpdb->get_results($this->sql($reference_ID), ARRAY_A);
209
- if ( !$results || !count($results) )
 
 
 
 
 
 
210
  return false;
211
 
212
  $results_ids = wp_list_pluck( $results, 'ID' );
205
  return;
206
  }
207
 
208
+ $results = $this->query_safely(
209
+ 'get_results',
210
+ array(
211
+ $this->sql($reference_ID),
212
+ ARRAY_A
213
+ )
214
+ );
215
+ if ( !$results || !count($results) || $results instanceof WP_Error)
216
  return false;
217
 
218
  $results_ids = wp_list_pluck( $results, 'ID' );
classes/YARPP_Cache_Postmeta.php CHANGED
@@ -167,7 +167,16 @@ class YARPP_Cache_Postmeta extends YARPP_Cache {
167
  global $wpdb;
168
 
169
  $original_related = $this->related($reference_ID);
170
- $related = $wpdb->get_results($this->sql($reference_ID), ARRAY_A);
 
 
 
 
 
 
 
 
 
171
  $new_related = wp_list_pluck( $related, 'ID' );
172
 
173
  if ( count($new_related) ) {
167
  global $wpdb;
168
 
169
  $original_related = $this->related($reference_ID);
170
+ $related = $this->query_safely(
171
+ 'get_results',
172
+ array(
173
+ $this->sql($reference_ID),
174
+ ARRAY_A
175
+ )
176
+ );
177
+ if($related instanceof WP_Error){
178
+ return YARPP_DONT_RUN;
179
+ }
180
  $new_related = wp_list_pluck( $related, 'ID' );
181
 
182
  if ( count($new_related) ) {
classes/YARPP_Cache_Tables.php CHANGED
@@ -11,33 +11,11 @@ class YARPP_Cache_Tables extends YARPP_Cache {
11
  }
12
 
13
  public function is_enabled() {
14
- global $wpdb;
15
- // now check for the cache tables
16
- $tabledata = $wpdb->get_col("show tables");
17
- if (in_array($wpdb->prefix . YARPP_TABLES_RELATED_TABLE,$tabledata) !== false)
18
- return true;
19
- else
20
- return false;
21
  }
22
 
23
  public function setup() {
24
- global $wpdb;
25
-
26
- $charset_collate = '';
27
- if (!empty($wpdb->charset)) $charset_collate = "DEFAULT CHARACTER SET ".$wpdb->charset;
28
- if (!empty($wpdb->collate)) $charset_collate .= " COLLATE ".$wpdb->collate;
29
-
30
- $wpdb->query(
31
- "CREATE TABLE IF NOT EXISTS `".$wpdb->prefix.YARPP_TABLES_RELATED_TABLE."` (
32
- `reference_ID` bigint(20) unsigned NOT NULL default '0',
33
- `ID` bigint(20) unsigned NOT NULL default '0',
34
- `score` float unsigned NOT NULL default '0',
35
- `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
36
- PRIMARY KEY (`reference_ID`,`ID`),
37
- INDEX (`score`),
38
- INDEX (`ID`)
39
- )$charset_collate;"
40
- );
41
  }
42
 
43
  public function upgrade($last_version) {
@@ -182,7 +160,7 @@ class YARPP_Cache_Tables extends YARPP_Cache {
182
  remove_action('parse_query',array(&$this,'set_score_override_flag'));
183
  }
184
 
185
- // @return YARPP_NO_RELATED | YARPP_RELATED | YARPP_NOT_CACHED
186
  public function is_cached($reference_ID) {
187
  global $wpdb;
188
 
@@ -192,7 +170,19 @@ class YARPP_Cache_Tables extends YARPP_Cache {
192
 
193
  // @since 3.5.3b3: check for max instead of min, so that if ID=0 and ID=X
194
  // are both saved, we act like there *are* related posts, because there are.
195
- $max_id = $wpdb->get_var("select max(ID) as max_id from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID = $reference_ID");
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
  if ( is_null( $max_id ) )
198
  return YARPP_NOT_CACHED;
@@ -221,7 +211,7 @@ class YARPP_Cache_Tables extends YARPP_Cache {
221
  wp_cache_delete( 'is_cached_' . $id, 'yarpp' );
222
  }
223
 
224
- // @return YARPP_RELATED | YARPP_NO_RELATED
225
  // @used by enforce
226
  protected function update($reference_ID) {
227
  global $wpdb;
@@ -233,7 +223,15 @@ class YARPP_Cache_Tables extends YARPP_Cache {
233
  $this->clear($reference_ID);
234
  }
235
 
236
- $wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) " . $this->sql($reference_ID) . " on duplicate key update date = now()");
 
 
 
 
 
 
 
 
237
 
238
  // If there were related entries saved...
239
  if ( $wpdb->rows_affected ) {
11
  }
12
 
13
  public function is_enabled() {
14
+ return $this->core->db_schema->cache_table_exists();
 
 
 
 
 
 
15
  }
16
 
17
  public function setup() {
18
+ $this->core->db_schema->create_cache_table();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  }
20
 
21
  public function upgrade($last_version) {
160
  remove_action('parse_query',array(&$this,'set_score_override_flag'));
161
  }
162
 
163
+ // @return YARPP_NO_RELATED | YARPP_RELATED | YARPP_NOT_CACHED | YARPP_DONT_RUN
164
  public function is_cached($reference_ID) {
165
  global $wpdb;
166
 
170
 
171
  // @since 3.5.3b3: check for max instead of min, so that if ID=0 and ID=X
172
  // are both saved, we act like there *are* related posts, because there are.
173
+
174
+ // Also, if there's a database error, hide it and just ignore it. It's probably a missing table that we'll fix
175
+ // next admin request.
176
+ $max_id = $this->query_safely(
177
+ 'get_var',
178
+ array(
179
+ "select max(ID) as max_id from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID = $reference_ID"
180
+ )
181
+ );
182
+
183
+ if($max_id instanceof WP_Error){
184
+ return YARPP_DONT_RUN;
185
+ }
186
 
187
  if ( is_null( $max_id ) )
188
  return YARPP_NOT_CACHED;
211
  wp_cache_delete( 'is_cached_' . $id, 'yarpp' );
212
  }
213
 
214
+ // @return YARPP_RELATED | YARPP_NO_RELATED | YARPP_DONT_RUN
215
  // @used by enforce
216
  protected function update($reference_ID) {
217
  global $wpdb;
223
  $this->clear($reference_ID);
224
  }
225
 
226
+ $result = $this->query_safely(
227
+ 'query',
228
+ array(
229
+ "insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) " . $this->sql( $reference_ID ) . " on duplicate key update date = now()"
230
+ )
231
+ );
232
+ if($result instanceof WP_Error){
233
+ return YARPP_DONT_RUN;
234
+ }
235
 
236
  // If there were related entries saved...
237
  if ( $wpdb->rows_affected ) {
classes/YARPP_Core.php CHANGED
@@ -118,7 +118,9 @@ class YARPP {
118
  if (is_admin()) {
119
  require_once(YARPP_DIR.'/classes/YARPP_Admin.php');
120
  $this->admin = new YARPP_Admin($this);
121
- $this->enforce();
 
 
122
  }
123
  $shortcode = new YARPP_Shortcode();
124
  $shortcode->register();
@@ -300,16 +302,18 @@ class YARPP {
300
  }
301
 
302
  public function enabled() {
303
- if (!(bool) $this->cache->is_enabled()) return false;
304
- if (!(bool) $this->diagnostic_fulltext_disabled()) return $this->diagnostic_fulltext_indices();
305
- return true;
 
 
306
  }
307
 
308
  public function activate() {
309
  /*
310
  * If it's not known to be disabled, but the indexes aren't there.
311
  */
312
- if (!$this->diagnostic_fulltext_disabled() && !$this->diagnostic_fulltext_indices()) {
313
  $this->enable_fulltext();
314
  }
315
 
@@ -347,7 +351,12 @@ class YARPP {
347
  return $engine;
348
  }
349
  }
350
-
 
 
 
 
 
351
  function diagnostic_fulltext_disabled() {
352
  return $this->db_options->is_fulltext_disabled();
353
  }
@@ -407,8 +416,6 @@ class YARPP {
407
  /* cut threshold by half: */
408
  $threshold = (float) $this->get_option('threshold');
409
  $this->set_option(array('threshold' => round($threshold / 2)));
410
-
411
- $this->db_options->set_fulltext_disabled(true);
412
  }
413
 
414
  /*
@@ -416,9 +423,7 @@ class YARPP {
416
  * @return bool
417
  */
418
  public function diagnostic_fulltext_indices() {
419
- global $wpdb;
420
- $wpdb->get_results("SHOW INDEX FROM {$wpdb->posts} WHERE Key_name = 'yarpp_title' OR Key_name = 'yarpp_content'");
421
- return ($wpdb->num_rows >= 2);
422
  }
423
 
424
  public function diagnostic_hidden_metaboxes() {
@@ -915,7 +920,11 @@ class YARPP {
915
  } else {
916
  $post_types = array(get_post_type($reference_ID));
917
  }
918
- return $post_types;
 
 
 
 
919
  }
920
 
921
  private function post_type_filter($post_type) {
@@ -995,7 +1004,6 @@ class YARPP {
995
  ),
996
  'diagnostics' => array(
997
  'myisam_posts' => $this->diagnostic_myisam_posts(),
998
- 'fulltext_disabled' => $this->diagnostic_fulltext_disabled(),
999
  'fulltext_indices' => $this->diagnostic_fulltext_indices(),
1000
  'hidden_metaboxes' => $this->diagnostic_hidden_metaboxes(),
1001
  'post_thumbnails' => $this->diagnostic_post_thumbnails(),
@@ -1100,12 +1108,9 @@ class YARPP {
1100
  return null;
1101
  }
1102
 
1103
- $post_types = apply_filters('yarpp_map_post_types', $post_types, 'website');
1104
-
1105
  return $this->display_related(
1106
  null,
1107
  array(
1108
- 'post_type' => $post_types,
1109
  'domain' => 'website'
1110
  ),
1111
  false
@@ -1147,8 +1152,6 @@ class YARPP {
1147
  public function display_related($reference_ID = null, $args = array(), $echo = true) {
1148
  // Avoid infinite recursion here.
1149
  if ( $this->do_not_query_for_related()) return false;
1150
- $this->enforce();
1151
-
1152
  wp_enqueue_style('yarppRelatedCss', plugins_url('/style/related.css', YARPP_MAIN_FILE));
1153
  $output = null;
1154
 
@@ -1280,7 +1283,6 @@ class YARPP {
1280
  public function get_related($reference_ID = null, $args = array()) {
1281
  // Avoid infinite recursion here.
1282
  if ( $this->do_not_query_for_related()) return false;
1283
- $this->enforce();
1284
 
1285
 
1286
  if (is_numeric($reference_ID)) {
@@ -1300,9 +1302,7 @@ class YARPP {
1300
  extract($this->parse_args($args, $options));
1301
 
1302
  $cache_status = $this->active_cache->enforce($reference_ID);
1303
- if ($cache_status === YARPP_DONT_RUN || $cache_status === YARPP_NO_RELATED) {
1304
- return array();
1305
- }
1306
 
1307
  /* Get ready for YARPP TIME! */
1308
  $this->active_cache->begin_yarpp_time($reference_ID, $args);
@@ -1338,7 +1338,6 @@ class YARPP {
1338
  public function related_exist($reference_ID = null, $args = array()) {
1339
  // Avoid infinite recursion here.
1340
  if ($this->do_not_query_for_related()) return false;
1341
- $this->enforce();
1342
 
1343
  if (is_numeric($reference_ID)) {
1344
  $reference_ID = (int) $reference_ID;
@@ -1352,10 +1351,9 @@ class YARPP {
1352
  $this->setup_active_cache($args);
1353
 
1354
  $cache_status = $this->active_cache->enforce($reference_ID);
1355
-
1356
- if ($cache_status === YARPP_NO_RELATED) {
1357
- return false;
1358
- }
1359
 
1360
  /* Get ready for YARPP TIME! */
1361
  $this->active_cache->begin_yarpp_time($reference_ID, $args);
@@ -1558,14 +1556,9 @@ class YARPP {
1558
  /* If the content includes <!--noyarpp-->, don't display */
1559
  if (stristr($content, '<!--noyarpp-->') !== false) return $content;
1560
 
1561
- $post_types = $this->get_query_post_types();
1562
-
1563
- $post_types = apply_filters('yarpp_map_post_types', $post_types, 'rss');
1564
-
1565
  return $content.$this->display_related(
1566
  null,
1567
  array(
1568
- 'post_type' => $post_types,
1569
  'domain' => 'rss'
1570
  ),
1571
  false
@@ -1578,9 +1571,8 @@ class YARPP {
1578
  /* If the content includes <!--noyarpp-->, don't display */
1579
  if (stristr($content, '<!--noyarpp-->') !== false) return $content;
1580
 
1581
- $post_type = $this->get_query_post_types();
1582
-
1583
- return $content . $this->clean_pre($this->display_related(null, array('post_type' => $post_type, 'domain' => 'rss'), false));
1584
  }
1585
 
1586
  /*
118
  if (is_admin()) {
119
  require_once(YARPP_DIR.'/classes/YARPP_Admin.php');
120
  $this->admin = new YARPP_Admin($this);
121
+ if( ! defined('DOING_AJAX')){
122
+ $this->enforce();
123
+ }
124
  }
125
  $shortcode = new YARPP_Shortcode();
126
  $shortcode->register();
302
  }
303
 
304
  public function enabled() {
305
+ if ( ! (bool) $this->cache->is_enabled() ) {
306
+ return false;
307
+ } else {
308
+ return $this->diagnostic_fulltext_indices();
309
+ }
310
  }
311
 
312
  public function activate() {
313
  /*
314
  * If it's not known to be disabled, but the indexes aren't there.
315
  */
316
+ if ( !$this->diagnostic_fulltext_indices()) {
317
  $this->enable_fulltext();
318
  }
319
 
351
  return $engine;
352
  }
353
  }
354
+
355
+ /**
356
+ * @deprecated in 5.14.0 we just always enable fulltext indexes, or keep checking for it, so this should never need
357
+ * to be called.
358
+ * @return bool
359
+ */
360
  function diagnostic_fulltext_disabled() {
361
  return $this->db_options->is_fulltext_disabled();
362
  }
416
  /* cut threshold by half: */
417
  $threshold = (float) $this->get_option('threshold');
418
  $this->set_option(array('threshold' => round($threshold / 2)));
 
 
419
  }
420
 
421
  /*
423
  * @return bool
424
  */
425
  public function diagnostic_fulltext_indices() {
426
+ return $this->db_schema->title_column_has_index() && $this->db_schema->content_column_has_index();
 
 
427
  }
428
 
429
  public function diagnostic_hidden_metaboxes() {
920
  } else {
921
  $post_types = array(get_post_type($reference_ID));
922
  }
923
+ return apply_filters(
924
+ 'yarpp_map_post_types',
925
+ $post_types,
926
+ is_array($args) && isset($args['domain']) ? $args['domain'] : null
927
+ );
928
  }
929
 
930
  private function post_type_filter($post_type) {
1004
  ),
1005
  'diagnostics' => array(
1006
  'myisam_posts' => $this->diagnostic_myisam_posts(),
 
1007
  'fulltext_indices' => $this->diagnostic_fulltext_indices(),
1008
  'hidden_metaboxes' => $this->diagnostic_hidden_metaboxes(),
1009
  'post_thumbnails' => $this->diagnostic_post_thumbnails(),
1108
  return null;
1109
  }
1110
 
 
 
1111
  return $this->display_related(
1112
  null,
1113
  array(
 
1114
  'domain' => 'website'
1115
  ),
1116
  false
1152
  public function display_related($reference_ID = null, $args = array(), $echo = true) {
1153
  // Avoid infinite recursion here.
1154
  if ( $this->do_not_query_for_related()) return false;
 
 
1155
  wp_enqueue_style('yarppRelatedCss', plugins_url('/style/related.css', YARPP_MAIN_FILE));
1156
  $output = null;
1157
 
1283
  public function get_related($reference_ID = null, $args = array()) {
1284
  // Avoid infinite recursion here.
1285
  if ( $this->do_not_query_for_related()) return false;
 
1286
 
1287
 
1288
  if (is_numeric($reference_ID)) {
1302
  extract($this->parse_args($args, $options));
1303
 
1304
  $cache_status = $this->active_cache->enforce($reference_ID);
1305
+ if ( in_array($cache_status, array(YARPP_DONT_RUN, YARPP_NO_RELATED), true)) return array();
 
 
1306
 
1307
  /* Get ready for YARPP TIME! */
1308
  $this->active_cache->begin_yarpp_time($reference_ID, $args);
1338
  public function related_exist($reference_ID = null, $args = array()) {
1339
  // Avoid infinite recursion here.
1340
  if ($this->do_not_query_for_related()) return false;
 
1341
 
1342
  if (is_numeric($reference_ID)) {
1343
  $reference_ID = (int) $reference_ID;
1351
  $this->setup_active_cache($args);
1352
 
1353
  $cache_status = $this->active_cache->enforce($reference_ID);
1354
+
1355
+ if (in_array($cache_status, array(YARPP_DONT_RUN, YARPP_NO_RELATED), true)) return false;
1356
+
 
1357
 
1358
  /* Get ready for YARPP TIME! */
1359
  $this->active_cache->begin_yarpp_time($reference_ID, $args);
1556
  /* If the content includes <!--noyarpp-->, don't display */
1557
  if (stristr($content, '<!--noyarpp-->') !== false) return $content;
1558
 
 
 
 
 
1559
  return $content.$this->display_related(
1560
  null,
1561
  array(
 
1562
  'domain' => 'rss'
1563
  ),
1564
  false
1571
  /* If the content includes <!--noyarpp-->, don't display */
1572
  if (stristr($content, '<!--noyarpp-->') !== false) return $content;
1573
 
1574
+
1575
+ return $content . $this->clean_pre($this->display_related(null, array('domain' => 'rss'), false));
 
1576
  }
1577
 
1578
  /*
classes/YARPP_DB_Options.php CHANGED
@@ -48,7 +48,7 @@ class YARPP_DB_Options {
48
 
49
  /**
50
  * Gets whether fulltext indexes were not found to be supported.
51
- *
52
  * @return bool
53
  */
54
  public function is_fulltext_disabled() {
@@ -59,7 +59,7 @@ class YARPP_DB_Options {
59
  * Records that fulltext indexes weren't supported.
60
  *
61
  * @param boolean $new_value True if we found fulltext indexes were supported, false otherwise.
62
- *
63
  * @return bool indicating success
64
  */
65
  public function set_fulltext_disabled( $new_value ) {
48
 
49
  /**
50
  * Gets whether fulltext indexes were not found to be supported.
51
+ * @deprecated in 5.14.0 because we just always try to use fulltext indexes
52
  * @return bool
53
  */
54
  public function is_fulltext_disabled() {
59
  * Records that fulltext indexes weren't supported.
60
  *
61
  * @param boolean $new_value True if we found fulltext indexes were supported, false otherwise.
62
+ * @deprecated in 5.14.0 because we just check the actual DB instead
63
  * @return bool indicating success
64
  */
65
  public function set_fulltext_disabled( $new_value ) {
classes/YARPP_DB_Schema.php CHANGED
@@ -13,6 +13,7 @@ class YARPP_DB_Schema {
13
  const CACHE_KEY_FULLTEXT_SUPPORT = 'fulltext_support';
14
  const CACHE_KEY_POSTS_TABLE_DATABASE_ENGINE = 'posts_table_database_engine';
15
  const CACHE_GROUP = 'yarpp';
 
16
  /**
17
  * Checks if there is an index for the post title column
18
  *
@@ -126,4 +127,47 @@ class YARPP_DB_Schema {
126
 
127
  return empty( $wpdb->last_error );
128
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  }
13
  const CACHE_KEY_FULLTEXT_SUPPORT = 'fulltext_support';
14
  const CACHE_KEY_POSTS_TABLE_DATABASE_ENGINE = 'posts_table_database_engine';
15
  const CACHE_GROUP = 'yarpp';
16
+ const CACHE_KEY_TABLE_EXISTS = 'table_exists';
17
  /**
18
  * Checks if there is an index for the post title column
19
  *
127
 
128
  return empty( $wpdb->last_error );
129
  }
130
+
131
+ /**
132
+ * Finds out if the YARPP cache table was created or not
133
+ * @return bool
134
+ */
135
+ public function cache_table_exists(){
136
+ $exists = wp_cache_get(self::CACHE_KEY_TABLE_EXISTS, self::CACHE_GROUP, false, $found);
137
+ if( ! $found ){
138
+ global $wpdb;
139
+ // now check for the cache tables
140
+ $tabledata = $wpdb->get_col('SHOW TABLES LIKE "'. $wpdb->prefix . YARPP_TABLES_RELATED_TABLE . '"');
141
+ if (in_array($wpdb->prefix . YARPP_TABLES_RELATED_TABLE,$tabledata) !== false)
142
+ $exists = true;
143
+ else
144
+ $exists = false;
145
+ wp_cache_set(self::CACHE_KEY_TABLE_EXISTS, $exists, self::CACHE_GROUP);
146
+ }
147
+ return $exists;
148
+ }
149
+
150
+ /**
151
+ * Create the YARPP cache table
152
+ */
153
+ public function create_cache_table(){
154
+ global $wpdb;
155
+
156
+ $charset_collate = '';
157
+ if (!empty($wpdb->charset)) $charset_collate = "DEFAULT CHARACTER SET ".$wpdb->charset;
158
+ if (!empty($wpdb->collate)) $charset_collate .= " COLLATE ".$wpdb->collate;
159
+
160
+ $wpdb->query(
161
+ "CREATE TABLE IF NOT EXISTS `".$wpdb->prefix.YARPP_TABLES_RELATED_TABLE."` (
162
+ `reference_ID` bigint(20) unsigned NOT NULL default '0',
163
+ `ID` bigint(20) unsigned NOT NULL default '0',
164
+ `score` float unsigned NOT NULL default '0',
165
+ `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
166
+ PRIMARY KEY (`reference_ID`,`ID`),
167
+ INDEX (`score`),
168
+ INDEX (`ID`)
169
+ )$charset_collate;"
170
+ );
171
+ wp_cache_delete(self::CACHE_KEY_TABLE_EXISTS, self::CACHE_GROUP);
172
+ }
173
  }
classes/YARPP_Meta_Box.php CHANGED
@@ -2,6 +2,9 @@
2
 
3
  class YARPP_Meta_Box {
4
  protected $template_text = null;
 
 
 
5
  protected $yarpp = null;
6
 
7
  public function __construct() {
@@ -70,7 +73,7 @@ class YARPP_Meta_Box {
70
  $weight = (int) yarpp_get_option("weight[$option]");
71
 
72
  /* Both require MyISAM fulltext indexing: */
73
- $fulltext = $this->yarpp->diagnostic_fulltext_disabled() ? ' readonly="readonly" disabled="disabled"' : '';
74
 
75
  echo "<div class='yarpp_form_row yarpp_form_select'><div class='yarpp_form_label'>{$desc}</div><div>";
76
  echo "<select name='weight[{$option}]'>";
2
 
3
  class YARPP_Meta_Box {
4
  protected $template_text = null;
5
+ /**
6
+ * @var YARPP
7
+ */
8
  protected $yarpp = null;
9
 
10
  public function __construct() {
73
  $weight = (int) yarpp_get_option("weight[$option]");
74
 
75
  /* Both require MyISAM fulltext indexing: */
76
+ $fulltext = $this->yarpp->diagnostic_fulltext_indices() ? '' : ' readonly="readonly" disabled="disabled"';
77
 
78
  echo "<div class='yarpp_form_row yarpp_form_select'><div class='yarpp_form_label'>{$desc}</div><div>";
79
  echo "<select name='weight[{$option}]'>";
classes/YARPP_Meta_Box_Relatedness.php CHANGED
@@ -23,9 +23,7 @@ class YARPP_Meta_Box_Relatedness extends YARPP_Meta_Box {
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
23
  */
24
  protected function disabled_warning(){
25
  global $yarpp, $wpdb;
26
+ if ( $yarpp->db_schema->database_supports_fulltext_indexes() && ! $yarpp->diagnostic_fulltext_indices()) {
 
 
27
  ?>
28
  <div class='yarpp-callout yarpp-notice'>
29
  <p><?php
includes/yarpp_myisam_notice.php CHANGED
@@ -8,8 +8,6 @@ if (isset($_POST['myisam_override'])) {
8
  $enabled = $yarpp->enable_fulltext();
9
 
10
  if($enabled){
11
-
12
- $yarpp->db_options->set_fulltext_disabled(false);
13
  ?>
14
  <div class="notice notice-success">
15
  <?php
8
  $enabled = $yarpp->enable_fulltext();
9
 
10
  if($enabled){
 
 
11
  ?>
12
  <div class="notice notice-success">
13
  <?php
includes/yarpp_options.php CHANGED
@@ -1,9 +1,6 @@
1
  <?php
2
  global $wpdb, $wp_version, $yarpp;
3
 
4
- /* Enforce YARPP setup: */
5
- $yarpp->enforce();
6
-
7
  if(!$yarpp->enabled() && !$yarpp->activate()) {
8
  echo '<div class="updated">'.__('The YARPP database has an error which could not be fixed.','yarpp').'</div>';
9
  }
1
  <?php
2
  global $wpdb, $wp_version, $yarpp;
3
 
 
 
 
4
  if(!$yarpp->enabled() && !$yarpp->activate()) {
5
  echo '<div class="updated">'.__('The YARPP database has an error which could not be fixed.','yarpp').'</div>';
6
  }
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.6
8
- Stable tag: 5.13.0
9
 
10
  The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
11
 
@@ -309,9 +309,15 @@ add_action(
309
  `
310
 
311
  == Changelog ==
 
 
 
 
 
 
312
  = 5.13.0 (1-March-2021) =
313
  * New: Clear YARPP cache button on settings page
314
- * [Bugfix])(https://wordpress.org/support/topic/undefined-variable-post_types/) Undefined variable ``$post_types`
315
 
316
  = 5.12.0 (22-February-2021) =
317
  * New shortcode template attribute. Eg `[yarpp template="yarpp-template-photoblog"]`
@@ -1085,5 +1091,5 @@ After a break of many years, the plugin is 100% supported now that the baton has
1085
  * Initial upload
1086
 
1087
  == Upgrade Notice ==
1088
- = 5.13.0 =
1089
  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.6
8
+ Stable tag: 5.14.0
9
 
10
  The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
11
 
309
  `
310
 
311
  == Changelog ==
312
+ = 5.14.0 (9-March-2021) =
313
+ * Enhancement: Improve pageload speed by avoiding checking YARPP database requirements on frontend requests
314
+
315
+ = 5.13.1 (1-March-2021) =
316
+ * Add some of 5.13.0's changes that somehow weren't included
317
+
318
  = 5.13.0 (1-March-2021) =
319
  * New: Clear YARPP cache button on settings page
320
+ * [Bugfix](https://wordpress.org/support/topic/undefined-variable-post_types/) Undefined variable ``$post_types`
321
 
322
  = 5.12.0 (22-February-2021) =
323
  * New shortcode template attribute. Eg `[yarpp template="yarpp-template-photoblog"]`
1091
  * Initial upload
1092
 
1093
  == Upgrade Notice ==
1094
+ = 5.14.0 =
1095
  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.13.0
6
  Author: YARPP
7
  Author URI: https://yarpp.com/
8
  Plugin URI: https://yarpp.com/
@@ -24,7 +24,7 @@ if(!defined('WP_CONTENT_DIR')){
24
  define('WP_CONTENT_DIR', substr($tr,0,strrpos($tr,'/')));
25
  }
26
 
27
- define('YARPP_VERSION', '5.13.0');
28
 
29
  define('YARPP_DIR', dirname(__FILE__));
30
  /**
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.14.0
6
  Author: YARPP
7
  Author URI: https://yarpp.com/
8
  Plugin URI: https://yarpp.com/
24
  define('WP_CONTENT_DIR', substr($tr,0,strrpos($tr,'/')));
25
  }
26
 
27
+ define('YARPP_VERSION', '5.14.0');
28
 
29
  define('YARPP_DIR', dirname(__FILE__));
30
  /**