Related Posts for WordPress - Version 2.0.3

Version Description

Download this release

Release Info

Developer barrykooij
Plugin Icon 128x128 Related Posts for WordPress
Version 2.0.3
Comparing to
See all releases

Code changes from version 2.0.2 to 2.0.3

classes/class-related-word-manager.php CHANGED
@@ -164,9 +164,6 @@ class RP4WP_Related_Word_Manager {
164
  // Remove the <!--more--> tag
165
  $content = str_ireplace( '<!--more-->', '', $content );
166
 
167
- // Remove everything but letters and numbers
168
- $content = preg_replace( '/[^a-z0-9]+/i', ' ', $content );
169
-
170
  // UTF8 fix content
171
  $content = $this->convert_characters( $content );
172
 
@@ -223,6 +220,8 @@ class RP4WP_Related_Word_Manager {
223
  $string = html_entity_decode( preg_replace( '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~iS', '$1', $string ), ENT_QUOTES, 'UTF-8' );
224
  }
225
 
 
 
226
 
227
  // Return string
228
  return $string;
@@ -284,7 +283,7 @@ class RP4WP_Related_Word_Manager {
284
  foreach ( $raw_words as $word ) {
285
 
286
  // Trim word
287
- $word = strtolower( trim( $word ) );
288
 
289
  // Only use words longer than 1 character
290
  if ( strlen( $word ) < 2 ) {
@@ -306,19 +305,30 @@ class RP4WP_Related_Word_Manager {
306
  }
307
  }
308
 
309
- $new_words = array();
 
 
 
 
 
 
310
  $total_raw_words = count( $raw_words );
311
- $length_weight = 0.6;
312
 
313
- foreach ( $words as $word => $amount ) {
 
314
 
315
- if ( $amount < 3 ) {
316
- continue; // Don't add words that occur less than 3 times
317
- }
318
 
319
- // Add word and turn amount into weight (make it relative)
320
- $new_words[$word] = ( $amount / ( $length_weight * $total_raw_words ) );
321
 
 
 
 
 
 
322
  }
323
 
324
  return $new_words;
164
  // Remove the <!--more--> tag
165
  $content = str_ireplace( '<!--more-->', '', $content );
166
 
 
 
 
167
  // UTF8 fix content
168
  $content = $this->convert_characters( $content );
169
 
220
  $string = html_entity_decode( preg_replace( '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~iS', '$1', $string ), ENT_QUOTES, 'UTF-8' );
221
  }
222
 
223
+ // Remove characters that are on our 'blacklist'
224
+ $string = preg_replace( '/[;:\'\"\[\]\-\_=\+\.,\/\\<>`~\(\)\!@#$%\^&\*\?\|]+/i', ' ', $string );
225
 
226
  // Return string
227
  return $string;
283
  foreach ( $raw_words as $word ) {
284
 
285
  // Trim word
286
+ $word = mb_strtolower( trim( $word ) );
287
 
288
  // Only use words longer than 1 character
289
  if ( strlen( $word ) < 2 ) {
305
  }
306
  }
307
 
308
+ // reverse sort, most important words at top
309
+ arsort( $words );
310
+
311
+ // store new words
312
+ $new_words = array();
313
+
314
+ // count total 'raw' words
315
  $total_raw_words = count( $raw_words );
 
316
 
317
+ // count words added
318
+ $words_added = 0;
319
 
320
+ $cache_word_amount = apply_filters( 'rp4wp_cache_word_amount', 6 );
321
+
322
+ foreach ( $words as $word => $amount ) {
323
 
324
+ // add word to new words with relative weight
325
+ $new_words[ $word ] = ( $amount / $total_raw_words );
326
 
327
+ // we only add 6 most important words, filterable via 'rp4wp_cache_word_amount'
328
+ $words_added ++;
329
+ if ( $words_added >= $cache_word_amount ) {
330
+ break;
331
+ }
332
  }
333
 
334
  return $new_words;
classes/class-rp4wp.php CHANGED
@@ -8,7 +8,7 @@ class RP4WP {
8
 
9
  private static $instance = null;
10
 
11
- const VERSION = '2.0.2';
12
 
13
  /**
14
  * @var RP4WP_Settings
8
 
9
  private static $instance = null;
10
 
11
+ const VERSION = '2.0.3';
12
 
13
  /**
14
  * @var RP4WP_Settings
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: never5, barrykooij, hchouhan
3
  Donate link: http://www.barrykooij.com/donate/
4
  Tags: related posts for wordpress, related posts for wp, simple related posts, easy related posts, related posts, related post, related, relations, internal links, seo, bounce rate
5
  Requires at least: 3.6
6
- Tested up to: 4.9
7
- Stable tag: 2.0.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -118,6 +118,12 @@ There is one custom table created for the post cache, this table will however no
118
 
119
  == Changelog ==
120
 
 
 
 
 
 
 
121
  = 2.0.2: October 10, 2017 =
122
  * Tweak: Fixed an issue where sticky posts were always included in related posts.
123
  * Tweak: Removed a post type check since post type is always post.
3
  Donate link: http://www.barrykooij.com/donate/
4
  Tags: related posts for wordpress, related posts for wp, simple related posts, easy related posts, related posts, related post, related, relations, internal links, seo, bounce rate
5
  Requires at least: 3.6
6
+ Tested up to: 4.9.4
7
+ Stable tag: 2.0.3
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
118
 
119
  == Changelog ==
120
 
121
+ = 2.0.3: March 2, 2018 =
122
+ * Tweak: Removed hard removal of non a-z0-9 characters because this removes all non-latin chars causing issues for non-latin languages. Instead we're now using a specific blacklist of characters that needs to be removed. Also moved this to convert_characters so we apply this blacklist also to title,taxonomy,etc.
123
+ * Tweak: Made case lowering of words in cache UTF-8 compatible, solving an issue with non-latin characters.
124
+ * Tweak: We no longer cache all words but only the top 6. This greatly improves performance of the caching task.
125
+ * Tweak: Added filter 'rp4wp_cache_word_amount' to filter amount of words added in cache (default=6).
126
+
127
  = 2.0.2: October 10, 2017 =
128
  * Tweak: Fixed an issue where sticky posts were always included in related posts.
129
  * Tweak: Removed a post type check since post type is always post.
related-posts-for-wp.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Related Posts for WordPress
4
  Plugin URI: http://www.relatedpostsforwp.com/
5
  Description: Related Posts for WordPress, the best way to display related posts in WordPress.
6
- Version: 2.0.2
7
  Author: Never5
8
  Author URI: http://www.never5.com/
9
  License: GPL v3
3
  Plugin Name: Related Posts for WordPress
4
  Plugin URI: http://www.relatedpostsforwp.com/
5
  Description: Related Posts for WordPress, the best way to display related posts in WordPress.
6
+ Version: 2.0.3
7
  Author: Never5
8
  Author URI: http://www.never5.com/
9
  License: GPL v3