Yet Another Related Posts Plugin (YARPP) - Version 5.1.7

Version Description

(2020-06-17) = * Bugfix Double-check database indexes exist before creating them * Bugfix: Titles were only being considered if body text was also considered for the relatedness algorithm. This update fixes the logic to work where only titles are set to be considered. * Bugfix: Do not dismiss deactivation modal when clicking outside it

Download this release

Release Info

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

Code changes from version 5.1.6 to 5.1.7

classes/YARPP_Cache.php CHANGED
@@ -163,18 +163,21 @@ abstract class YARPP_Cache {
163
 
164
  // SELECT
165
  $newsql = "SELECT $reference_ID as reference_ID, ID, "; //post_title, post_date, post_content, post_excerpt,
166
-
167
  $newsql .= 'ROUND(0';
168
- if (isset($weight['body']) && isset($weight['body']) && (int) $weight['body']) {
169
- $newsql .= " + (MATCH (post_content) AGAINST ('".esc_sql($keywords['body'])."')) * ".absint($weight['body']);
170
- }
171
- if (isset($weight['body']) && isset($weight['title']) && (int) $weight['title']) {
172
- $newsql .= " + (MATCH (post_title) AGAINST ('".esc_sql($keywords['title'])."')) * ".absint($weight['title']);
173
- }
174
-
175
- // Build tax criteria query parts based on the weights
176
- foreach ((array) $weight['tax'] as $tax => $tax_weight) {
177
- $newsql .= " + ".$this->tax_criteria($reference_ID, $tax)." * ".intval($tax_weight);
 
 
 
 
178
  }
179
 
180
  $newsql .= ',1) as score';
@@ -182,7 +185,7 @@ abstract class YARPP_Cache {
182
  $newsql .= "\n from $wpdb->posts \n";
183
 
184
  $exclude_tt_ids = wp_parse_id_list($exclude);
185
- if (count($exclude_tt_ids) || count((array) $weight['tax']) || count($require_tax)) {
186
  $newsql .= "left join $wpdb->term_relationships as terms on ( terms.object_id = $wpdb->posts.ID ) \n";
187
  }
188
 
163
 
164
  // SELECT
165
  $newsql = "SELECT $reference_ID as reference_ID, ID, "; //post_title, post_date, post_content, post_excerpt,
 
166
  $newsql .= 'ROUND(0';
167
+ if (isset($weight) && is_array($weight)){
168
+ if (isset($weight['body']) && (int) $weight['body']) {
169
+ $newsql .= " + (MATCH (post_content) AGAINST ('".esc_sql($keywords['body'])."')) * ".absint($weight['body']);
170
+ }
171
+ if (isset($weight['title']) && (int) $weight['title']) {
172
+ $newsql .= " + (MATCH (post_title) AGAINST ('".esc_sql($keywords['title'])."')) * ".absint($weight['title']);
173
+ }
174
+
175
+ // Build tax criteria query parts based on the weights
176
+ if(isset($weight['tax']) && is_array($weight['tax'])){
177
+ foreach ((array) $weight['tax'] as $tax => $tax_weight) {
178
+ $newsql .= " + ".$this->tax_criteria($reference_ID, $tax)." * ".intval($tax_weight);
179
+ }
180
+ }
181
  }
182
 
183
  $newsql .= ',1) as score';
185
  $newsql .= "\n from $wpdb->posts \n";
186
 
187
  $exclude_tt_ids = wp_parse_id_list($exclude);
188
+ if (count($exclude_tt_ids) || (isset($weight) && isset($weight['tax']) && count((array) $weight['tax'])) || count($require_tax)) {
189
  $newsql .= "left join $wpdb->term_relationships as terms on ( terms.object_id = $wpdb->posts.ID ) \n";
190
  }
191
 
classes/YARPP_Core.php CHANGED
@@ -18,6 +18,10 @@ class YARPP {
18
  public $cache_bypass;
19
  public $cache;
20
  public $admin;
 
 
 
 
21
 
22
  private $active_cache;
23
  private $storage_class;
@@ -37,9 +41,10 @@ class YARPP {
37
  load_plugin_textdomain('yarpp', false, plugin_basename(YARPP_DIR).'/lang');
38
 
39
  /* Load cache object. */
40
- $this->storage_class = 'YARPP_Cache_'.ucfirst(YARPP_CACHE_TYPE);
41
- $this->cache = new $this->storage_class($this);
42
- $this->cache_bypass = new YARPP_Cache_Bypass($this);
 
43
 
44
  register_activation_hook(__FILE__, array($this, 'activate'));
45
 
@@ -326,18 +331,23 @@ class YARPP {
326
 
327
  /* Temporarily ensure that errors are not displayed: */
328
  $previous_value = $wpdb->hide_errors();
 
 
 
 
329
 
330
- $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` (`post_title`)");
331
- if (!empty($wpdb->last_error)){
332
- $this->disable_fulltext();
333
- return false;
334
- }
 
 
 
 
 
 
335
 
336
- $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` (`post_content`)");
337
- if (!empty($wpdb->last_error)){
338
- $this->disable_fulltext();
339
- return false;
340
- }
341
 
342
  /* Restore previous setting */
343
  $wpdb->show_errors($previous_value);
18
  public $cache_bypass;
19
  public $cache;
20
  public $admin;
21
+ /**
22
+ * @var YARPP_DB_Schema
23
+ */
24
+ public $db_schema;
25
 
26
  private $active_cache;
27
  private $storage_class;
41
  load_plugin_textdomain('yarpp', false, plugin_basename(YARPP_DIR).'/lang');
42
 
43
  /* Load cache object. */
44
+ $this->storage_class = 'YARPP_Cache_'.ucfirst(YARPP_CACHE_TYPE);
45
+ $this->cache = new $this->storage_class($this);
46
+ $this->cache_bypass = new YARPP_Cache_Bypass($this);
47
+ $this->db_schema = new YARPP_DB_Schema();
48
 
49
  register_activation_hook(__FILE__, array($this, 'activate'));
50
 
331
 
332
  /* Temporarily ensure that errors are not displayed: */
333
  $previous_value = $wpdb->hide_errors();
334
+ if(! $this->db_schema->title_column_has_index()) {
335
+ $wpdb->query( "ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` (`post_title`)" );
336
+ if ( ! empty( $wpdb->last_error ) ) {
337
+ $this->disable_fulltext();
338
 
339
+ return false;
340
+ }
341
+ }
342
+
343
+ if(! $this->db_schema->content_column_has_index()){
344
+ $wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` (`post_content`)");
345
+ if (!empty($wpdb->last_error)){
346
+ $this->disable_fulltext();
347
+ return false;
348
+ }
349
+ }
350
 
 
 
 
 
 
351
 
352
  /* Restore previous setting */
353
  $wpdb->show_errors($previous_value);
classes/YARPP_DB_Schema.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class YARPP_DB_Schema
5
+ * Class for database schema inspection and changes.
6
+ *
7
+ * @package YARPP
8
+ * @author Mike Nelson
9
+ * @since 5.1.7
10
+ */
11
+ class YARPP_DB_Schema {
12
+
13
+
14
+ /**
15
+ * Checks if there is an index for the post title column
16
+ *
17
+ * @return bool
18
+ */
19
+ public function title_column_has_index() {
20
+ global $wpdb;
21
+ // Disable a few inspections because this method is only called once on a very specific request.
22
+ // phpcs:disable WordPress.VIP.DirectDatabaseQuery.DirectQuery
23
+ // phpcs:disable WordPress.VIP.DirectDatabaseQuery.NoCaching
24
+ $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} WHERE Key_name = 'yarpp_title'" );
25
+ // phpcs:enable WordPress.VIP.DirectDatabaseQuery.DirectQuery
26
+ // phpcs:enable WordPress.VIP.DirectDatabaseQuery.NoCaching
27
+ return ( $wpdb->num_rows >= 1 );
28
+ }
29
+
30
+ /**
31
+ * Checks if there is an index for the post content column
32
+ *
33
+ * @return bool
34
+ */
35
+ public function content_column_has_index() {
36
+ global $wpdb;
37
+ // Disable a few inspections because this method is only called once on a very specific request.
38
+ //phpcs:disable WordPress.VIP.DirectDatabaseQuery.DirectQuery
39
+ //phpcs:disable WordPress.VIP.DirectDatabaseQuery.NoCaching
40
+ $wpdb->get_results( "SHOW INDEX FROM {$wpdb->posts} WHERE Key_name = 'yarpp_content'" );
41
+ //phpcs:enable WordPress.VIP.DirectDatabaseQuery.DirectQuery
42
+ //phpcs:enable WordPress.VIP.DirectDatabaseQuery.NoCaching
43
+ return ( $wpdb->num_rows >= 1 );
44
+ }
45
+ }
lib/plugin-deactivation-survey/deactivate-feedback-form.js CHANGED
@@ -135,7 +135,7 @@
135
  this.deactivateURL = event.target.href;
136
 
137
  if ( ! this.dialog) {
138
- this.dialog = $( this.element ).remodal();
139
  }
140
  this.dialog.open();
141
  event.preventDefault();
@@ -148,7 +148,8 @@
148
  var data = this.plugin.send;
149
  data.survey_response = {
150
  contact:{
151
- email: $( element ).find( "input[name='email']" ).val().trim().toLowerCase()
 
152
  },
153
  type:'uninstall',
154
  data:{
135
  this.deactivateURL = event.target.href;
136
 
137
  if ( ! this.dialog) {
138
+ this.dialog = $( this.element ).remodal({closeOnOutsideClick:false});
139
  }
140
  this.dialog.open();
141
  event.preventDefault();
148
  var data = this.plugin.send;
149
  data.survey_response = {
150
  contact:{
151
+ email: $( element ).find( "input[name='email']" ).val().trim().toLowerCase(),
152
+ role: this.plugin.role || null
153
  },
154
  type:'uninstall',
155
  data:{
lib/plugin-deactivation-survey/deactivate-feedback-form.php CHANGED
@@ -32,8 +32,8 @@ if ( ! function_exists( 'shareaholic_deactivate_feedback' ) ) {
32
  return;
33
  }
34
 
35
- if ( $plugins[0] && $plugins[0]->script_cache_ver ) {
36
- $script_cache_ver = $plugins[0]->script_cache_ver;
37
  } else {
38
  $script_cache_ver = '1.1.1';
39
  }
@@ -58,14 +58,19 @@ if ( ! function_exists( 'shareaholic_deactivate_feedback' ) ) {
58
  );
59
 
60
  $current_user = wp_get_current_user();
61
- if ( $current_user instanceof WP_User && $current_user->ID ) {
62
  $email = $current_user->user_email;
 
 
 
63
  } else {
64
  $email = '';
 
65
  }
66
 
67
  foreach ( $plugins as $plugin ) {
68
  $plugin->email = $email;
 
69
  }
70
 
71
  // Send plugin data.
32
  return;
33
  }
34
 
35
+ if ( is_array( $plugins ) && end( $plugins )->script_cache_ver ) {
36
+ $script_cache_ver = end( $plugins )->script_cache_ver;
37
  } else {
38
  $script_cache_ver = '1.1.1';
39
  }
58
  );
59
 
60
  $current_user = wp_get_current_user();
61
+ if ( $current_user instanceof WP_User && is_user_logged_in() && $current_user->ID ) {
62
  $email = $current_user->user_email;
63
+ if ( $current_user->roles[0] ) {
64
+ $role = $current_user->roles[0];
65
+ }
66
  } else {
67
  $email = '';
68
+ $role = '';
69
  }
70
 
71
  foreach ( $plugins as $plugin ) {
72
  $plugin->email = $email;
73
+ $plugin->role = $role;
74
  }
75
 
76
  // Send plugin data.
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.4
8
- Stable tag: 5.1.6
9
 
10
  Display a list of related posts on your site based on a powerful unique algorithm. Optionally, earn money by including sponsored content.
11
 
@@ -262,6 +262,11 @@ add_action(
262
  `
263
 
264
  == Changelog ==
 
 
 
 
 
265
  = 5.1.6 (2020-05-15) =
266
  * [Bugfix](https://wordpress.org/support/topic/403-when-saving-changes/): 403 error when saving changes resolved
267
  * Enhancement: Feedback form enhancements
@@ -935,6 +940,6 @@ After a break of many years, the plugin is 100% supported now that the baton has
935
  * Initial upload
936
 
937
  == Upgrade Notice ==
938
- = 5.1.6 =
939
  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!
940
 
5
  Requires PHP: 5.3
6
  License: GPLv2 or later
7
  Tested up to: 5.4
8
+ Stable tag: 5.1.7
9
 
10
  Display a list of related posts on your site based on a powerful unique algorithm. Optionally, earn money by including sponsored content.
11
 
262
  `
263
 
264
  == Changelog ==
265
+ = 5.1.7 (2020-06-17) =
266
+ * [Bugfix](https://wordpress.org/support/topic/cant-use-indexing/) Double-check database indexes exist before creating them
267
+ * Bugfix: Titles were only being considered if body text was also considered for the relatedness algorithm. This update fixes the logic to work where only titles are set to be considered.
268
+ * [Bugfix](https://wordpress.org/support/topic/wont-let-me-deactivate-or-delete-plugin/): Do not dismiss deactivation modal when clicking outside it
269
+
270
  = 5.1.6 (2020-05-15) =
271
  * [Bugfix](https://wordpress.org/support/topic/403-when-saving-changes/): 403 error when saving changes resolved
272
  * Enhancement: Feedback form enhancements
940
  * Initial upload
941
 
942
  == Upgrade Notice ==
943
+ = 5.1.7 =
944
  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!
945
 
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.1.6
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.1.6');
27
 
28
  define('YARPP_DIR', dirname(__FILE__));
29
  define('YARPP_URL', plugins_url('',__FILE__));
@@ -70,6 +70,7 @@ include_once(YARPP_DIR.'/classes/YARPP_Cache.php');
70
  include_once(YARPP_DIR.'/classes/YARPP_Cache_Bypass.php');
71
  include_once(YARPP_DIR.'/classes/YARPP_Cache_'.ucfirst(YARPP_CACHE_TYPE).'.php');
72
  include_once( YARPP_DIR . '/lib/plugin-deactivation-survey/deactivate-feedback-form.php' );
 
73
 
74
  /* WP hooks ----------------------------------------------------------------------------------------------------------*/
75
  add_action('init', 'yarpp_init');
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.1.7
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.1.7');
27
 
28
  define('YARPP_DIR', dirname(__FILE__));
29
  define('YARPP_URL', plugins_url('',__FILE__));
70
  include_once(YARPP_DIR.'/classes/YARPP_Cache_Bypass.php');
71
  include_once(YARPP_DIR.'/classes/YARPP_Cache_'.ucfirst(YARPP_CACHE_TYPE).'.php');
72
  include_once( YARPP_DIR . '/lib/plugin-deactivation-survey/deactivate-feedback-form.php' );
73
+ include_once(YARPP_DIR.'/classes/YARPP_DB_Schema.php');
74
 
75
  /* WP hooks ----------------------------------------------------------------------------------------------------------*/
76
  add_action('init', 'yarpp_init');