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

Version Description

Download this release

Release Info

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

Code changes from version 3.5 to 3.5.1b1

class-admin.php CHANGED
@@ -234,7 +234,7 @@ jQuery(function () {
234
'domain' => isset($_REQUEST['domain']) ? $_REQUEST['domain'] : 'website'
235
);
236
if ( $this->core->get_option('cross_relate') )
237
- $args['post_type'] = array('post', 'page');
238
239
$return = $this->core->display_related(absint($_REQUEST['ID']), $args, false);
240
echo $return;
234
'domain' => isset($_REQUEST['domain']) ? $_REQUEST['domain'] : 'website'
235
);
236
if ( $this->core->get_option('cross_relate') )
237
+ $args['post_type'] = $yarpp->get_post_types();
238
239
$return = $this->core->display_related(absint($_REQUEST['ID']), $args, false);
240
echo $return;
class-cache.php CHANGED
@@ -209,10 +209,10 @@ abstract class YARPP_Cache {
209
210
$newsql .= " order by score desc limit $limit";
211
212
- if ( isset($args['post_type']) && is_array($args['post_type']) )
213
- $post_types = $args['post_type'];
214
else
215
- $post_types = $this->core->get_post_types( 'name' );
216
217
$queries = array();
218
foreach ( $post_types as $post_type ) {
209
210
$newsql .= " order by score desc limit $limit";
211
212
+ if ( isset($args['post_type']) )
213
+ $post_types = (array) $args['post_type'];
214
else
215
+ $post_types = $this->core->get_post_types();
216
217
$queries = array();
218
foreach ( $post_types as $post_type ) {
class-core.php CHANGED
@@ -434,15 +434,15 @@ class YARPP {
434
}
435
436
private $post_types = null;
437
- function get_post_types( $field = false ) {
438
if ( is_null($this->post_types) ) {
439
$this->post_types = get_post_types(array(), 'objects');
440
$this->post_types = array_filter( $this->post_types, array($this, 'post_type_filter') );
441
}
442
443
- if ( $field )
444
- return wp_list_pluck( $this->post_types, $field );
445
- return $this->post_types;
446
}
447
448
private function post_type_filter( $post_type ) {
@@ -466,7 +466,7 @@ class YARPP {
466
}
467
468
private function taxonomy_filter( $taxonomy ) {
469
- if ( !count(array_intersect( $taxonomy->object_type, $this->get_post_types( 'name' ) )) )
470
return false;
471
472
// if yarpp_support is set, follow that; otherwise include if show_ui is true
@@ -530,7 +530,7 @@ class YARPP {
530
'orderby' => $orders[0],
531
'order' => $orders[1],
532
'showposts' => $limit,
533
- 'post_type' => ( isset($args['post_type']) ? $args['post_type'] : $this->get_post_types( 'name' ) )
534
));
535
}
536
$this->prep_query( $current_query->is_feed );
@@ -601,7 +601,7 @@ class YARPP {
601
'orderby' => $orders[0],
602
'order' => $orders[1],
603
'showposts' => $limit,
604
- 'post_type' => ( isset($args['post_type']) ? $args['post_type'] : $this->get_post_types( 'name' ) )
605
));
606
$this->active_cache->end_yarpp_time(); // YARPP time is over... :(
607
@@ -633,7 +633,7 @@ class YARPP {
633
$related_query->query(array(
634
'p' => $reference_ID,
635
'showposts' => 1,
636
- 'post_type' => ( isset($args['post_type']) ? $args['post_type'] : $this->get_post_types( 'name' ) )
637
));
638
$return = $related_query->have_posts();
639
unset($related_query);
@@ -741,14 +741,15 @@ class YARPP {
741
*/
742
743
function the_content($content) {
744
- global $post;
745
-
746
if (is_feed())
747
return $this->the_content_rss($content);
748
749
- $type = ($post->post_type == 'page' ? array('page') : array('post'));
750
if ( $this->get_option('cross_relate') )
751
- $type = array('post','page');
752
753
if ( $this->get_option('auto_display') && is_single() )
754
return $content . $this->display_related(null, array('post_type' => $type, 'domain' => 'website'), false);
@@ -757,11 +758,12 @@ class YARPP {
757
}
758
759
function the_content_rss($content) {
760
- global $post;
761
-
762
- $type = ($post->post_type == 'page' ? array('page') : array('post'));
763
if ( $this->get_option('cross_relate') )
764
- $type = array('post','page');
765
766
if ( $this->get_option('rss_display') )
767
return $content . $this->display_related(null, array('post_type' => $type, 'domain' => 'rss'), false);
@@ -770,11 +772,12 @@ class YARPP {
770
}
771
772
function the_excerpt_rss($content) {
773
- global $post;
774
-
775
- $type = ($post->post_type == 'page' ? array('page') : array('post'));
776
if ( $this->get_option('cross_relate') )
777
- $type = array('post','page');
778
779
if ( $this->get_option('rss_excerpt_display') && $this->get_option('rss_display') )
780
return $content . clean_pre($this->display_related(null, array('post_type' => $type, 'domain' => 'rss'), false));
434
}
435
436
private $post_types = null;
437
+ function get_post_types( $field = 'name' ) {
438
if ( is_null($this->post_types) ) {
439
$this->post_types = get_post_types(array(), 'objects');
440
$this->post_types = array_filter( $this->post_types, array($this, 'post_type_filter') );
441
}
442
443
+ if ( 'objects' == $field )
444
+ return $this->post_types;
445
+ return wp_list_pluck( $this->post_types, $field );
446
}
447
448
private function post_type_filter( $post_type ) {
466
}
467
468
private function taxonomy_filter( $taxonomy ) {
469
+ if ( !count(array_intersect( $taxonomy->object_type, $this->get_post_types() )) )
470
return false;
471
472
// if yarpp_support is set, follow that; otherwise include if show_ui is true
530
'orderby' => $orders[0],
531
'order' => $orders[1],
532
'showposts' => $limit,
533
+ 'post_type' => ( isset($args['post_type']) ? $args['post_type'] : $this->get_post_types() )
534
));
535
}
536
$this->prep_query( $current_query->is_feed );
601
'orderby' => $orders[0],
602
'order' => $orders[1],
603
'showposts' => $limit,
604
+ 'post_type' => ( isset($args['post_type']) ? $args['post_type'] : $this->get_post_types() )
605
));
606
$this->active_cache->end_yarpp_time(); // YARPP time is over... :(
607
633
$related_query->query(array(
634
'p' => $reference_ID,
635
'showposts' => 1,
636
+ 'post_type' => ( isset($args['post_type']) ? $args['post_type'] : $this->get_post_types() )
637
));
638
$return = $related_query->have_posts();
639
unset($related_query);
741
*/
742
743
function the_content($content) {
744
if (is_feed())
745
return $this->the_content_rss($content);
746
747
if ( $this->get_option('cross_relate') )
748
+ $type = $this->get_post_types();
749
+ else if ( 'page' == get_post_type() )
750
+ $type = array( 'page' );
751
+ else
752
+ $type = array( 'post' );
753
754
if ( $this->get_option('auto_display') && is_single() )
755
return $content . $this->display_related(null, array('post_type' => $type, 'domain' => 'website'), false);
758
}
759
760
function the_content_rss($content) {
761
if ( $this->get_option('cross_relate') )
762
+ $type = $this->get_post_types();
763
+ else if ( 'page' == get_post_type() )
764
+ $type = array( 'page' );
765
+ else
766
+ $type = array( 'post' );
767
768
if ( $this->get_option('rss_display') )
769
return $content . $this->display_related(null, array('post_type' => $type, 'domain' => 'rss'), false);
772
}
773
774
function the_excerpt_rss($content) {
775
if ( $this->get_option('cross_relate') )
776
+ $type = $this->get_post_types();
777
+ else if ( 'page' == get_post_type() )
778
+ $type = array( 'page' );
779
+ else
780
+ $type = array( 'post' );
781
782
if ( $this->get_option('rss_excerpt_display') && $this->get_option('rss_display') )
783
return $content . clean_pre($this->display_related(null, array('post_type' => $type, 'domain' => 'rss'), false));
class-widget.php CHANGED
@@ -8,7 +8,7 @@ class YARPP_Widget extends WP_Widget {
8
}
9
10
function widget($args, $instance) {
11
- global $post, $yarpp;
12
if ( !is_singular() )
13
return;
14
@@ -18,9 +18,12 @@ class YARPP_Widget extends WP_Widget {
18
if ( isset($instance['use_template']) )
19
$instance['template'] = $instance['use_template'] ? $instance['template_file'] : false;
20
21
- $instance['post_type'] = ($post->post_type == 'page' ? array('page') : array('post'));
22
- if ( yarpp_get_option('cross_relate') )
23
- $instance['post_type'] = array('post','page');
24
25
$title = apply_filters('widget_title', $instance['title']);
26
echo $before_widget;
8
}
9
10
function widget($args, $instance) {
11
+ global $yarpp;
12
if ( !is_singular() )
13
return;
14
18
if ( isset($instance['use_template']) )
19
$instance['template'] = $instance['use_template'] ? $instance['template_file'] : false;
20
21
+ if ( $yarpp->get_option('cross_relate') )
22
+ $instance['post_type'] = $yarpp->get_post_types();
23
+ else if ( 'page' == get_post_type() )
24
+ $instance['post_type'] = array( 'page' );
25
+ else
26
+ $instance['post_type'] = array( 'post' );
27
28
$title = apply_filters('widget_title', $instance['title']);
29
echo $before_widget;
options-meta-boxes.php CHANGED
@@ -110,7 +110,7 @@ if ( count($exclude_term_ids) ) {
110
111
<table class="form-table" style="margin-top: 0; clear:none;">
112
<tbody>
113
- <tr><th><?php _e('Post types considered:', 'yarpp'); ?></th><td><?php echo implode(', ', $yarpp->get_post_types('label')); ?> <a href='http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/other_notes'><?php _e('more&gt;','yarpp');?></a></td></tr>
114
<?php
115
foreach ($yarpp->get_taxonomies() as $taxonomy) {
116
$this->exclude($taxonomy->name, sprintf(__('Disallow by %s:','yarpp'), $taxonomy->labels->singular_name));
110
111
<table class="form-table" style="margin-top: 0; clear:none;">
112
<tbody>
113
+ <tr><th><?php _e('Post types considered:', 'yarpp'); ?></th><td><?php echo implode(', ', $yarpp->get_post_types( 'label' )); ?> <a href='http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/other_notes'><?php _e('more&gt;','yarpp');?></a></td></tr>
114
<?php
115
foreach ($yarpp->get_taxonomies() as $taxonomy) {
116
$this->exclude($taxonomy->name, sprintf(__('Disallow by %s:','yarpp'), $taxonomy->labels->singular_name));
readme.txt CHANGED
@@ -230,6 +230,9 @@ If you are a bilingual speaker of English and another language and an avid user
230
231
== Changelog ==
232
233
= 3.5 =
234
* New public YARPP query API, which supports custom post types
235
* Documentation in the "other notes" section of the readme
230
231
== Changelog ==
232
233
+ = 3.5.1 =
234
+ * [Bugfix](http://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-catchable-fatal-error-object-of-class-stdclass-could-not-be-converted-to-string): change `$yarpp->get_post_types()` to return array of names by default
235
+ * Ensure that all supported post types are used when "display results from all post types" is set
236
= 3.5 =
237
* New public YARPP query API, which supports custom post types
238
* Documentation in the "other notes" section of the readme
related-functions.php CHANGED
@@ -37,9 +37,11 @@ function related_posts($args = array(), $reference_ID=false, $echo=true) {
37
}
38
39
global $yarpp;
40
- $args['post_type'] = array('post');
41
if ( $yarpp->get_option('cross_relate') )
42
$args['post_type'] = $yarpp->get_post_types();
43
return yarpp_related( $args, $reference_ID, $echo );
44
}
45
@@ -50,9 +52,11 @@ function related_pages($args = array(), $reference_ID=false, $echo=true) {
50
}
51
52
global $yarpp;
53
- $args['post_type'] = array('page');
54
if ( $yarpp->get_option('cross_relate') )
55
$args['post_type'] = $yarpp->get_post_types();
56
return yarpp_related( $args, $reference_ID, $echo );
57
}
58
@@ -64,27 +68,33 @@ function related_entries($args = array(), $reference_ID=false, $echo=true ) {
64
65
global $yarpp;
66
$args['post_type'] = $yarpp->get_post_types();
67
return yarpp_related( $args, $reference_ID, $echo );
68
}
69
70
function related_posts_exist($args = array(), $reference_ID=false) {
71
global $yarpp;
72
- $args['post_type'] = array('post');
73
if ( $yarpp->get_option('cross_relate') )
74
$args['post_type'] = $yarpp->get_post_types();
75
return yarpp_related_exist( $args, $reference_ID );
76
}
77
78
function related_pages_exist($args = array(), $reference_ID=false) {
79
global $yarpp;
80
- $args['post_type'] = array('page');
81
if ( $yarpp->get_option('cross_relate') )
82
$args['post_type'] = $yarpp->get_post_types();
83
return yarpp_related_exist( $args, $reference_ID );
84
}
85
86
function related_entries_exist($args = array(),$reference_ID=false) {
87
global $yarpp;
88
$args['post_type'] = $yarpp->get_post_types();
89
return yarpp_related_exist( $args, $reference_ID );
90
}
37
}
38
39
global $yarpp;
40
if ( $yarpp->get_option('cross_relate') )
41
$args['post_type'] = $yarpp->get_post_types();
42
+ else
43
+ $args['post_type'] = array( 'post' );
44
+
45
return yarpp_related( $args, $reference_ID, $echo );
46
}
47
52
}
53
54
global $yarpp;
55
if ( $yarpp->get_option('cross_relate') )
56
$args['post_type'] = $yarpp->get_post_types();
57
+ else
58
+ $args['post_type'] = array( 'page' );
59
+
60
return yarpp_related( $args, $reference_ID, $echo );
61
}
62
68
69
global $yarpp;
70
$args['post_type'] = $yarpp->get_post_types();
71
+
72
return yarpp_related( $args, $reference_ID, $echo );
73
}
74
75
function related_posts_exist($args = array(), $reference_ID=false) {
76
global $yarpp;
77
if ( $yarpp->get_option('cross_relate') )
78
$args['post_type'] = $yarpp->get_post_types();
79
+ else
80
+ $args['post_type'] = array( 'post' );
81
+
82
return yarpp_related_exist( $args, $reference_ID );
83
}
84
85
function related_pages_exist($args = array(), $reference_ID=false) {
86
global $yarpp;
87
if ( $yarpp->get_option('cross_relate') )
88
$args['post_type'] = $yarpp->get_post_types();
89
+ else
90
+ $args['post_type'] = array( 'page' );
91
+
92
return yarpp_related_exist( $args, $reference_ID );
93
}
94
95
function related_entries_exist($args = array(),$reference_ID=false) {
96
global $yarpp;
97
$args['post_type'] = $yarpp->get_post_types();
98
+
99
return yarpp_related_exist( $args, $reference_ID );
100
}
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
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');
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.1b1
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.1b1');
13
define('YARPP_DIR', dirname(__FILE__));
14
define('YARPP_NO_RELATED', ':(');
15
define('YARPP_RELATED', ':)');