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

Version Description

Download this release

Release Info

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

Code changes from version 3.5.3b1 to 3.5.3b2

Files changed (7) hide show
  1. cache-postmeta.php +3 -6
  2. cache-tables.php +4 -10
  3. class-cache.php +36 -37
  4. class-core.php +18 -9
  5. readme.txt +5 -1
  6. template-metabox.php +1 -1
  7. yarpp.php +2 -2
cache-postmeta.php CHANGED
@@ -152,14 +152,11 @@ class YARPP_Cache_Postmeta extends YARPP_Cache {
152
}
153
}
154
155
- // @return YARPP_NO_RELATED | YARPP_RELATED | YARPP_NOT_CACHED
156
- public function update($reference_ID) {
157
global $wpdb;
158
159
- // $reference_ID must be numeric
160
- if ( !$reference_ID = absint($reference_ID) )
161
- return YARPP_NOT_CACHED;
162
-
163
$original_related = $this->related($reference_ID);
164
$related = $wpdb->get_results($this->sql($reference_ID), ARRAY_A);
165
$new_related = wp_list_pluck( $related, 'ID' );
152
}
153
}
154
155
+ // @return YARPP_NO_RELATED | YARPP_RELATED
156
+ // @used by enforce
157
+ protected function update($reference_ID) {
158
global $wpdb;
159
160
$original_related = $this->related($reference_ID);
161
$related = $wpdb->get_results($this->sql($reference_ID), ARRAY_A);
162
$new_related = wp_list_pluck( $related, 'ID' );
cache-tables.php CHANGED
@@ -186,7 +186,7 @@ class YARPP_Cache_Tables extends YARPP_Cache {
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;
@@ -198,14 +198,11 @@ class YARPP_Cache_Tables extends YARPP_Cache {
198
wp_cache_delete( 'is_cached_' . $id, 'yarpp' );
199
}
200
201
- // @return YARPP_RELATED | YARPP_NO_RELATED | YARPP_NOT_CACHED
202
- public function update($reference_ID) {
203
global $wpdb;
204
205
- // $reference_ID must be numeric
206
- if ( !$reference_ID = absint($reference_ID) )
207
- return YARPP_NOT_CACHED;
208
-
209
$original_related = (array) @$this->related($reference_ID);
210
211
if ( count($original_related) ) {
@@ -231,9 +228,6 @@ class YARPP_Cache_Tables extends YARPP_Cache {
231
} else {
232
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) values ($reference_ID,0,0) on duplicate key update date = now()");
233
234
- //if (!$wpdb->rows_affected)
235
- // return YARPP_NOT_CACHED;
236
-
237
// Clear the caches of those which are no longer related.
238
if ( count($original_related) )
239
$this->clear($original_related);
186
public function clear( $reference_IDs ) {
187
global $wpdb;
188
189
+ $reference_IDs = wp_parse_id_list( $reference_IDs );
190
191
if ( !count($reference_IDs) )
192
return;
198
wp_cache_delete( 'is_cached_' . $id, 'yarpp' );
199
}
200
201
+ // @return YARPP_RELATED | YARPP_NO_RELATED
202
+ // @used by enforce
203
+ protected function update($reference_ID) {
204
global $wpdb;
205
206
$original_related = (array) @$this->related($reference_ID);
207
208
if ( count($original_related) ) {
228
} else {
229
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) values ($reference_ID,0,0) on duplicate key update date = now()");
230
231
// Clear the caches of those which are no longer related.
232
if ( count($original_related) )
233
$this->clear($original_related);
class-cache.php CHANGED
@@ -39,7 +39,11 @@ abstract class YARPP_Cache {
39
// Note: return value changed in 3.4
40
// return YARPP_NO_RELATED | YARPP_RELATED | YARPP_DONT_RUN | false if no good input
41
function enforce( $reference_ID, $force = false ) {
42
- if ( !$reference_ID = absint($reference_ID) )
43
return false;
44
45
$status = $this->is_cached($reference_ID);
@@ -50,12 +54,9 @@ abstract class YARPP_Cache {
50
return YARPP_DONT_RUN;
51
52
// If not cached, process now:
53
- if ( YARPP_NOT_CACHED == $status || $force ) {
54
- $status = $this->update($reference_ID);
55
- // if still not cached, there's a problem, but for the time being return NO RELATED
56
- if ( YARPP_NOT_CACHED === $status )
57
- return YARPP_NO_RELATED;
58
- }
59
60
// There are no related posts
61
if ( YARPP_NO_RELATED === $status )
@@ -77,42 +78,43 @@ abstract class YARPP_Cache {
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
84
- // @since 3.4: don't compute on revisions
85
- if (defined('WP_IMPORTING') || wp_is_post_revision($post_ID))
86
- return;
87
-
88
- // @since 3.4: simply clear the cache on save; don't recompute.
89
- $this->clear((int) $post_ID);
90
- }
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);
109
- break;
110
- case "publish":
111
- // find everything which is related to this post, and clear them, so that this
112
- // post might show up as related to them.
113
- $related = $this->related($post->ID, null);
114
$this->clear($related);
115
}
116
}
117
118
function set_score_override_flag( $q ) {
@@ -576,14 +578,11 @@ class YARPP_Cache_Bypass extends YARPP_Cache {
576
remove_filter('posts_request',array(&$this,'demo_request_filter'));
577
}
578
579
- // @return YARPP_NO_RELATED | YARPP_RELATED | YARPP_NOT_CACHED
580
- public function update($reference_ID) {
581
global $wpdb;
582
583
- // $reference_ID must be numeric
584
- if ( !$reference_ID = absint($reference_ID) )
585
- return YARPP_NOT_CACHED;
586
-
587
return YARPP_RELATED;
588
}
589
39
// Note: return value changed in 3.4
40
// return YARPP_NO_RELATED | YARPP_RELATED | YARPP_DONT_RUN | false if no good input
41
function enforce( $reference_ID, $force = false ) {
42
+ // @since 3.5.3: don't compute on revisions
43
+ if ( $the_post = wp_is_post_revision($reference_ID) )
44
+ $reference_ID = $the_post;
45
+
46
+ if ( !is_int( $reference_ID ) )
47
return false;
48
49
$status = $this->is_cached($reference_ID);
54
return YARPP_DONT_RUN;
55
56
// If not cached, process now:
57
+ if ( YARPP_NOT_CACHED == $status || $force )
58
+ $status = $this->update((int) $reference_ID);
59
+ // status now will be YARPP_NO_RELATED | YARPP_RELATED
60
61
// There are no related posts
62
if ( YARPP_NO_RELATED === $status )
78
* POST STATUS INTERACTIONS
79
*/
80
81
// Clear the cache for this entry and for all posts which are "related" to it.
82
// New in 3.2: This is called when a post is deleted.
83
function delete_post( $post_ID ) {
84
// Clear the cache for this post.
85
$this->clear((int) $post_ID);
86
87
+ // Find all "peers" which list this post as a related post and clear their caches
88
+ if ( $peers = $this->related(null, (int) $post_ID) )
89
+ $this->clear($peers);
90
}
91
92
// New in 3.2.1: handle various post_status transitions
93
function transition_post_status( $new_status, $old_status, $post ) {
94
+ $post_ID = $post->ID;
95
+
96
+ // @since 3.4: don't compute on revisions
97
+ // @since 3.5: compute on the parent instead
98
+ if ( $the_post = wp_is_post_revision($post_ID) )
99
+ $post_ID = $the_post;
100
+
101
+ // unpublish
102
+ if ( $old_status == 'publish' && $new_status != 'publish' ) {
103
+ // Find all "peers" which list this post as a related post and clear their caches
104
+ if ( $peers = $this->related(null, (int) $post_ID) )
105
+ $this->clear($peers);
106
+ }
107
+
108
+ // publish
109
+ if ( $old_status != 'publish' && $new_status == 'publish' ) {
110
+ // find everything which is related to this post, and clear them, so that this
111
+ // post might show up as related to them.
112
+ if ( $related = $this->related($post_ID, null) )
113
$this->clear($related);
114
}
115
+
116
+ // @since 3.4: simply clear the cache on save; don't recompute.
117
+ $this->clear((int) $post_ID);
118
}
119
120
function set_score_override_flag( $q ) {
578
remove_filter('posts_request',array(&$this,'demo_request_filter'));
579
}
580
581
+ // @return YARPP_NO_RELATED | YARPP_RELATED
582
+ // @used by enforce
583
+ protected function update($reference_ID) {
584
global $wpdb;
585
586
return YARPP_RELATED;
587
}
588
class-core.php CHANGED
@@ -32,11 +32,10 @@ class YARPP {
32
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
42
// automatic display hooks:
@@ -512,12 +511,16 @@ class YARPP {
512
513
$this->upgrade_check();
514
515
- $reference_ID = ( null === $reference_ID || false === $reference_ID ) ?
516
- get_the_ID() : absint($reference_ID);
517
-
518
// if we're already in a YARPP loop, stop now.
519
if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
520
return false;
521
522
$this->setup_active_cache( $args );
523
@@ -598,6 +601,9 @@ class YARPP {
598
$this->upgrade_check();
599
600
$reference_ID = ( null === $reference_ID ) ? get_the_ID() : absint($reference_ID);
601
602
// if we're already in a YARPP loop, stop now.
603
if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
@@ -636,12 +642,15 @@ class YARPP {
636
function related_exist($reference_ID = null, $args = array()) {
637
$this->upgrade_check();
638
639
- $reference_ID = ( null === $reference_ID ) ? get_the_ID() : absint($reference_ID);
640
-
641
// if we're already in a YARPP loop, stop now.
642
if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
643
return false;
644
645
$this->setup_active_cache( $args );
646
647
$cache_status = $this->active_cache->enforce($reference_ID);
@@ -819,8 +828,8 @@ class YARPP {
819
if (is_wp_error($remote))
820
return false;
821
822
- $result = unserialize($remote['body']);
823
- set_transient('yarpp_version_info', $result, 60*60*12);
824
}
825
return $result;
826
}
32
33
register_activation_hook( __FILE__, array($this, 'activate') );
34
35
// new in 3.2: update cache on delete
36
add_action( 'delete_post', array($this->cache, 'delete_post'), 10, 1 );
37
// new in 3.2.1: handle post_status transitions
38
+ // new in 3.5.3: use transition_post_status instead of save_post hook
39
add_action( 'transition_post_status', array($this->cache, 'transition_post_status'), 10, 3);
40
41
// automatic display hooks:
511
512
$this->upgrade_check();
513
514
// if we're already in a YARPP loop, stop now.
515
if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
516
return false;
517
+
518
+ $reference_ID = ( null === $reference_ID || false === $reference_ID ) ?
519
+ get_the_ID() : absint($reference_ID);
520
+
521
+ // @since 3.5.3: don't compute on revisions
522
+ if ( $the_post = wp_is_post_revision($reference_ID) )
523
+ $reference_ID = $the_post;
524
525
$this->setup_active_cache( $args );
526
601
$this->upgrade_check();
602
603
$reference_ID = ( null === $reference_ID ) ? get_the_ID() : absint($reference_ID);
604
+ // @since 3.5.3: don't compute on revisions
605
+ if ( $the_post = wp_is_post_revision($reference_ID) )
606
+ $reference_ID = $the_post;
607
608
// if we're already in a YARPP loop, stop now.
609
if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
642
function related_exist($reference_ID = null, $args = array()) {
643
$this->upgrade_check();
644
645
// if we're already in a YARPP loop, stop now.
646
if ( $this->cache->is_yarpp_time() || $this->cache_bypass->is_yarpp_time() )
647
return false;
648
649
+ $reference_ID = ( null === $reference_ID ) ? get_the_ID() : absint($reference_ID);
650
+ // @since 3.5.3: don't compute on revisions
651
+ if ( $the_post = wp_is_post_revision($reference_ID) )
652
+ $reference_ID = $the_post;
653
+
654
$this->setup_active_cache( $args );
655
656
$cache_status = $this->active_cache->enforce($reference_ID);
828
if (is_wp_error($remote))
829
return false;
830
831
+ if ( $result = @unserialize($remote['body']) )
832
+ set_transient('yarpp_version_info', $result, 60*60*12);
833
}
834
return $result;
835
}
readme.txt CHANGED
@@ -233,9 +233,13 @@ If you are a bilingual speaker of English and another language and an avid user
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
233
234
= 3.5.3 =
235
236
+ * Ensure YARPP functions do not operate on post revisions
237
+ * Removed one way in which it would incorrectly return "no related posts"
238
* Code cleanup:
239
* [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
240
+ * YARPP_Cache_*::update methods are now protected
241
+ * Simplified some post status transition handling
242
+ * Ensure that `delete_post` hook receives relevant post ID information
243
244
= 3.5.2 =
245
* [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
template-metabox.php CHANGED
@@ -1,7 +1,7 @@
1
<?php
2
global $yarpp;
3
4
- $yarpp->cache->enforce($reference_ID, false); // enforce the cache, but don't force it
5
6
if ($yarpp->debug) {
7
$keywords = $yarpp->cache->get_keywords($reference_ID);
1
<?php
2
global $yarpp;
3
4
+ $yarpp->cache->enforce((int) $reference_ID, false); // enforce the cache, but don't force it
5
6
if ($yarpp->debug) {
7
$keywords = $yarpp->cache->get_keywords($reference_ID);
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.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', ':)');
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.3b2
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.3b2');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');