Version Description
(22-February-2021) = * New shortcode template attribute. Eg [yarpp template="yarpp-template-photoblog"] * Deprecated: functions related_posts, related_pages, related_entries (use yarpp_related instead), and related_posts_exist, related_pages_exist and related_entries_exist (use yarpp_related_exist instead) * Bugfix: consistently use "post_type" parameter and "cross-relate" from all YARPP functions * Bugfix: Add textdomain to allow translating the readme file
Download this release
Release Info
Developer | mnelson4 |
Plugin | Yet Another Related Posts Plugin (YARPP) |
Version | 5.12.0 |
Comparing to | |
See all releases |
Code changes from version 5.11.0 to 5.12.0
- classes/YARPP_Admin.php +10 -6
- classes/YARPP_Cache.php +4 -19
- classes/YARPP_Core.php +33 -23
- classes/YARPP_Rest_Api.php +2 -11
- classes/YARPP_Shortcode.php +16 -2
- classes/YARPP_Widget.php +0 -8
- includes/related_functions.php +74 -0
- js/metabox.js +14 -9
- readme.txt +25 -6
- yarpp.php +3 -2
classes/YARPP_Admin.php
CHANGED
@@ -401,7 +401,7 @@ class YARPP_Admin {
|
|
401 |
$this->optin_notice('install', $optinAction);
|
402 |
}
|
403 |
|
404 |
-
public function optin_notice($type=false, $optinAction) {
|
405 |
$screen = get_current_screen();
|
406 |
if(is_null($screen) || $screen->id == 'settings_page_yarpp') return;
|
407 |
|
@@ -630,19 +630,23 @@ class YARPP_Admin {
|
|
630 |
return array();
|
631 |
return $wpdb->get_col("select term_id from $wpdb->term_taxonomy where taxonomy = '{$taxonomy}' and term_taxonomy_id in (" . join(',', $tt_ids) . ")");
|
632 |
}
|
633 |
-
|
|
|
|
|
|
|
|
|
|
|
634 |
public function ajax_display() {
|
635 |
check_ajax_referer('yarpp_display');
|
636 |
|
637 |
if (!isset($_REQUEST['ID'])) return;
|
638 |
|
639 |
$args = array(
|
640 |
-
'post_type' => array('post'),
|
641 |
'domain' => isset($_REQUEST['domain']) ? $_REQUEST['domain'] : 'website'
|
642 |
);
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
$return = $this->core->display_related(absint($_REQUEST['ID']), $args, false);
|
647 |
|
648 |
header("HTTP/1.1 200");
|
401 |
$this->optin_notice('install', $optinAction);
|
402 |
}
|
403 |
|
404 |
+
public function optin_notice($type=false, $optinAction='disable') {
|
405 |
$screen = get_current_screen();
|
406 |
if(is_null($screen) || $screen->id == 'settings_page_yarpp') return;
|
407 |
|
630 |
return array();
|
631 |
return $wpdb->get_col("select term_id from $wpdb->term_taxonomy where taxonomy = '{$taxonomy}' and term_taxonomy_id in (" . join(',', $tt_ids) . ")");
|
632 |
}
|
633 |
+
|
634 |
+
/**
|
635 |
+
* Handles populating the YARPP related metabox. When the page is initially loaded, this is called to populate it
|
636 |
+
* but $_REQUEST['refresh'] isn't set because we're happy using the cached results. But when the user clicks the
|
637 |
+
* "Refresh" button, $_REQUEST['refresh'] is set so we try to clear the cache and re-calculate the related content.
|
638 |
+
*/
|
639 |
public function ajax_display() {
|
640 |
check_ajax_referer('yarpp_display');
|
641 |
|
642 |
if (!isset($_REQUEST['ID'])) return;
|
643 |
|
644 |
$args = array(
|
|
|
645 |
'domain' => isset($_REQUEST['domain']) ? $_REQUEST['domain'] : 'website'
|
646 |
);
|
647 |
+
if(isset($_REQUEST['refresh']) && $this->core->cache instanceof YARPP_Cache){
|
648 |
+
$this->core->cache->clear($_REQUEST['ID']);
|
649 |
+
}
|
650 |
$return = $this->core->display_related(absint($_REQUEST['ID']), $args, false);
|
651 |
|
652 |
header("HTTP/1.1 200");
|
classes/YARPP_Cache.php
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
<?php
|
2 |
abstract class YARPP_Cache {
|
|
|
|
|
|
|
3 |
protected $core;
|
4 |
/**
|
5 |
* During "YARPP Time", we add a bunch of filters to modify WP_Query
|
@@ -253,15 +256,7 @@ abstract class YARPP_Cache {
|
|
253 |
|
254 |
}
|
255 |
|
256 |
-
|
257 |
-
$post_types = (array) $args['post_type'];
|
258 |
-
} else {
|
259 |
-
if ($this->core->get_option('cross_relate')) {
|
260 |
-
$post_types = $this->core->get_post_types();
|
261 |
-
} else {
|
262 |
-
$post_types = array(get_post_type($reference_post));
|
263 |
-
}
|
264 |
-
}
|
265 |
$sanitized_post_types = array_map(
|
266 |
function($item){
|
267 |
global $wpdb;
|
@@ -307,16 +302,6 @@ abstract class YARPP_Cache {
|
|
307 |
$limit
|
308 |
);
|
309 |
|
310 |
-
if (isset($args['post_type'])) {
|
311 |
-
$post_types = (array) $args['post_type'];
|
312 |
-
} else {
|
313 |
-
if ($this->core->get_option('cross_relate')) {
|
314 |
-
$post_types = $this->core->get_post_types();
|
315 |
-
} else {
|
316 |
-
$post_types = array(get_post_type($reference_post));
|
317 |
-
}
|
318 |
-
}
|
319 |
-
|
320 |
if ($this->core->debug) echo "<!-- $newsql -->";
|
321 |
|
322 |
$this->last_sql = $newsql;
|
1 |
<?php
|
2 |
abstract class YARPP_Cache {
|
3 |
+
/**
|
4 |
+
* @var YARPP
|
5 |
+
*/
|
6 |
protected $core;
|
7 |
/**
|
8 |
* During "YARPP Time", we add a bunch of filters to modify WP_Query
|
256 |
|
257 |
}
|
258 |
|
259 |
+
$post_types = $this->core->get_query_post_types($reference_post, $args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
$sanitized_post_types = array_map(
|
261 |
function($item){
|
262 |
global $wpdb;
|
302 |
$limit
|
303 |
);
|
304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
if ($this->core->debug) echo "<!-- $newsql -->";
|
306 |
|
307 |
$this->last_sql = $newsql;
|
classes/YARPP_Core.php
CHANGED
@@ -882,6 +882,14 @@ class YARPP {
|
|
882 |
}
|
883 |
|
884 |
private $post_types = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
885 |
public function get_post_types($field = 'name') {
|
886 |
if (is_null($this->post_types)) {
|
887 |
$this->post_types = get_post_types(array(), 'objects');
|
@@ -893,6 +901,23 @@ class YARPP {
|
|
893 |
return wp_list_pluck( $this->post_types, $field );
|
894 |
}
|
895 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
896 |
private function post_type_filter($post_type) {
|
897 |
// Remove blacklisted post types.
|
898 |
if(class_exists( 'bbPress' ) && in_array(
|
@@ -1075,12 +1100,6 @@ class YARPP {
|
|
1075 |
return null;
|
1076 |
}
|
1077 |
|
1078 |
-
if ($this->get_option('cross_relate')) {
|
1079 |
-
$post_types = $this->get_post_types();
|
1080 |
-
} else {
|
1081 |
-
$post_types = array(get_post_type());
|
1082 |
-
}
|
1083 |
-
|
1084 |
$post_types = apply_filters('yarpp_map_post_types', $post_types, 'website');
|
1085 |
|
1086 |
return $this->display_related(
|
@@ -1175,7 +1194,7 @@ class YARPP {
|
|
1175 |
'orderby' => $orders[0],
|
1176 |
'order' => $orders[1],
|
1177 |
'showposts' => $limit,
|
1178 |
-
'post_type' => (
|
1179 |
)
|
1180 |
);
|
1181 |
}
|
@@ -1207,11 +1226,12 @@ class YARPP {
|
|
1207 |
// Be careful to avoid infinite recursion, because those templates might show each related posts' body or
|
1208 |
// excerpt, which would trigger finding its related posts, which would show its related posts body or excerpt...
|
1209 |
$this->rendering_related_content = true;
|
|
|
1210 |
if ($domain === 'metabox') {
|
1211 |
include(YARPP_DIR.'/includes/template_metabox.php');
|
1212 |
} else if ((bool) $template && $template === 'thumbnails') {
|
1213 |
include(YARPP_DIR.'/includes/template_thumbnails.php');
|
1214 |
-
} else if ((bool) $template && file_exists(STYLESHEETPATH.'/'.$template)) {
|
1215 |
global $post;
|
1216 |
ob_start();
|
1217 |
include(STYLESHEETPATH.'/'.$template);
|
@@ -1294,7 +1314,7 @@ class YARPP {
|
|
1294 |
'orderby' => $orders[0],
|
1295 |
'order' => $orders[1],
|
1296 |
'showposts' => $limit,
|
1297 |
-
'post_type' => (
|
1298 |
));
|
1299 |
|
1300 |
$related_query->posts = apply_filters(
|
@@ -1343,7 +1363,7 @@ class YARPP {
|
|
1343 |
$related_query->query(array(
|
1344 |
'p' => $reference_ID,
|
1345 |
'showposts' => 1,
|
1346 |
-
'post_type' => (
|
1347 |
));
|
1348 |
|
1349 |
$related_query->posts = apply_filters(
|
@@ -1538,11 +1558,7 @@ class YARPP {
|
|
1538 |
/* If the content includes <!--noyarpp-->, don't display */
|
1539 |
if (stristr($content, '<!--noyarpp-->') !== false) return $content;
|
1540 |
|
1541 |
-
|
1542 |
-
$post_types = $this->get_post_types();
|
1543 |
-
} else {
|
1544 |
-
$post_types = array(get_post_type());
|
1545 |
-
}
|
1546 |
|
1547 |
$post_types = apply_filters('yarpp_map_post_types', $post_types, 'rss');
|
1548 |
|
@@ -1562,15 +1578,9 @@ class YARPP {
|
|
1562 |
/* If the content includes <!--noyarpp-->, don't display */
|
1563 |
if (stristr($content, '<!--noyarpp-->') !== false) return $content;
|
1564 |
|
1565 |
-
|
1566 |
-
$type = $this->get_post_types();
|
1567 |
-
} else if (get_post_type() === 'page') {
|
1568 |
-
$type = array('page');
|
1569 |
-
} else {
|
1570 |
-
$type = array('post');
|
1571 |
-
}
|
1572 |
|
1573 |
-
return $content . $this->clean_pre($this->display_related(null, array('post_type' => $
|
1574 |
}
|
1575 |
|
1576 |
/*
|
882 |
}
|
883 |
|
884 |
private $post_types = null;
|
885 |
+
|
886 |
+
/**
|
887 |
+
* Gets all the post types YARPP can add related content to, and the post types YARPP can include in
|
888 |
+
* "the pool"
|
889 |
+
* @param string $field 'objects', or any property on WP_Post_Type, like 'name'. Defaults to 'name'.
|
890 |
+
*
|
891 |
+
* @return array|null
|
892 |
+
*/
|
893 |
public function get_post_types($field = 'name') {
|
894 |
if (is_null($this->post_types)) {
|
895 |
$this->post_types = get_post_types(array(), 'objects');
|
901 |
return wp_list_pluck( $this->post_types, $field );
|
902 |
}
|
903 |
|
904 |
+
/**
|
905 |
+
* Gets the post types to use for the current YARPP query
|
906 |
+
* @param string|WP_Post $reference_ID
|
907 |
+
* @param array $args
|
908 |
+
* @return string[]
|
909 |
+
*/
|
910 |
+
public function get_query_post_types($reference_ID = null, $args = array()){
|
911 |
+
if(isset($args['post_type'])){
|
912 |
+
$post_types = (array)$args['post_type'];
|
913 |
+
} else if ($this->get_option('cross_relate')) {
|
914 |
+
$post_types = $this->get_post_types();
|
915 |
+
} else {
|
916 |
+
$post_types = array(get_post_type($reference_ID));
|
917 |
+
}
|
918 |
+
return $post_types;
|
919 |
+
}
|
920 |
+
|
921 |
private function post_type_filter($post_type) {
|
922 |
// Remove blacklisted post types.
|
923 |
if(class_exists( 'bbPress' ) && in_array(
|
1100 |
return null;
|
1101 |
}
|
1102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1103 |
$post_types = apply_filters('yarpp_map_post_types', $post_types, 'website');
|
1104 |
|
1105 |
return $this->display_related(
|
1194 |
'orderby' => $orders[0],
|
1195 |
'order' => $orders[1],
|
1196 |
'showposts' => $limit,
|
1197 |
+
'post_type' => $this->get_query_post_types($reference_ID, $args)
|
1198 |
)
|
1199 |
);
|
1200 |
}
|
1226 |
// Be careful to avoid infinite recursion, because those templates might show each related posts' body or
|
1227 |
// excerpt, which would trigger finding its related posts, which would show its related posts body or excerpt...
|
1228 |
$this->rendering_related_content = true;
|
1229 |
+
$template = sanitize_file_name($template);
|
1230 |
if ($domain === 'metabox') {
|
1231 |
include(YARPP_DIR.'/includes/template_metabox.php');
|
1232 |
} else if ((bool) $template && $template === 'thumbnails') {
|
1233 |
include(YARPP_DIR.'/includes/template_thumbnails.php');
|
1234 |
+
} else if ((bool) $template && strpos($template,'yarpp-template-') === 0 && file_exists(STYLESHEETPATH.'/'.$template)) {
|
1235 |
global $post;
|
1236 |
ob_start();
|
1237 |
include(STYLESHEETPATH.'/'.$template);
|
1314 |
'orderby' => $orders[0],
|
1315 |
'order' => $orders[1],
|
1316 |
'showposts' => $limit,
|
1317 |
+
'post_type' => $this->get_query_post_types($reference_ID, $args)
|
1318 |
));
|
1319 |
|
1320 |
$related_query->posts = apply_filters(
|
1363 |
$related_query->query(array(
|
1364 |
'p' => $reference_ID,
|
1365 |
'showposts' => 1,
|
1366 |
+
'post_type' => $this->get_query_post_types($reference_ID, $args)
|
1367 |
));
|
1368 |
|
1369 |
$related_query->posts = apply_filters(
|
1558 |
/* If the content includes <!--noyarpp-->, don't display */
|
1559 |
if (stristr($content, '<!--noyarpp-->') !== false) return $content;
|
1560 |
|
1561 |
+
$post_types = $this->get_query_post_types();
|
|
|
|
|
|
|
|
|
1562 |
|
1563 |
$post_types = apply_filters('yarpp_map_post_types', $post_types, 'rss');
|
1564 |
|
1578 |
/* If the content includes <!--noyarpp-->, don't display */
|
1579 |
if (stristr($content, '<!--noyarpp-->') !== false) return $content;
|
1580 |
|
1581 |
+
$post_type = $this->get_query_post_types();
|
|
|
|
|
|
|
|
|
|
|
|
|
1582 |
|
1583 |
+
return $content . $this->clean_pre($this->display_related(null, array('post_type' => $post_type, 'domain' => 'rss'), false));
|
1584 |
}
|
1585 |
|
1586 |
/*
|
classes/YARPP_Rest_Api.php
CHANGED
@@ -143,14 +143,6 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
143 |
if(! $post_obj instanceof WP_Post){
|
144 |
return new WP_Error('rest_invalid_id', esc_html__( 'Invalid Id', 'yarpp' ), array('status' => 404));
|
145 |
}
|
146 |
-
|
147 |
-
if ($yarpp->get_option('cross_relate')) {
|
148 |
-
$post_types = $yarpp->get_post_types();
|
149 |
-
} else {
|
150 |
-
$post_types = array(get_post_type($post_obj));
|
151 |
-
}
|
152 |
-
|
153 |
-
$post_types = apply_filters('yarpp_map_post_types', $post_types, 'rest_api');
|
154 |
$allowed_args = array('limit');
|
155 |
|
156 |
$args = array_filter(
|
@@ -160,7 +152,6 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
160 |
},
|
161 |
ARRAY_FILTER_USE_KEY
|
162 |
);
|
163 |
-
$args['post_type'] = $post_types;
|
164 |
$related_posts = $yarpp->get_related(
|
165 |
$id,
|
166 |
$args
|
@@ -186,9 +177,9 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
186 |
$simulated_request->set_query_params($simulated_params);
|
187 |
|
188 |
// Hack the WordPress Posts controller to return posts of all types, so long as they have the IDs we want.
|
189 |
-
add_action( '
|
190 |
$read_controller_response = $read_controller->get_items($simulated_request);
|
191 |
-
remove_action( '
|
192 |
|
193 |
if(is_wp_error($read_controller_response)){
|
194 |
return $read_controller_response;
|
143 |
if(! $post_obj instanceof WP_Post){
|
144 |
return new WP_Error('rest_invalid_id', esc_html__( 'Invalid Id', 'yarpp' ), array('status' => 404));
|
145 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
$allowed_args = array('limit');
|
147 |
|
148 |
$args = array_filter(
|
152 |
},
|
153 |
ARRAY_FILTER_USE_KEY
|
154 |
);
|
|
|
155 |
$related_posts = $yarpp->get_related(
|
156 |
$id,
|
157 |
$args
|
177 |
$simulated_request->set_query_params($simulated_params);
|
178 |
|
179 |
// Hack the WordPress Posts controller to return posts of all types, so long as they have the IDs we want.
|
180 |
+
add_action( 'rest_' . $post_obj->post_type . '_query', array($this, 'ignore_post_type_filter_callback'), 10, 2 );
|
181 |
$read_controller_response = $read_controller->get_items($simulated_request);
|
182 |
+
remove_action( 'rest_' . $post_obj->post_type . '_query', array($this, 'ignore_post_type_filter_callback'), 10, 2 );
|
183 |
|
184 |
if(is_wp_error($read_controller_response)){
|
185 |
return $read_controller_response;
|
classes/YARPP_Shortcode.php
CHANGED
@@ -25,15 +25,29 @@ class YARPP_Shortcode {
|
|
25 |
public function render($atts) {
|
26 |
$atts = shortcode_atts(
|
27 |
array(
|
28 |
-
'reference_id' => null
|
|
|
29 |
),
|
30 |
$atts
|
31 |
);
|
32 |
/** @global $yarpp YARPP */
|
33 |
global $yarpp;
|
34 |
$post = get_post((int)$atts['reference_id']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
if($post instanceof WP_Post){
|
36 |
-
return $yarpp->display_related(
|
|
|
|
|
|
|
37 |
} else {
|
38 |
return '<!-- YARPP shortcode called but no reference post found. It was probably called outside "the loop" or the reference_id provided was invalid.-->';
|
39 |
}
|
25 |
public function render($atts) {
|
26 |
$atts = shortcode_atts(
|
27 |
array(
|
28 |
+
'reference_id' => null,
|
29 |
+
'template' => null
|
30 |
),
|
31 |
$atts
|
32 |
);
|
33 |
/** @global $yarpp YARPP */
|
34 |
global $yarpp;
|
35 |
$post = get_post((int)$atts['reference_id']);
|
36 |
+
$yarpp_args = array(
|
37 |
+
'domain' => 'shortcode'
|
38 |
+
);
|
39 |
+
if(isset($atts['template'])){
|
40 |
+
$yarpp_args['template'] = trim($atts['template']);
|
41 |
+
if(strpos($yarpp_args['template'],'.php') === false){
|
42 |
+
$yarpp_args['template'] .= '.php';
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
if($post instanceof WP_Post){
|
47 |
+
return $yarpp->display_related(
|
48 |
+
$post->ID,
|
49 |
+
$yarpp_args,
|
50 |
+
false);
|
51 |
} else {
|
52 |
return '<!-- YARPP shortcode called but no reference post found. It was probably called outside "the loop" or the reference_id provided was invalid.-->';
|
53 |
}
|
classes/YARPP_Widget.php
CHANGED
@@ -20,14 +20,6 @@ class YARPP_Widget extends WP_Widget {
|
|
20 |
$instance['template'] = ($instance['use_template']) ? ($instance['template_file']) : false;
|
21 |
}
|
22 |
|
23 |
-
if ($yarpp->get_option('cross_relate')){
|
24 |
-
$instance['post_type'] = $yarpp->get_post_types();
|
25 |
-
} else if (in_array(get_post_type(), $yarpp->get_post_types())) {
|
26 |
-
$instance['post_type'] = array(get_post_type());
|
27 |
-
} else {
|
28 |
-
$instance['post_type'] = array('post');
|
29 |
-
}
|
30 |
-
|
31 |
$title = apply_filters('widget_title', $instance['title']);
|
32 |
$output = $before_widget;
|
33 |
if (!$instance['template']) {
|
20 |
$instance['template'] = ($instance['use_template']) ? ($instance['template_file']) : false;
|
21 |
}
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
$title = apply_filters('widget_title', $instance['title']);
|
24 |
$output = $before_widget;
|
25 |
if (!$instance['template']) {
|
includes/related_functions.php
CHANGED
@@ -4,6 +4,14 @@ Here are the related_WHATEVER functions, as introduced in 1.1.
|
|
4 |
Since YARPP 2.1, these functions receive (optionally) one array argument.
|
5 |
----------------------------------------------------------------------------------------------------------------------*/
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
function yarpp_related($args = array(), $reference_ID = false, $echo = true) {
|
8 |
global $yarpp;
|
9 |
|
@@ -15,6 +23,13 @@ function yarpp_related($args = array(), $reference_ID = false, $echo = true) {
|
|
15 |
return $yarpp->display_related($reference_ID, $args, $echo);
|
16 |
}
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
function yarpp_related_exist($args = array(), $reference_ID = false) {
|
19 |
global $yarpp;
|
20 |
|
@@ -26,12 +41,29 @@ function yarpp_related_exist($args = array(), $reference_ID = false) {
|
|
26 |
return $yarpp->related_exist($reference_ID, $args);
|
27 |
}
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
function yarpp_get_related($args = array(), $reference_ID = false) {
|
30 |
global $yarpp;
|
31 |
return $yarpp->get_related($reference_ID, $args);
|
32 |
}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
function related_posts($args = array(), $reference_ID = false, $echo = true) {
|
|
|
35 |
global $yarpp;
|
36 |
|
37 |
if ( false !== $reference_ID && is_bool($reference_ID) ) {
|
@@ -48,7 +80,16 @@ function related_posts($args = array(), $reference_ID = false, $echo = true) {
|
|
48 |
return yarpp_related($args, $reference_ID, $echo);
|
49 |
}
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
function related_pages($args = array(), $reference_ID = false, $echo = true) {
|
|
|
52 |
global $yarpp;
|
53 |
|
54 |
if (false !== $reference_ID && is_bool($reference_ID)) {
|
@@ -65,7 +106,16 @@ function related_pages($args = array(), $reference_ID = false, $echo = true) {
|
|
65 |
return yarpp_related($args, $reference_ID, $echo);
|
66 |
}
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
function related_entries($args = array(), $reference_ID = false, $echo = true) {
|
|
|
69 |
global $yarpp;
|
70 |
|
71 |
if (false !== $reference_ID && is_bool($reference_ID)) {
|
@@ -78,7 +128,15 @@ function related_entries($args = array(), $reference_ID = false, $echo = true) {
|
|
78 |
return yarpp_related($args, $reference_ID, $echo);
|
79 |
}
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
function related_posts_exist($args = array(), $reference_ID = false) {
|
|
|
82 |
global $yarpp;
|
83 |
|
84 |
if ($yarpp->get_option('cross_relate')) {
|
@@ -90,7 +148,15 @@ function related_posts_exist($args = array(), $reference_ID = false) {
|
|
90 |
return yarpp_related_exist($args, $reference_ID);
|
91 |
}
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
function related_pages_exist($args = array(), $reference_ID = false) {
|
|
|
94 |
global $yarpp;
|
95 |
|
96 |
if ($yarpp->get_option('cross_relate')) {
|
@@ -102,7 +168,15 @@ function related_pages_exist($args = array(), $reference_ID = false) {
|
|
102 |
return yarpp_related_exist( $args, $reference_ID );
|
103 |
}
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
function related_entries_exist($args = array(),$reference_ID = false) {
|
|
|
106 |
global $yarpp;
|
107 |
|
108 |
$args['post_type'] = $yarpp->get_post_types();
|
4 |
Since YARPP 2.1, these functions receive (optionally) one array argument.
|
5 |
----------------------------------------------------------------------------------------------------------------------*/
|
6 |
|
7 |
+
/**
|
8 |
+
* Gets the HTML for displaying related posts.
|
9 |
+
* @param array $args
|
10 |
+
* @param int $reference_ID the post ID to search against. If used from within "the loop", defaults to the
|
11 |
+
* $current_post
|
12 |
+
* @param bool $echo if false only returns the HTML string
|
13 |
+
* @return string HTML output
|
14 |
+
*/
|
15 |
function yarpp_related($args = array(), $reference_ID = false, $echo = true) {
|
16 |
global $yarpp;
|
17 |
|
23 |
return $yarpp->display_related($reference_ID, $args, $echo);
|
24 |
}
|
25 |
|
26 |
+
/**
|
27 |
+
* Whether there are any related posts.
|
28 |
+
* @param array $args
|
29 |
+
* @param int $reference_ID the post ID to search against. If used from within "the loop", defaults to the
|
30 |
+
* $current_post
|
31 |
+
* @return bool
|
32 |
+
*/
|
33 |
function yarpp_related_exist($args = array(), $reference_ID = false) {
|
34 |
global $yarpp;
|
35 |
|
41 |
return $yarpp->related_exist($reference_ID, $args);
|
42 |
}
|
43 |
|
44 |
+
/**
|
45 |
+
* Gets an array of related posts.
|
46 |
+
*
|
47 |
+
* @param array $args
|
48 |
+
* @param int $reference_ID the post ID to search against. If used from within "the loop", defaults to the
|
49 |
+
* $current_post
|
50 |
+
*
|
51 |
+
* @return WP_Post[]
|
52 |
+
*/
|
53 |
function yarpp_get_related($args = array(), $reference_ID = false) {
|
54 |
global $yarpp;
|
55 |
return $yarpp->get_related($reference_ID, $args);
|
56 |
}
|
57 |
|
58 |
+
/**
|
59 |
+
* @deprecated 5.12.0 use yarpp_related instead
|
60 |
+
*
|
61 |
+
* @param array $args
|
62 |
+
* @param bool $reference_ID
|
63 |
+
* @param bool $echo
|
64 |
+
*/
|
65 |
function related_posts($args = array(), $reference_ID = false, $echo = true) {
|
66 |
+
_deprecated_function('related_posts','5.12.0', 'yarpp_related');
|
67 |
global $yarpp;
|
68 |
|
69 |
if ( false !== $reference_ID && is_bool($reference_ID) ) {
|
80 |
return yarpp_related($args, $reference_ID, $echo);
|
81 |
}
|
82 |
|
83 |
+
/**
|
84 |
+
*
|
85 |
+
* @deprecated since 5.12.0 use yarpp_related() instead
|
86 |
+
* @param array $args
|
87 |
+
* @param bool $reference_ID
|
88 |
+
* @param bool $echo
|
89 |
+
* @return array
|
90 |
+
*/
|
91 |
function related_pages($args = array(), $reference_ID = false, $echo = true) {
|
92 |
+
_deprecated_function('related_pages','5.12.0', 'yarpp_related');
|
93 |
global $yarpp;
|
94 |
|
95 |
if (false !== $reference_ID && is_bool($reference_ID)) {
|
106 |
return yarpp_related($args, $reference_ID, $echo);
|
107 |
}
|
108 |
|
109 |
+
/**
|
110 |
+
* @deprecated since 5.12.0 use yarpp_related() instead
|
111 |
+
* @param array $args
|
112 |
+
* @param int $reference_ID
|
113 |
+
* @param bool $echo
|
114 |
+
*
|
115 |
+
* @return string|void
|
116 |
+
*/
|
117 |
function related_entries($args = array(), $reference_ID = false, $echo = true) {
|
118 |
+
_deprecated_function('related_entries','5.12.0', 'yarpp_related');
|
119 |
global $yarpp;
|
120 |
|
121 |
if (false !== $reference_ID && is_bool($reference_ID)) {
|
128 |
return yarpp_related($args, $reference_ID, $echo);
|
129 |
}
|
130 |
|
131 |
+
/**
|
132 |
+
* @deprecated since 5.12.0 use yarpp_related_exist() instead
|
133 |
+
* @param array $args
|
134 |
+
* @param int $reference_ID
|
135 |
+
*
|
136 |
+
* @return bool
|
137 |
+
*/
|
138 |
function related_posts_exist($args = array(), $reference_ID = false) {
|
139 |
+
_deprecated_function('related_posts_exist','5.12.0', 'yarpp_related_exist');
|
140 |
global $yarpp;
|
141 |
|
142 |
if ($yarpp->get_option('cross_relate')) {
|
148 |
return yarpp_related_exist($args, $reference_ID);
|
149 |
}
|
150 |
|
151 |
+
/**
|
152 |
+
* @deprecated since 5.12.0 use yarpp_related_exist() instead
|
153 |
+
* @param array $args
|
154 |
+
* @param bool $reference_ID
|
155 |
+
*
|
156 |
+
* @return bool
|
157 |
+
*/
|
158 |
function related_pages_exist($args = array(), $reference_ID = false) {
|
159 |
+
_deprecated_function('related_pages_exist','5.12.0', 'yarpp_related_exist');
|
160 |
global $yarpp;
|
161 |
|
162 |
if ($yarpp->get_option('cross_relate')) {
|
168 |
return yarpp_related_exist( $args, $reference_ID );
|
169 |
}
|
170 |
|
171 |
+
/**
|
172 |
+
* @deprecated since 5.12.0 use yarpp_related_exist() instead
|
173 |
+
* @param array $args
|
174 |
+
* @param bool $reference_ID
|
175 |
+
*
|
176 |
+
* @return bool
|
177 |
+
*/
|
178 |
function related_entries_exist($args = array(),$reference_ID = false) {
|
179 |
+
_deprecated_function('related_entries_exist','5.12.0', 'yarpp_related_exist');
|
180 |
global $yarpp;
|
181 |
|
182 |
$args['post_type'] = $yarpp->get_post_types();
|
js/metabox.js
CHANGED
@@ -13,23 +13,28 @@ jQuery(document).ready(function($) {
|
|
13 |
|
14 |
if (!loaded_metabox) {
|
15 |
loaded_metabox = true;
|
16 |
-
yarpp_metabox_populate();
|
17 |
}
|
18 |
}
|
19 |
|
20 |
/*
|
21 |
* Populates Metabox
|
|
|
22 |
*/
|
23 |
-
function yarpp_metabox_populate() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
$.ajax({
|
25 |
type:'POST',
|
26 |
url: ajaxurl,
|
27 |
-
data:
|
28 |
-
action: 'yarpp_display',
|
29 |
-
domain: 'metabox',
|
30 |
-
ID: parseInt($('#post_ID').val()),
|
31 |
-
'_ajax_nonce': $('#yarpp_display-nonce').val()
|
32 |
-
},
|
33 |
error: function() {
|
34 |
display.html("Error");
|
35 |
},
|
@@ -73,7 +78,7 @@ jQuery(document).ready(function($) {
|
|
73 |
$spinner.css( 'visibility', 'visible' );
|
74 |
|
75 |
$('#yarpp-list').css( 'opacity', 0.6 );
|
76 |
-
yarpp_metabox_populate();
|
77 |
});
|
78 |
|
79 |
/*
|
13 |
|
14 |
if (!loaded_metabox) {
|
15 |
loaded_metabox = true;
|
16 |
+
yarpp_metabox_populate(false);
|
17 |
}
|
18 |
}
|
19 |
|
20 |
/*
|
21 |
* Populates Metabox
|
22 |
+
* @param bool refresh
|
23 |
*/
|
24 |
+
function yarpp_metabox_populate(refresh) {
|
25 |
+
var data = {
|
26 |
+
action: 'yarpp_display',
|
27 |
+
domain: 'metabox',
|
28 |
+
ID: parseInt($('#post_ID').val()),
|
29 |
+
'_ajax_nonce': $('#yarpp_display-nonce').val()
|
30 |
+
};
|
31 |
+
if(typeof refresh !== 'undefined' && refresh){
|
32 |
+
data['refresh'] = true;
|
33 |
+
}
|
34 |
$.ajax({
|
35 |
type:'POST',
|
36 |
url: ajaxurl,
|
37 |
+
data: data,
|
|
|
|
|
|
|
|
|
|
|
38 |
error: function() {
|
39 |
display.html("Error");
|
40 |
},
|
78 |
$spinner.css( 'visibility', 'visible' );
|
79 |
|
80 |
$('#yarpp-list').css( 'opacity', 0.6 );
|
81 |
+
yarpp_metabox_populate(true);
|
82 |
});
|
83 |
|
84 |
/*
|
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.6
|
8 |
-
Stable tag: 5.
|
9 |
|
10 |
The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
|
11 |
|
@@ -78,6 +78,10 @@ If you know the reference Post ID that you want to show content related to, use:
|
|
78 |
|
79 |
`[yarpp reference_id=123]` to show content related to post 123
|
80 |
|
|
|
|
|
|
|
|
|
81 |
The add YARRP related posts to your theme files (eg. single.php), we recommend using:
|
82 |
|
83 |
`<?php echo do_shortcode('[yarpp]'); ?>`
|
@@ -97,7 +101,7 @@ Most likely you have "no related posts" right now because the default "match thr
|
|
97 |
|
98 |
If you do not want to show the Related Posts display in its default position (right below the post content), first go to YARPP options and turn off the "automatically display" options in the "website" section. If you would like to instead display it in your sidebar and you have a widget-aware theme, YARPP provides a Related Posts widget which you can add under "Appearance" > "Widgets."
|
99 |
|
100 |
-
If you would like to add the Related Posts display elsewhere, edit your relevant theme file (most likely something like `single.php`) and add the shortcode code `[yarpp]` (recommended) or PHP function `
|
101 |
|
102 |
= How can I limit related posts to a certain time frame? For instance, I don't want to show posts from two years ago. =
|
103 |
|
@@ -117,9 +121,7 @@ Some WordPress themes treat the home page as an archive or a "page." Go to "Sett
|
|
117 |
|
118 |
= How can I prevent the "related posts" list from displaying on specific posts? =
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
You could also add `<!--noyarpp-->` to the HTML code of any post to prevent related posts from displaying. This solution will only work if you are using "Automatic Display" in the "Display Options" section. If you are programatically calling `related_posts()` or the shortcode `[yarpp]` from PHP code, you'll have to do your own checking to see if related posts are appropriate to display or not.
|
123 |
|
124 |
= I'm using the Thumbnails display in YARPP 4. How do I override the style of the text that displays? The title only shows two lines, the font is larger than I'd like, I'd like to center the thumbnails, etc. =
|
125 |
|
@@ -261,6 +263,17 @@ If you need to use related entries programmatically or to know whether they exis
|
|
261 |
|
262 |
Note that custom YARPP queries using the functions mentioned here are *not* cached in the built-in YARPP caching system. Thus, if you notice any performance hits, you may need to write your own code to cache the results.
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
= Does YARPP support custom taxonomies? =
|
265 |
|
266 |
Yes. Any taxonomy, including custom taxonomies, may be specified in the `weight` or `require_tax` arguments in a custom display as above. `term_taxonomy_id` specified in the `exclude` argument may be of any taxonomy.
|
@@ -296,6 +309,12 @@ add_action(
|
|
296 |
`
|
297 |
|
298 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
= 5.11.0 (08-February-2021) =
|
300 |
* [New](https://wordpress.org/support/topic/why-related-topics-doesnt-show-up-under-topics-and-replies/): Adds native support for bbPress! Have you ever wanted a nifty Related Posts section on your bbPress topic pages, like the ones you've seen on forums like StackOverflow? It's now possible with YARPP Related Posts!
|
301 |
* Enhancement: Updates to provided custom template examples
|
@@ -1060,5 +1079,5 @@ After a break of many years, the plugin is 100% supported now that the baton has
|
|
1060 |
* Initial upload
|
1061 |
|
1062 |
== Upgrade Notice ==
|
1063 |
-
= 5.
|
1064 |
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!
|
5 |
Requires PHP: 5.3
|
6 |
License: GPLv2 or later
|
7 |
Tested up to: 5.6
|
8 |
+
Stable tag: 5.12.0
|
9 |
|
10 |
The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
|
11 |
|
78 |
|
79 |
`[yarpp reference_id=123]` to show content related to post 123
|
80 |
|
81 |
+
To specify which YARPP template to use, use the "template" attribute like so:
|
82 |
+
|
83 |
+
`[yarpp template="yarpp-template-photoblog"]`
|
84 |
+
|
85 |
The add YARRP related posts to your theme files (eg. single.php), we recommend using:
|
86 |
|
87 |
`<?php echo do_shortcode('[yarpp]'); ?>`
|
101 |
|
102 |
If you do not want to show the Related Posts display in its default position (right below the post content), first go to YARPP options and turn off the "automatically display" options in the "website" section. If you would like to instead display it in your sidebar and you have a widget-aware theme, YARPP provides a Related Posts widget which you can add under "Appearance" > "Widgets."
|
103 |
|
104 |
+
If you would like to add the Related Posts display elsewhere, edit your relevant theme file (most likely something like `single.php`) and add the shortcode code `[yarpp]` (recommended) or PHP function `yarpp_related();` within [The Loop](https://codex.wordpress.org/The_Loop) where you want to display the related posts. Make sure you don't add `echo yarpp_related();` or you may end up with duplicates in your related posts section.
|
105 |
|
106 |
= How can I limit related posts to a certain time frame? For instance, I don't want to show posts from two years ago. =
|
107 |
|
121 |
|
122 |
= How can I prevent the "related posts" list from displaying on specific posts? =
|
123 |
|
124 |
+
Add `<!--noyarpp-->` to the HTML code of any post to prevent related posts from displaying. This solution will only work if you are using "Automatic Display" in the "Display Options" section. If you are programatically calling `yarpp_related()` or the shortcode `[yarpp]` from PHP code, you'll have to do your own checking to see if related posts are appropriate to display or not.
|
|
|
|
|
125 |
|
126 |
= I'm using the Thumbnails display in YARPP 4. How do I override the style of the text that displays? The title only shows two lines, the font is larger than I'd like, I'd like to center the thumbnails, etc. =
|
127 |
|
263 |
|
264 |
Note that custom YARPP queries using the functions mentioned here are *not* cached in the built-in YARPP caching system. Thus, if you notice any performance hits, you may need to write your own code to cache the results.
|
265 |
|
266 |
+
Here is an example of how to use a custom YARPP query and cache the results for a day:
|
267 |
+
|
268 |
+
`
|
269 |
+
$result = get_transient('yarpp_custom_results_for_' . $post->ID);
|
270 |
+
if(! $result){
|
271 |
+
$result = yarpp_related(['post_type' => 'reply'],null,false);
|
272 |
+
set_transient('yarpp_custom_results_for_' . $post->ID, $result, DAY_IN_SECONDS);
|
273 |
+
}
|
274 |
+
echo $result;
|
275 |
+
`
|
276 |
+
|
277 |
= Does YARPP support custom taxonomies? =
|
278 |
|
279 |
Yes. Any taxonomy, including custom taxonomies, may be specified in the `weight` or `require_tax` arguments in a custom display as above. `term_taxonomy_id` specified in the `exclude` argument may be of any taxonomy.
|
309 |
`
|
310 |
|
311 |
== Changelog ==
|
312 |
+
= 5.12.0 (22-February-2021) =
|
313 |
+
* New shortcode template attribute. Eg [yarpp template="yarpp-template-photoblog"]
|
314 |
+
* Deprecated: functions related_posts, related_pages, related_entries (use yarpp_related instead), and related_posts_exist, related_pages_exist and related_entries_exist (use yarpp_related_exist instead)
|
315 |
+
* Bugfix: consistently use "post_type" parameter and "cross-relate" from all YARPP functions
|
316 |
+
* [Bugfix](https://wordpress.org/support/topic/cannot-be-translated-because-there-is-no-text-domain-description/): Add textdomain to allow translating the readme file
|
317 |
+
|
318 |
= 5.11.0 (08-February-2021) =
|
319 |
* [New](https://wordpress.org/support/topic/why-related-topics-doesnt-show-up-under-topics-and-replies/): Adds native support for bbPress! Have you ever wanted a nifty Related Posts section on your bbPress topic pages, like the ones you've seen on forums like StackOverflow? It's now possible with YARPP Related Posts!
|
320 |
* Enhancement: Updates to provided custom template examples
|
1079 |
* Initial upload
|
1080 |
|
1081 |
== Upgrade Notice ==
|
1082 |
+
= 5.12.0 =
|
1083 |
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!
|
yarpp.php
CHANGED
@@ -2,10 +2,11 @@
|
|
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.
|
6 |
Author: YARPP
|
7 |
Author URI: https://yarpp.com/
|
8 |
Plugin URI: https://yarpp.com/
|
|
|
9 |
*/
|
10 |
|
11 |
/**
|
@@ -23,7 +24,7 @@ if(!defined('WP_CONTENT_DIR')){
|
|
23 |
define('WP_CONTENT_DIR', substr($tr,0,strrpos($tr,'/')));
|
24 |
}
|
25 |
|
26 |
-
define('YARPP_VERSION', '5.
|
27 |
|
28 |
define('YARPP_DIR', dirname(__FILE__));
|
29 |
/**
|
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.12.0
|
6 |
Author: YARPP
|
7 |
Author URI: https://yarpp.com/
|
8 |
Plugin URI: https://yarpp.com/
|
9 |
+
Text Domain: yarpp
|
10 |
*/
|
11 |
|
12 |
/**
|
24 |
define('WP_CONTENT_DIR', substr($tr,0,strrpos($tr,'/')));
|
25 |
}
|
26 |
|
27 |
+
define('YARPP_VERSION', '5.12.0');
|
28 |
|
29 |
define('YARPP_DIR', dirname(__FILE__));
|
30 |
/**
|