Yet Another Related Posts Plugin (YARPP) - Version 3.5.3b1

Version Description

Download this release

Release Info

Developer mitchoyoshitaka
Plugin Icon 128x128 Yet Another Related Posts Plugin (YARPP)
Version 3.5.3b1
Comparing to
See all releases

Code changes from version 3.5.2 to 3.5.3b1

Files changed (6) hide show
  1. cache-postmeta.php +6 -6
  2. cache-tables.php +15 -11
  3. class-cache.php +6 -6
  4. class-core.php +2 -2
  5. readme.txt +6 -0
  6. yarpp.php +2 -2
cache-postmeta.php CHANGED
@@ -139,14 +139,14 @@ class YARPP_Cache_Postmeta extends YARPP_Cache {
139
return YARPP_RELATED;
140
}
141
142
- public function clear($reference_ID) {
143
- if (is_int($reference_ID))
144
- $reference_ID = array($reference_ID);
145
- // make sure that we have a non-trivial array
146
- if (!is_array($reference_ID) || !count($reference_ID))
147
return;
148
// clear each cache
149
- foreach($reference_ID as $id) {
150
delete_post_meta( $id, YARPP_POSTMETA_RELATED_KEY );
151
delete_post_meta( $id, YARPP_POSTMETA_KEYWORDS_KEY );
152
}
139
return YARPP_RELATED;
140
}
141
142
+ public function clear( $reference_IDs ) {
143
+ $reference_IDs = wp_parse_id_list( $reference_IDs );
144
+
145
+ if ( !count($reference_ID) )
146
return;
147
+
148
// clear each cache
149
+ foreach( $reference_IDs as $id ) {
150
delete_post_meta( $id, YARPP_POSTMETA_RELATED_KEY );
151
delete_post_meta( $id, YARPP_POSTMETA_KEYWORDS_KEY );
152
}
cache-tables.php CHANGED
@@ -28,13 +28,20 @@ class YARPP_Cache_Tables extends YARPP_Cache {
28
29
public function setup() {
30
global $wpdb;
31
$wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . "` (
32
`ID` bigint(20) unsigned NOT NULL default '0',
33
`body` text NOT NULL,
34
`title` text NOT NULL,
35
`date` timestamp NOT NULL default CURRENT_TIMESTAMP,
36
PRIMARY KEY (`ID`)
37
- ) ENGINE=MyISAM COMMENT='YARPP''s keyword cache table';");
38
$wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . "` (
39
`reference_ID` bigint(20) unsigned NOT NULL default '0',
40
`ID` bigint(20) unsigned NOT NULL default '0',
@@ -42,7 +49,7 @@ class YARPP_Cache_Tables extends YARPP_Cache {
42
`date` timestamp NOT NULL default CURRENT_TIMESTAMP,
43
PRIMARY KEY ( `reference_ID` , `ID` ),
44
INDEX (`score`), INDEX (`ID`)
45
- ) ENGINE=MyISAM;");
46
}
47
48
public function upgrade($last_version) {
@@ -176,22 +183,19 @@ class YARPP_Cache_Tables extends YARPP_Cache {
176
return $result;
177
}
178
179
- public function clear($reference_ID) {
180
global $wpdb;
181
182
- // everything is an array now:
183
- if ( !is_array($reference_ID) )
184
- $reference_ID = array( $reference_ID );
185
186
- if ( !count($reference_ID) )
187
return;
188
189
- $wpdb->query("delete from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID in (".implode(',',$reference_ID).")");
190
- $wpdb->query("delete from {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " where ID in (".implode(',',$reference_ID).")");
191
// @since 3.5.2: clear is_cached_* values as well
192
- foreach ( $reference_ID as $id ) {
193
wp_cache_delete( 'is_cached_' . $id, 'yarpp' );
194
- }
195
}
196
197
// @return YARPP_RELATED | YARPP_NO_RELATED | YARPP_NOT_CACHED
28
29
public function setup() {
30
global $wpdb;
31
+
32
+ $charset_collate = '';
33
+ if ( ! empty( $wpdb->charset ) )
34
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
35
+ if ( ! empty( $wpdb->collate ) )
36
+ $charset_collate .= " COLLATE $wpdb->collate";
37
+
38
$wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . "` (
39
`ID` bigint(20) unsigned NOT NULL default '0',
40
`body` text NOT NULL,
41
`title` text NOT NULL,
42
`date` timestamp NOT NULL default CURRENT_TIMESTAMP,
43
PRIMARY KEY (`ID`)
44
+ ) $charset_collate;");
45
$wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . "` (
46
`reference_ID` bigint(20) unsigned NOT NULL default '0',
47
`ID` bigint(20) unsigned NOT NULL default '0',
49
`date` timestamp NOT NULL default CURRENT_TIMESTAMP,
50
PRIMARY KEY ( `reference_ID` , `ID` ),
51
INDEX (`score`), INDEX (`ID`)
52
+ ) $charset_collate;");
53
}
54
55
public function upgrade($last_version) {
183
return $result;
184
}
185
186
+ public function clear( $reference_IDs ) {
187
global $wpdb;
188
189
+ $reference_IDs = wp_parse_id_list( $reference_ID );
190
191
+ if ( !count($reference_IDs) )
192
return;
193
194
+ $wpdb->query("delete from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID in (".implode(',',$reference_IDs).")");
195
+ $wpdb->query("delete from {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " where ID in (".implode(',',$reference_IDs).")");
196
// @since 3.5.2: clear is_cached_* values as well
197
+ foreach ( $reference_IDs as $id )
198
wp_cache_delete( 'is_cached_' . $id, 'yarpp' );
199
}
200
201
// @return YARPP_RELATED | YARPP_NO_RELATED | YARPP_NOT_CACHED
class-cache.php CHANGED
@@ -77,7 +77,7 @@ abstract class YARPP_Cache {
77
* POST STATUS INTERACTIONS
78
*/
79
80
- function save_post($post_ID) {
81
global $wpdb;
82
83
// @since 3.2: don't compute cache during import
@@ -91,18 +91,18 @@ abstract class YARPP_Cache {
91
92
// Clear the cache for this entry and for all posts which are "related" to it.
93
// New in 3.2: This is called when a post is deleted.
94
- function delete_post($post_ID) {
95
// Clear the cache for this post.
96
- $this->clear($post_ID);
97
98
// Find all "peers" which list this post as a related post.
99
- $peers = $this->related(null, $post_ID);
100
// Clear the peers' caches.
101
$this->clear($peers);
102
}
103
104
// New in 3.2.1: handle various post_status transitions
105
- function transition_post_status($new_status, $old_status, $post) {
106
switch ($new_status) {
107
case "draft":
108
$this->delete_post($post->ID);
@@ -115,7 +115,7 @@ abstract class YARPP_Cache {
115
}
116
}
117
118
- function set_score_override_flag($q) {
119
if ( $this->is_yarpp_time() ) {
120
$this->score_override = ($q->query_vars['orderby'] == 'score');
121
77
* POST STATUS INTERACTIONS
78
*/
79
80
+ function save_post( $post_ID, $post ) {
81
global $wpdb;
82
83
// @since 3.2: don't compute cache during import
91
92
// Clear the cache for this entry and for all posts which are "related" to it.
93
// New in 3.2: This is called when a post is deleted.
94
+ function delete_post( $post_ID ) {
95
// Clear the cache for this post.
96
+ $this->clear((int) $post_ID);
97
98
// Find all "peers" which list this post as a related post.
99
+ $peers = $this->related(null, (int) $post_ID);
100
// Clear the peers' caches.
101
$this->clear($peers);
102
}
103
104
// New in 3.2.1: handle various post_status transitions
105
+ function transition_post_status( $new_status, $old_status, $post ) {
106
switch ($new_status) {
107
case "draft":
108
$this->delete_post($post->ID);
115
}
116
}
117
118
+ function set_score_override_flag( $q ) {
119
if ( $this->is_yarpp_time() ) {
120
$this->score_override = ($q->query_vars['orderby'] == 'score');
121
class-core.php CHANGED
@@ -33,9 +33,9 @@ class YARPP {
33
register_activation_hook( __FILE__, array($this, 'activate') );
34
35
// update cache on save
36
- add_action( 'save_post', array($this->cache, 'save_post') );
37
// new in 3.2: update cache on delete
38
- add_action( 'delete_post', array($this->cache, 'delete_post') );
39
// new in 3.2.1: handle post_status transitions
40
add_action( 'transition_post_status', array($this->cache, 'transition_post_status'), 10, 3);
41
33
register_activation_hook( __FILE__, array($this, 'activate') );
34
35
// update cache on save
36
+ add_action( 'save_post', array($this->cache, 'save_post'), 10, 2 );
37
// new in 3.2: update cache on delete
38
+ add_action( 'delete_post', array($this->cache, 'delete_post'), 10, 1 );
39
// new in 3.2.1: handle post_status transitions
40
add_action( 'transition_post_status', array($this->cache, 'transition_post_status'), 10, 3);
41
readme.txt CHANGED
@@ -231,6 +231,12 @@ If you are a bilingual speaker of English and another language and an avid user
231
232
== Changelog ==
233
234
= 3.5.2 =
235
* [Bugfix](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-bug-found-with-solution): fix an unfortunate typo which caused "no related posts" on many environments with non-MyISAM tables
236
* Fixed a bug where related posts would not be recomputed on post update, on environments using the `table` YARPP cache method and a persistent object caching system, like W3 Total Cache or memcached
231
232
== Changelog ==
233
234
+ = 3.5.3 =
235
+
236
+ * Ensure that `save_post` and `delete_post` hooks receive relevant post ID information
237
+ * Code cleanup:
238
+ * [Bugfix](https://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-latin1-instead-of-utf-8?replies=3): tables should be created using WordPress charset settings
239
+
240
= 3.5.2 =
241
* [Bugfix](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-bug-found-with-solution): fix an unfortunate typo which caused "no related posts" on many environments with non-MyISAM tables
242
* Fixed a bug where related posts would not be recomputed on post update, on environments using the `table` YARPP cache method and a persistent object caching system, like W3 Total Cache or memcached
yarpp.php CHANGED
@@ -3,13 +3,13 @@
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. Now with custom post type support!
6
- Version: 3.5.2
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
- define('YARPP_VERSION', '3.5.2');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. Now with custom post type support!
6
+ Version: 3.5.3b1
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
+ define('YARPP_VERSION', '3.5.3b1');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');