Version Description
(19-April-2021) =
* New: Choose image size for YARPP Thumbnail theme
* Bugfix: Resolves join
warning (Part 2/2)
Download this release
Release Info
Developer | jeffparker |
Plugin | Yet Another Related Posts Plugin (YARPP) |
Version | 5.18.1 |
Comparing to | |
See all releases |
Code changes from version 5.17.0 to 5.18.1
- classes/YARPP_Cache.php +12 -13
- classes/YARPP_Core.php +14 -3
- classes/YARPP_Meta_Box.php +4 -0
- classes/YARPP_Meta_Box_Display_Feed.php +11 -2
- classes/YARPP_Meta_Box_Display_Rest_Api.php +10 -10
- classes/YARPP_Meta_Box_Display_Web.php +9 -0
- classes/YARPP_Rest_Api.php +70 -68
- classes/YARPP_Shortcode.php +6 -6
- includes/init_functions.php +79 -0
- includes/phtmls/yarpp_meta_box_radio.phtml +12 -0
- includes/yarpp_meta_boxes_hooks.php +9 -11
- readme.txt +14 -10
- uninstall.php +41 -37
- yarpp.php +2 -2
classes/YARPP_Cache.php
CHANGED
@@ -312,19 +312,18 @@ abstract class YARPP_Cache {
|
|
312 |
}
|
313 |
|
314 |
private function tax_criteria($reference_ID, $taxonomy) {
|
315 |
-
$terms = get_the_terms($reference_ID, $taxonomy);
|
316 |
-
// if there are no terms of that tax
|
317 |
-
if (
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
);
|
327 |
-
return "count(distinct if( terms.term_taxonomy_id in (".join(',',$tt_ids)."), terms.term_taxonomy_id, null ))";
|
328 |
}
|
329 |
/*
|
330 |
* KEYWORDS
|
312 |
}
|
313 |
|
314 |
private function tax_criteria($reference_ID, $taxonomy) {
|
315 |
+
$terms = get_the_terms( $reference_ID, $taxonomy );
|
316 |
+
// if there are no terms of that tax or WP error.
|
317 |
+
if ( is_wp_error( $terms ) || false === $terms ) {
|
318 |
+
return '(1 = 0)';
|
319 |
+
}
|
320 |
+
$make_term_object_to_array = wp_list_pluck( $terms, 'term_taxonomy_id' );
|
321 |
+
// If empty then return.
|
322 |
+
if ( empty( $make_term_object_to_array ) ) {
|
323 |
+
return '(1 = 0)';
|
324 |
+
}
|
325 |
+
$tt_ids = join( ',', $make_term_object_to_array );
|
326 |
+
return "count(distinct if( terms.term_taxonomy_id in (" . $tt_ids . "), terms.term_taxonomy_id, null ))";
|
|
|
327 |
}
|
328 |
/*
|
329 |
* KEYWORDS
|
classes/YARPP_Core.php
CHANGED
@@ -100,8 +100,9 @@ class YARPP {
|
|
100 |
/**
|
101 |
* If we're using thumbnails, register yarpp-thumbnail size, if theme has not already.
|
102 |
* Note: see FAQ in the readme if you would like to change the YARPP thumbnail size.
|
|
|
103 |
*/
|
104 |
-
if (
|
105 |
$width = 120;
|
106 |
$height = 120;
|
107 |
$crop = true;
|
@@ -199,6 +200,8 @@ class YARPP {
|
|
199 |
'pools' => array(),
|
200 |
'manually_using_thumbnails' => false,
|
201 |
'rest_api_display' => true,
|
|
|
|
|
202 |
'rest_api_client_side_caching' => false,
|
203 |
'yarpp_rest_api_cache_time' => 15
|
204 |
);
|
@@ -504,8 +507,16 @@ class YARPP {
|
|
504 |
global $_wp_additional_image_sizes;
|
505 |
if (!isset($_wp_additional_image_sizes['yarpp-thumbnail'])) return $this->default_dimensions;
|
506 |
|
507 |
-
|
508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
|
510 |
/* Ensure YARPP dimensions format: */
|
511 |
$dimensions['width'] = (int) $dimensions['width'];
|
100 |
/**
|
101 |
* If we're using thumbnails, register yarpp-thumbnail size, if theme has not already.
|
102 |
* Note: see FAQ in the readme if you would like to change the YARPP thumbnail size.
|
103 |
+
* If theme has already yarpp-thumbnail size registered and we also try to register yarpp-thumbnail then it will throw a fatal error. So it is necessary to check if yarpp-thumbnail size is not registered.
|
104 |
*/
|
105 |
+
if ( false === yarpp_get_image_sizes( 'yarpp-thumbnail' ) ) {
|
106 |
$width = 120;
|
107 |
$height = 120;
|
108 |
$crop = true;
|
200 |
'pools' => array(),
|
201 |
'manually_using_thumbnails' => false,
|
202 |
'rest_api_display' => true,
|
203 |
+
'thumbnail_size_display' => 0,
|
204 |
+
'thumbnail_size_feed_display' => 0,
|
205 |
'rest_api_client_side_caching' => false,
|
206 |
'yarpp_rest_api_cache_time' => 15
|
207 |
);
|
507 |
global $_wp_additional_image_sizes;
|
508 |
if (!isset($_wp_additional_image_sizes['yarpp-thumbnail'])) return $this->default_dimensions;
|
509 |
|
510 |
+
// get user selected thumbnail size.
|
511 |
+
if ( is_feed() ) {
|
512 |
+
$dimensions = yarpp_get_thumbnail_image_dimensions( 'thumbnail_size_feed_display' );
|
513 |
+
} else {
|
514 |
+
$dimensions = yarpp_get_thumbnail_image_dimensions();
|
515 |
+
}
|
516 |
+
if ( empty($dimensions) ) {
|
517 |
+
$dimensions = $_wp_additional_image_sizes['yarpp-thumbnail'];
|
518 |
+
$dimensions['size'] = 'yarpp-thumbnail';
|
519 |
+
}
|
520 |
|
521 |
/* Ensure YARPP dimensions format: */
|
522 |
$dimensions['width'] = (int) $dimensions['width'];
|
classes/YARPP_Meta_Box.php
CHANGED
@@ -25,6 +25,10 @@ class YARPP_Meta_Box {
|
|
25 |
public function checkbox($option, $desc, $class = null) {
|
26 |
include(YARPP_DIR.'/includes/phtmls/yarpp_meta_box_checkbox.phtml');
|
27 |
}
|
|
|
|
|
|
|
|
|
28 |
|
29 |
public function template_checkbox($rss=false, $class = null) {
|
30 |
$pre = ($rss) ? 'rss_' : '';
|
25 |
public function checkbox($option, $desc, $class = null) {
|
26 |
include(YARPP_DIR.'/includes/phtmls/yarpp_meta_box_checkbox.phtml');
|
27 |
}
|
28 |
+
|
29 |
+
public function radio($option, $desc, $class = null, $value = null) {
|
30 |
+
include( YARPP_DIR . '/includes/phtmls/yarpp_meta_box_radio.phtml' );
|
31 |
+
}
|
32 |
|
33 |
public function template_checkbox($rss=false, $class = null) {
|
34 |
$pre = ($rss) ? 'rss_' : '';
|
classes/YARPP_Meta_Box_Display_Feed.php
CHANGED
@@ -37,8 +37,17 @@ class YARPP_Meta_Box_Display_Feed extends YARPP_Meta_Box {
|
|
37 |
echo ">";
|
38 |
$this->textbox( 'rss_thumbnails_heading', __( 'Heading:', 'yarpp' ), 40 );
|
39 |
$this->textbox( 'rss_thumbnails_default', __( 'Default image (URL):', 'yarpp' ), 40 );
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
echo "<div class='yarpp_subbox template_options_builtin'";
|
43 |
if ( $choice != 'builtin' )
|
44 |
echo ' style="display: none;"';
|
37 |
echo ">";
|
38 |
$this->textbox( 'rss_thumbnails_heading', __( 'Heading:', 'yarpp' ), 40 );
|
39 |
$this->textbox( 'rss_thumbnails_default', __( 'Default image (URL):', 'yarpp' ), 40 );
|
40 |
+
$get_image_sizes = yarpp_get_image_sizes();
|
41 |
+
echo '<div class="yarpp_form_row yarpp_form_radio_label">';
|
42 |
+
echo '<div class="yarpp_form_label">' . esc_html( 'Thumbnail Size', 'yarpp' ) . '</div><div>';
|
43 |
+
foreach ( $get_image_sizes as $key => $_size ) {
|
44 |
+
/* translators: %s: thumbnail key's name */
|
45 |
+
$name = sprintf( __( '%1$s (%2$s X %3$s)', 'yarpp' ), $key, $_size['width'], $_size['height'] );
|
46 |
+
$this->radio( 'thumbnail_size_feed_display', $name, '', $key );
|
47 |
+
}
|
48 |
+
echo '</div></div>';
|
49 |
+
echo "</div>";
|
50 |
+
|
51 |
echo "<div class='yarpp_subbox template_options_builtin'";
|
52 |
if ( $choice != 'builtin' )
|
53 |
echo ' style="display: none;"';
|
classes/YARPP_Meta_Box_Display_Rest_Api.php
CHANGED
@@ -1,19 +1,19 @@
|
|
1 |
<?php
|
2 |
|
3 |
class YARPP_Meta_Box_Display_Rest_Api extends YARPP_Meta_Box {
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
echo '<div class="yarpp_rest_browser_cache_displayed">';
|
10 |
$this->textbox('yarpp_rest_api_cache_time', __('Cache time (in minutes)', 'yarpp'));
|
11 |
echo '</div>';
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
}
|
1 |
<?php
|
2 |
|
3 |
class YARPP_Meta_Box_Display_Rest_Api extends YARPP_Meta_Box {
|
4 |
+
public function display() {
|
5 |
|
6 |
+
$this->checkbox( 'rest_api_display', __( 'Display related posts in REST API?', 'yarpp' ) . " <span class='yarpp_help dashicons dashicons-editor-help' data-help='" . esc_attr( __( 'This option adds related posts to the REST API.', 'yarpp' ) ) . "'> </span>", '' );
|
7 |
+
echo "<div class='yarpp_rest_displayed'>";
|
8 |
+
$this->checkbox( 'rest_api_client_side_caching', __( 'Enable in-browser caching?', 'yarpp' ) . " <span class='yarpp_help dashicons dashicons-editor-help' data-help='" . esc_attr( __( 'Web browsers will be instructed to cache YARPP REST API results. This can dramatically increase the speed of subsequent YARPP REST API requests, but it also means stale content might be served for the length of the cache time.', 'yarpp' ) ) . "'> </span>", '' );
|
9 |
echo '<div class="yarpp_rest_browser_cache_displayed">';
|
10 |
$this->textbox('yarpp_rest_api_cache_time', __('Cache time (in minutes)', 'yarpp'));
|
11 |
echo '</div>';
|
12 |
|
13 |
+
echo '<a href="https://support.shareaholic.com/hc/en-us/articles/360046456752">';
|
14 |
+
esc_html_e('YARPP REST API documentation →', 'yarpp');
|
15 |
+
echo '</a>';
|
16 |
|
17 |
+
echo '</div>';
|
18 |
+
}
|
19 |
+
}
|
classes/YARPP_Meta_Box_Display_Web.php
CHANGED
@@ -58,6 +58,15 @@ class YARPP_Meta_Box_Display_Web extends YARPP_Meta_Box {
|
|
58 |
echo ">";
|
59 |
$this->textbox( 'thumbnails_heading', __( 'Heading:', 'yarpp' ), 40 );
|
60 |
$this->textbox( 'thumbnails_default', __( 'Default image (URL):', 'yarpp' ), 40 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
echo "</div>";
|
62 |
|
63 |
echo "<div class='yarpp_subbox template_options_builtin'";
|
58 |
echo ">";
|
59 |
$this->textbox( 'thumbnails_heading', __( 'Heading:', 'yarpp' ), 40 );
|
60 |
$this->textbox( 'thumbnails_default', __( 'Default image (URL):', 'yarpp' ), 40 );
|
61 |
+
$get_image_sizes = yarpp_get_image_sizes();
|
62 |
+
echo '<div class="yarpp_form_row yarpp_form_radio_label">';
|
63 |
+
echo '<div class="yarpp_form_label">' . esc_html( 'Thumbnail Size', 'yarpp' ) . '</div><div>';
|
64 |
+
foreach ( $get_image_sizes as $key => $_size ) {
|
65 |
+
/* translators: %s: thumbnail key's name */
|
66 |
+
$name = sprintf( __( '%1$s (%2$sx%3$s)', 'yarpp' ), $key, $_size['width'], $_size['height'] );
|
67 |
+
$this->radio( 'thumbnail_size_display', $name, '', $key );
|
68 |
+
}
|
69 |
+
echo '</div></div>';
|
70 |
echo "</div>";
|
71 |
|
72 |
echo "<div class='yarpp_subbox template_options_builtin'";
|
classes/YARPP_Rest_Api.php
CHANGED
@@ -3,11 +3,11 @@
|
|
3 |
/**
|
4 |
* YARPP rest api functionality
|
5 |
*/
|
6 |
-
class YARPP_Rest_Api extends WP_REST_Controller{
|
7 |
|
8 |
public function __construct() {
|
9 |
add_action('rest_api_init', array($this, 'register_api_routes'));
|
10 |
-
add_filter('wp_rest_cache/allowed_endpoints', array($this,'cache_endpoints'),10,1);
|
11 |
}
|
12 |
|
13 |
/**
|
@@ -18,65 +18,65 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
18 |
/**
|
19 |
* Initializes yarpp rest routes via rest_api_init
|
20 |
*/
|
21 |
-
|
22 |
global $yarpp;
|
23 |
|
24 |
-
|
25 |
-
|
26 |
|
27 |
/* Register the yarpp rest route */
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
));
|
43 |
-
|
44 |
-
|
45 |
|
46 |
/**
|
47 |
* Wraps WP_REST_Posts_Controller's schema, and adds YARPP-specific fields.
|
48 |
*
|
49 |
* @return array
|
50 |
*/
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
|
62 |
/**
|
63 |
* @param WP_REST_Request $request
|
64 |
*
|
65 |
* @return WP_Error
|
66 |
*/
|
67 |
-
public function get_item_permissions_check($request) {
|
68 |
$error_response = new WP_Error(
|
69 |
'rest_forbidden_context',
|
70 |
__( 'Sorry, you are not allowed to read this post.', 'yarpp' ),
|
71 |
array( 'status' => rest_authorization_required_code() )
|
72 |
);
|
73 |
-
$post_obj
|
74 |
-
if(! $this->get_posts_controller($post_obj->post_type)->check_read_permission($post_obj)){
|
75 |
return $error_response;
|
76 |
}
|
77 |
|
78 |
$core_permissions_check = $this->get_posts_controller()->get_items_permissions_check($request);
|
79 |
-
if($core_permissions_check instanceof WP_Error){
|
80 |
return $core_permissions_check;
|
81 |
}
|
82 |
// Check for password-protected posts.
|
@@ -130,28 +130,28 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
130 |
* @param WP_REST_REQUEST $request Incoming HTTP request data.
|
131 |
* @return WP_Error|WP_HTTP_Response
|
132 |
*/
|
133 |
-
public function get_related_posts($request) {
|
134 |
/**
|
135 |
* @var $yarpp YARPP
|
136 |
*/
|
137 |
global $yarpp;
|
138 |
|
139 |
$query_params = $request->get_params();
|
140 |
-
$id
|
141 |
|
142 |
$post_obj = get_post($id);
|
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 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
$related_posts = $yarpp->get_related(
|
156 |
$id,
|
157 |
$args
|
@@ -159,8 +159,8 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
159 |
|
160 |
// Great, we have the posts we want. But they're formatted totally differently than the WP REST API endpoints
|
161 |
// So we use the core WP_RESTS_Posts_Controller to get the response in exactly the same format.
|
162 |
-
$ids
|
163 |
-
$read_controller
|
164 |
$simulated_request = clone $request;
|
165 |
$simulated_request->set_route('wp/v1/posts');
|
166 |
|
@@ -170,7 +170,7 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
170 |
// we only get one page at a time. WP page numbering starts at 1.
|
171 |
'page' => 1
|
172 |
);
|
173 |
-
if(isset($query_params['context'])){
|
174 |
$simulated_params['context'] = $query_params['context'];
|
175 |
}
|
176 |
|
@@ -181,41 +181,42 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
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;
|
186 |
}
|
187 |
$read_controller_posts = $read_controller_response->get_data();
|
188 |
-
$ordered_rest_results
|
189 |
// Reorder the posts in the response according to what they were in the YARPP response.
|
190 |
-
foreach($related_posts as $related_post){
|
191 |
-
foreach($read_controller_posts as $read_controller_post){
|
192 |
-
if($related_post->ID === $read_controller_post['id']){
|
193 |
// Add score, but before _links.
|
194 |
$links = $read_controller_post['_links'];
|
195 |
unset($read_controller_post['_links']);
|
196 |
-
$read_controller_post['score']
|
197 |
$read_controller_post['_links'] = $links;
|
198 |
-
$ordered_rest_results[]
|
199 |
}
|
200 |
}
|
201 |
}
|
202 |
$read_controller_response->set_data($ordered_rest_results);
|
203 |
$this->maybe_set_caching_headers($read_controller_response);
|
204 |
return $read_controller_response;
|
205 |
-
|
206 |
|
207 |
/**
|
208 |
* If enables, sends HTTP headers along with the response that instructs the browser to cache the results.
|
|
|
209 |
* @param WP_Rest_Response $response
|
210 |
*/
|
211 |
-
|
212 |
global $yarpp;
|
213 |
if ($yarpp->get_option('rest_api_client_side_caching')) {
|
214 |
-
$seconds_to_cache = (int)$yarpp->get_option('yarpp_rest_api_cache_time') * MINUTE_IN_SECONDS;
|
215 |
$seconds_to_cache = max($seconds_to_cache, 0); // ensure non-negative values
|
216 |
-
$ts
|
217 |
-
$response->header(
|
218 |
-
$response->header(
|
219 |
}
|
220 |
}
|
221 |
|
@@ -224,12 +225,12 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
224 |
*
|
225 |
* @return WP_REST_Posts_Controller
|
226 |
*/
|
227 |
-
|
228 |
-
if( ! $this->posts_controller instanceof WP_REST_Posts_Controller){
|
229 |
$this->posts_controller = new WP_REST_Posts_Controller($post_type);
|
230 |
}
|
231 |
return $this->posts_controller;
|
232 |
-
|
233 |
|
234 |
/**
|
235 |
* Register the /wp-json/yarpp/v1/related for caching with https://wordpress.org/plugins/wp-rest-cache/
|
@@ -246,14 +247,15 @@ class YARPP_Rest_Api extends WP_REST_Controller{
|
|
246 |
* This way we can ask the posts controller for all posts of any type (remember we're only fetching ones with
|
247 |
* IDs that match the results of YARPP's related query.) The results are all formatted like posts, which isn't
|
248 |
* stellar, but it's got the important info.
|
|
|
249 |
* @param $args
|
250 |
* @param $request
|
251 |
*
|
252 |
* @return mixed
|
253 |
*/
|
254 |
-
public function ignore_post_type_filter_callback( $args, $request ){
|
255 |
global $yarpp;
|
256 |
$args['post_type'] = $yarpp->get_post_types();
|
257 |
return $args;
|
258 |
-
|
259 |
-
}
|
3 |
/**
|
4 |
* YARPP rest api functionality
|
5 |
*/
|
6 |
+
class YARPP_Rest_Api extends WP_REST_Controller {
|
7 |
|
8 |
public function __construct() {
|
9 |
add_action('rest_api_init', array($this, 'register_api_routes'));
|
10 |
+
add_filter('wp_rest_cache/allowed_endpoints', array($this,'cache_endpoints'), 10, 1);
|
11 |
}
|
12 |
|
13 |
/**
|
18 |
/**
|
19 |
* Initializes yarpp rest routes via rest_api_init
|
20 |
*/
|
21 |
+
function register_api_routes() {
|
22 |
global $yarpp;
|
23 |
|
24 |
+
if ($yarpp->get_option('rest_api_display')) {
|
25 |
+
$NAMESPACE = 'yarpp/v1';
|
26 |
|
27 |
/* Register the yarpp rest route */
|
28 |
+
register_rest_route( $NAMESPACE, '/related/(?P<id>[\w-]+)', array(
|
29 |
+
array(
|
30 |
+
'methods' => WP_REST_Server::READABLE,
|
31 |
+
'callback' => array($this,'get_related_posts'),
|
32 |
+
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
33 |
+
'args' => $this->get_related_posts_args()
|
34 |
+
),
|
35 |
+
'args' => array(
|
36 |
+
'id' => array(
|
37 |
+
'description' => __( 'Unique identifier for the object.' ),
|
38 |
+
'type' => 'integer',
|
39 |
+
),
|
40 |
+
),
|
41 |
+
'schema' => array( $this, 'get_public_item_schema' ),
|
42 |
));
|
43 |
+
}
|
44 |
+
}
|
45 |
|
46 |
/**
|
47 |
* Wraps WP_REST_Posts_Controller's schema, and adds YARPP-specific fields.
|
48 |
*
|
49 |
* @return array
|
50 |
*/
|
51 |
+
public function get_public_item_schema() {
|
52 |
+
$posts_schema = $this->get_posts_controller('post')->get_public_item_schema();
|
53 |
+
$posts_schema['properties']['score'] = array(
|
54 |
+
'description' => __('YARPP relatedness score', 'yarpp'),
|
55 |
+
'type' => 'number',
|
56 |
+
'context' => array('view', 'edit', 'embed'),
|
57 |
+
'readonly' => true,
|
58 |
+
);
|
59 |
+
return $posts_schema;
|
60 |
+
}
|
61 |
|
62 |
/**
|
63 |
* @param WP_REST_Request $request
|
64 |
*
|
65 |
* @return WP_Error
|
66 |
*/
|
67 |
+
public function get_item_permissions_check( $request) {
|
68 |
$error_response = new WP_Error(
|
69 |
'rest_forbidden_context',
|
70 |
__( 'Sorry, you are not allowed to read this post.', 'yarpp' ),
|
71 |
array( 'status' => rest_authorization_required_code() )
|
72 |
);
|
73 |
+
$post_obj = get_post($request->get_param('id'));
|
74 |
+
if (! $this->get_posts_controller($post_obj->post_type)->check_read_permission($post_obj)) {
|
75 |
return $error_response;
|
76 |
}
|
77 |
|
78 |
$core_permissions_check = $this->get_posts_controller()->get_items_permissions_check($request);
|
79 |
+
if ($core_permissions_check instanceof WP_Error) {
|
80 |
return $core_permissions_check;
|
81 |
}
|
82 |
// Check for password-protected posts.
|
130 |
* @param WP_REST_REQUEST $request Incoming HTTP request data.
|
131 |
* @return WP_Error|WP_HTTP_Response
|
132 |
*/
|
133 |
+
public function get_related_posts( $request) {
|
134 |
/**
|
135 |
* @var $yarpp YARPP
|
136 |
*/
|
137 |
global $yarpp;
|
138 |
|
139 |
$query_params = $request->get_params();
|
140 |
+
$id = $query_params['id'];
|
141 |
|
142 |
$post_obj = get_post($id);
|
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(
|
149 |
+
$query_params,
|
150 |
+
function( $key) use ( $allowed_args) {
|
151 |
+
return in_array($key, $allowed_args);
|
152 |
+
},
|
153 |
+
ARRAY_FILTER_USE_KEY
|
154 |
+
);
|
155 |
$related_posts = $yarpp->get_related(
|
156 |
$id,
|
157 |
$args
|
159 |
|
160 |
// Great, we have the posts we want. But they're formatted totally differently than the WP REST API endpoints
|
161 |
// So we use the core WP_RESTS_Posts_Controller to get the response in exactly the same format.
|
162 |
+
$ids = wp_list_pluck( $related_posts, 'ID' );
|
163 |
+
$read_controller = $this->get_posts_controller($post_obj->post_type);
|
164 |
$simulated_request = clone $request;
|
165 |
$simulated_request->set_route('wp/v1/posts');
|
166 |
|
170 |
// we only get one page at a time. WP page numbering starts at 1.
|
171 |
'page' => 1
|
172 |
);
|
173 |
+
if (isset($query_params['context'])) {
|
174 |
$simulated_params['context'] = $query_params['context'];
|
175 |
}
|
176 |
|
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;
|
186 |
}
|
187 |
$read_controller_posts = $read_controller_response->get_data();
|
188 |
+
$ordered_rest_results = array();
|
189 |
// Reorder the posts in the response according to what they were in the YARPP response.
|
190 |
+
foreach ($related_posts as $related_post) {
|
191 |
+
foreach ($read_controller_posts as $read_controller_post) {
|
192 |
+
if ($related_post->ID === $read_controller_post['id']) {
|
193 |
// Add score, but before _links.
|
194 |
$links = $read_controller_post['_links'];
|
195 |
unset($read_controller_post['_links']);
|
196 |
+
$read_controller_post['score'] = (float) $related_post->score;
|
197 |
$read_controller_post['_links'] = $links;
|
198 |
+
$ordered_rest_results[] = $read_controller_post;
|
199 |
}
|
200 |
}
|
201 |
}
|
202 |
$read_controller_response->set_data($ordered_rest_results);
|
203 |
$this->maybe_set_caching_headers($read_controller_response);
|
204 |
return $read_controller_response;
|
205 |
+
}
|
206 |
|
207 |
/**
|
208 |
* If enables, sends HTTP headers along with the response that instructs the browser to cache the results.
|
209 |
+
*
|
210 |
* @param WP_Rest_Response $response
|
211 |
*/
|
212 |
+
protected function maybe_set_caching_headers( WP_Rest_Response $response) {
|
213 |
global $yarpp;
|
214 |
if ($yarpp->get_option('rest_api_client_side_caching')) {
|
215 |
+
$seconds_to_cache = (int) $yarpp->get_option('yarpp_rest_api_cache_time') * MINUTE_IN_SECONDS;
|
216 |
$seconds_to_cache = max($seconds_to_cache, 0); // ensure non-negative values
|
217 |
+
$ts = gmdate('D, d M Y H:i:s', time() + $seconds_to_cache) . ' GMT';
|
218 |
+
$response->header('Expires', $ts);
|
219 |
+
$response->header('Cache-Control', "public, max-age=$seconds_to_cache");
|
220 |
}
|
221 |
}
|
222 |
|
225 |
*
|
226 |
* @return WP_REST_Posts_Controller
|
227 |
*/
|
228 |
+
protected function get_posts_controller( $post_type = null) {
|
229 |
+
if ( ! $this->posts_controller instanceof WP_REST_Posts_Controller) {
|
230 |
$this->posts_controller = new WP_REST_Posts_Controller($post_type);
|
231 |
}
|
232 |
return $this->posts_controller;
|
233 |
+
}
|
234 |
|
235 |
/**
|
236 |
* Register the /wp-json/yarpp/v1/related for caching with https://wordpress.org/plugins/wp-rest-cache/
|
247 |
* This way we can ask the posts controller for all posts of any type (remember we're only fetching ones with
|
248 |
* IDs that match the results of YARPP's related query.) The results are all formatted like posts, which isn't
|
249 |
* stellar, but it's got the important info.
|
250 |
+
*
|
251 |
* @param $args
|
252 |
* @param $request
|
253 |
*
|
254 |
* @return mixed
|
255 |
*/
|
256 |
+
public function ignore_post_type_filter_callback( $args, $request ) {
|
257 |
global $yarpp;
|
258 |
$args['post_type'] = $yarpp->get_post_types();
|
259 |
return $args;
|
260 |
+
}
|
261 |
+
}
|
classes/YARPP_Shortcode.php
CHANGED
@@ -22,7 +22,7 @@ class YARPP_Shortcode {
|
|
22 |
*
|
23 |
* @return string
|
24 |
*/
|
25 |
-
public function render($atts) {
|
26 |
$atts = shortcode_atts(
|
27 |
array(
|
28 |
'reference_id' => null,
|
@@ -32,18 +32,18 @@ class YARPP_Shortcode {
|
|
32 |
);
|
33 |
/** @global $yarpp YARPP */
|
34 |
global $yarpp;
|
35 |
-
$post
|
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,
|
@@ -53,4 +53,4 @@ class YARPP_Shortcode {
|
|
53 |
}
|
54 |
|
55 |
}
|
56 |
-
}
|
22 |
*
|
23 |
* @return string
|
24 |
*/
|
25 |
+
public function render( $atts) {
|
26 |
$atts = shortcode_atts(
|
27 |
array(
|
28 |
'reference_id' => null,
|
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,
|
53 |
}
|
54 |
|
55 |
}
|
56 |
+
}
|
includes/init_functions.php
CHANGED
@@ -18,6 +18,85 @@ function yarpp_get_option($option = null) {
|
|
18 |
global $yarpp;
|
19 |
return $yarpp->get_option($option);
|
20 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
/**
|
22 |
* Given a minified path, and a non-minified path, will return
|
23 |
* a minified or non-minified file URL based on whether SCRIPT_DEBUG is set true or not.
|
18 |
global $yarpp;
|
19 |
return $yarpp->get_option($option);
|
20 |
}
|
21 |
+
/**
|
22 |
+
* Get user selected thumbnail size.
|
23 |
+
*
|
24 |
+
* @param string $option option name.
|
25 |
+
* @param string $default_option default thumbnail size name.
|
26 |
+
* @return string name of thumbnail.
|
27 |
+
*/
|
28 |
+
function yarpp_get_option_thumbnail( $option = null, $default_option = 'thumbnail' ) {
|
29 |
+
$get_template = yarpp_get_option( 'template' );
|
30 |
+
$user_selected_thumbnail = yarpp_get_option( $option );
|
31 |
+
/**
|
32 |
+
* If existing user upgrades to v5.18.1 then continue using YARPP-thumbnail as default option.
|
33 |
+
* If this is a fresh install then YARPP will use "thumbnail" (WordPress default) because this is always available and does not require images to regenerate.
|
34 |
+
* Lastly, fallback to the provided fallback default.
|
35 |
+
*/
|
36 |
+
if ( empty( $user_selected_thumbnail ) && 'thumbnails' === $get_template ) {
|
37 |
+
$thumbnail_size = 'yarpp-thumbnail';
|
38 |
+
} elseif ( ! empty( $user_selected_thumbnail ) && 'thumbnails' === $get_template ) {
|
39 |
+
// Ensure user selected thumbnail is still registered.
|
40 |
+
global $_wp_additional_image_sizes;
|
41 |
+
if (isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && !isset($_wp_additional_image_sizes[$user_selected_thumbnail])){
|
42 |
+
$thumbnail_size = 'yarpp-thumbnail';
|
43 |
+
} else {
|
44 |
+
$thumbnail_size = $user_selected_thumbnail;
|
45 |
+
}
|
46 |
+
} else {
|
47 |
+
$thumbnail_size = $default_option;
|
48 |
+
}
|
49 |
+
return $thumbnail_size;
|
50 |
+
}
|
51 |
+
/**
|
52 |
+
* Get user selected thumbnail dimension.
|
53 |
+
*
|
54 |
+
* @param string $size thumbnail size.
|
55 |
+
* @return array user selected thumbnail dimension.
|
56 |
+
*/
|
57 |
+
function yarpp_get_thumbnail_image_dimensions( $size = 'thumbnail_size_display' ) {
|
58 |
+
$user_thumbnail_choice = yarpp_get_option_thumbnail( $size );
|
59 |
+
$dimensions = yarpp_get_image_sizes( $user_thumbnail_choice );
|
60 |
+
$dimensions['size'] = $user_thumbnail_choice;
|
61 |
+
/* Ensure thumbnail dimensions format: */
|
62 |
+
$dimensions['width'] = (int) $dimensions['width'];
|
63 |
+
$dimensions['height'] = (int) $dimensions['height'];
|
64 |
+
return $dimensions;
|
65 |
+
}
|
66 |
+
/**
|
67 |
+
* Get information about available image sizes.
|
68 |
+
*
|
69 |
+
* @param string $size thumbnail size.
|
70 |
+
* @return string[] An array of image size names.
|
71 |
+
*/
|
72 |
+
function yarpp_get_image_sizes( $size = '' ) {
|
73 |
+
$wp_additional_image_sizes = wp_get_additional_image_sizes();
|
74 |
+
$sizes = array();
|
75 |
+
$get_intermediate_image_sizes = get_intermediate_image_sizes();
|
76 |
+
// Create the full array with sizes and crop info.
|
77 |
+
foreach ( $get_intermediate_image_sizes as $_size ) {
|
78 |
+
if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ), true ) ) {
|
79 |
+
$sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
|
80 |
+
$sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
|
81 |
+
$sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
|
82 |
+
} elseif ( isset( $wp_additional_image_sizes[ $_size ] ) ) {
|
83 |
+
$sizes[ $_size ] = array(
|
84 |
+
'width' => $wp_additional_image_sizes[ $_size ]['width'],
|
85 |
+
'height' => $wp_additional_image_sizes[ $_size ]['height'],
|
86 |
+
'crop' => $wp_additional_image_sizes[ $_size ]['crop']
|
87 |
+
);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
// Get only 1 size if found.
|
91 |
+
if ( $size ) {
|
92 |
+
if ( isset( $sizes[ $size ] ) ) {
|
93 |
+
return $sizes[ $size ];
|
94 |
+
} else {
|
95 |
+
return false;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
return $sizes;
|
99 |
+
}
|
100 |
/**
|
101 |
* Given a minified path, and a non-minified path, will return
|
102 |
* a minified or non-minified file URL based on whether SCRIPT_DEBUG is set true or not.
|
includes/phtmls/yarpp_meta_box_radio.phtml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="yarpp_form_row yarpp_form_radio <?php esc_attr_e( $class ) ?>">
|
2 |
+
<div>
|
3 |
+
<input
|
4 |
+
type="radio"
|
5 |
+
name="<?php esc_attr_e( $option ) ?>"
|
6 |
+
id="yarpp-<?php esc_attr_e( $option.'_'.$value ) ?>"
|
7 |
+
value="<?php esc_attr_e( $value ) ?>"
|
8 |
+
<?php checked( $value === yarpp_get_option_thumbnail($option, 'thumbnail')) ?>
|
9 |
+
/>
|
10 |
+
<label for="yarpp-<?php echo $option.'_'.$value ?>"><?php echo $desc ?></label>
|
11 |
+
</div>
|
12 |
+
</div>
|
includes/yarpp_meta_boxes_hooks.php
CHANGED
@@ -43,6 +43,15 @@ add_meta_box(
|
|
43 |
'core'
|
44 |
);
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
add_meta_box(
|
47 |
'yarpp_display_rss',
|
48 |
__('RSS Feed Options', 'yarpp'),
|
@@ -74,17 +83,6 @@ if(
|
|
74 |
);
|
75 |
}
|
76 |
|
77 |
-
|
78 |
-
add_meta_box(
|
79 |
-
'yarpp_display_contact',
|
80 |
-
__('Contact YARPP', 'yarpp'),
|
81 |
-
array(new YARPP_Meta_Box_Contact, 'display'),
|
82 |
-
'settings_page_yarpp',
|
83 |
-
'side',
|
84 |
-
'core'
|
85 |
-
);
|
86 |
-
|
87 |
-
|
88 |
function yarpp_make_optin_classy($classes) {
|
89 |
if (!yarpp_get_option('optin') )
|
90 |
$classes[] = 'yarpp_attention';
|
43 |
'core'
|
44 |
);
|
45 |
|
46 |
+
add_meta_box(
|
47 |
+
'yarpp_display_contact',
|
48 |
+
__('Contact YARPP', 'yarpp'),
|
49 |
+
array(new YARPP_Meta_Box_Contact, 'display'),
|
50 |
+
'settings_page_yarpp',
|
51 |
+
'side',
|
52 |
+
'core'
|
53 |
+
);
|
54 |
+
|
55 |
add_meta_box(
|
56 |
'yarpp_display_rss',
|
57 |
__('RSS Feed Options', 'yarpp'),
|
83 |
);
|
84 |
}
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
function yarpp_make_optin_classy($classes) {
|
87 |
if (!yarpp_get_option('optin') )
|
88 |
$classes[] = 'yarpp_attention';
|
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.7
|
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 |
|
@@ -209,7 +209,7 @@ Before upgrading to a new WordPress version, you should first deactivate all plu
|
|
209 |
|
210 |
= Can I clear my cache? Can I build up the cache manually? =
|
211 |
|
212 |
-
|
213 |
|
214 |
= I removed the YARPP plugin but I still see YARPP-related database tables. Shouldn't those be removed, too? =
|
215 |
|
@@ -313,29 +313,33 @@ add_action(
|
|
313 |
`
|
314 |
|
315 |
== Changelog ==
|
|
|
|
|
|
|
|
|
316 |
= 5.17.0 (06-April-2021) =
|
317 |
-
* [New](https://wordpress.org/support/topic/unable-to-dequeue-related-css-stylesheet/):
|
318 |
`
|
319 |
add_filter( 'yarpp_enqueue_related_style', '_\_return_false' );
|
320 |
`
|
321 |
-
* New:
|
322 |
|
323 |
= 5.16.1 (29-March-2021) =
|
324 |
* Bugfix: include new minified JS files
|
325 |
|
326 |
= 5.16.0 (29-March-2021) =
|
327 |
-
* Enhancement:
|
328 |
-
* [Bugfix](https://wordpress.org/support/topic/cannot-save-changes-spinning-forever/):
|
329 |
-
* [Bugfix](https://wordpress.org/support/topic/warning-message-yarpp_cache-php/):
|
330 |
|
331 |
= 5.15.3 (15-March-2021) =
|
332 |
-
* Enhancement:
|
333 |
|
334 |
= 5.15.2 (12-March-2021) =
|
335 |
* Tested up to WordPress 5.7
|
336 |
|
337 |
= 5.15.1 (11-March-2021) =
|
338 |
-
* Bugfix:
|
339 |
|
340 |
= 5.15.0 (11-March-2021) =
|
341 |
* [Enhancement](https://wordpress.org/support/topic/5-14-0-rendered-our-site-unusable/): Default to not comparing using titles and bodies and only add database indexes when they are enabled to improve performance
|
@@ -1125,5 +1129,5 @@ After a break of many years, the plugin is 100% supported now that the baton has
|
|
1125 |
* Initial upload
|
1126 |
|
1127 |
== Upgrade Notice ==
|
1128 |
-
= 5.
|
1129 |
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.7
|
8 |
+
Stable tag: 5.18.1
|
9 |
|
10 |
The most popular plugin to display a list of related posts on your site based on a powerful unique algorithm.
|
11 |
|
209 |
|
210 |
= Can I clear my cache? Can I build up the cache manually? =
|
211 |
|
212 |
+
Yes, there is a button to clear YARPP's cache table in YARPP's WP Admin options.
|
213 |
|
214 |
= I removed the YARPP plugin but I still see YARPP-related database tables. Shouldn't those be removed, too? =
|
215 |
|
313 |
`
|
314 |
|
315 |
== Changelog ==
|
316 |
+
= 5.18.1 (19-April-2021) =
|
317 |
+
* New: Choose image size for YARPP Thumbnail theme
|
318 |
+
* [Bugfix](https://wordpress.org/support/topic/warning-message-yarpp_cache-php/): Resolves `join` warning (Part 2/2)
|
319 |
+
|
320 |
= 5.17.0 (06-April-2021) =
|
321 |
+
* [New](https://wordpress.org/support/topic/unable-to-dequeue-related-css-stylesheet/): Adds filter to be able to dequeue related.css
|
322 |
`
|
323 |
add_filter( 'yarpp_enqueue_related_style', '_\_return_false' );
|
324 |
`
|
325 |
+
* New: Adds friendly per-post meta box options to disable YARPP automatic display on a specific post
|
326 |
|
327 |
= 5.16.1 (29-March-2021) =
|
328 |
* Bugfix: include new minified JS files
|
329 |
|
330 |
= 5.16.0 (29-March-2021) =
|
331 |
+
* Enhancement: Switches to minified JavaScript in YARPP Admin for a speed boost
|
332 |
+
* [Bugfix](https://wordpress.org/support/topic/cannot-save-changes-spinning-forever/): Resolves conflict with Easy Forms for MailChimp which was preventing YARPP settings from being saved
|
333 |
+
* [Bugfix](https://wordpress.org/support/topic/warning-message-yarpp_cache-php/): Resolves `join` warning (Part 1/2)
|
334 |
|
335 |
= 5.15.3 (15-March-2021) =
|
336 |
+
* Enhancement: Improves readability of the database indexes prompt
|
337 |
|
338 |
= 5.15.2 (12-March-2021) =
|
339 |
* Tested up to WordPress 5.7
|
340 |
|
341 |
= 5.15.1 (11-March-2021) =
|
342 |
+
* Bugfix: Fixes issue pushing 5.15.0
|
343 |
|
344 |
= 5.15.0 (11-March-2021) =
|
345 |
* [Enhancement](https://wordpress.org/support/topic/5-14-0-rendered-our-site-unusable/): Default to not comparing using titles and bodies and only add database indexes when they are enabled to improve performance
|
1129 |
* Initial upload
|
1130 |
|
1131 |
== Upgrade Notice ==
|
1132 |
+
= 5.18.1 =
|
1133 |
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!
|
uninstall.php
CHANGED
@@ -2,72 +2,76 @@
|
|
2 |
/**
|
3 |
* Uninstall procedure.
|
4 |
* Last update 2013-12-09
|
|
|
5 |
* @since Version 4.0.7
|
6 |
* @author Eliezer Vargas
|
7 |
*/
|
8 |
|
9 |
/* Exit if plugin delete hasn't be called */
|
10 |
-
if (!defined('WP_UNINSTALL_PLUGIN'))
|
|
|
|
|
11 |
|
12 |
global $wpdb;
|
13 |
|
14 |
/* Yarpp option names */
|
15 |
$optNames = array(
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
);
|
28 |
|
29 |
/* Select right procedure for single or multi site */
|
30 |
-
if(is_multisite()) {
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
|
46 |
} else {
|
47 |
|
48 |
-
|
49 |
|
50 |
}/*end if*/
|
51 |
|
52 |
|
53 |
/**
|
54 |
* Loop through option array and delete the option and clear and drop cache tables.
|
|
|
55 |
* @param array $opts Array of yarpp's options
|
56 |
-
* @param object $wpdb
|
57 |
*/
|
58 |
-
function clean(
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
|
73 |
-
}/*end clean */
|
2 |
/**
|
3 |
* Uninstall procedure.
|
4 |
* Last update 2013-12-09
|
5 |
+
*
|
6 |
* @since Version 4.0.7
|
7 |
* @author Eliezer Vargas
|
8 |
*/
|
9 |
|
10 |
/* Exit if plugin delete hasn't be called */
|
11 |
+
if (!defined('WP_UNINSTALL_PLUGIN')) {
|
12 |
+
exit();
|
13 |
+
}
|
14 |
|
15 |
global $wpdb;
|
16 |
|
17 |
/* Yarpp option names */
|
18 |
$optNames = array(
|
19 |
+
'yarpp',
|
20 |
+
'yarpp_pro',
|
21 |
+
'yarpp_fulltext_disabled',
|
22 |
+
'yarpp_optin_timeout',
|
23 |
+
'yarpp_version',
|
24 |
+
'yarpp_version_info',
|
25 |
+
'yarpp_version_info_timeout',
|
26 |
+
'yarpp_activated',
|
27 |
+
'widget_yarpp_widget',
|
28 |
+
'yarpp_upgraded',
|
29 |
+
'yarpp_activate_timestamp'
|
30 |
);
|
31 |
|
32 |
/* Select right procedure for single or multi site */
|
33 |
+
if (is_multisite()) {
|
34 |
|
35 |
+
/* Get sites ids */
|
36 |
+
$blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
|
37 |
|
38 |
+
/* Get main site id */
|
39 |
+
$original_blog_id = get_current_blog_id();
|
40 |
|
41 |
+
/* loop through all sites */
|
42 |
+
foreach ($blog_ids as $blog_id) {
|
43 |
+
switch_to_blog($blog_id);
|
44 |
+
clean($optNames, $wpdb);
|
45 |
+
}/*end foreach*/
|
46 |
|
47 |
+
switch_to_blog($original_blog_id);
|
48 |
|
49 |
} else {
|
50 |
|
51 |
+
clean($optNames, $wpdb);
|
52 |
|
53 |
}/*end if*/
|
54 |
|
55 |
|
56 |
/**
|
57 |
* Loop through option array and delete the option and clear and drop cache tables.
|
58 |
+
*
|
59 |
* @param array $opts Array of yarpp's options
|
60 |
+
* @param object $wpdb WordPress db global
|
61 |
*/
|
62 |
+
function clean( array $opts, $wpdb) {
|
63 |
|
64 |
+
foreach ($opts as $opt) {
|
65 |
+
delete_option($opt);
|
66 |
+
}
|
67 |
|
68 |
+
/* Truncate, clear and drop yarpp cache */
|
69 |
+
$wpdb->query('DELETE FROM `' . $wpdb->prefix . 'postmeta` WHERE meta_key LIKE "%yarpp%"');
|
70 |
+
$wpdb->query('TRUNCATE TABLE `' . $wpdb->prefix . 'yarpp_related_cache`');
|
71 |
+
wp_cache_flush();
|
72 |
+
$wpdb->query('DROP TABLE `' . $wpdb->prefix . 'yarpp_related_cache`');
|
73 |
|
74 |
+
/* Delete users yarpp related data */
|
75 |
+
$wpdb->query('DELETE FROM `' . $wpdb->prefix . 'usermeta` WHERE meta_key LIKE "%yarpp%"');
|
76 |
|
77 |
+
}/*end clean */
|
yarpp.php
CHANGED
@@ -2,7 +2,7 @@
|
|
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/
|
@@ -24,7 +24,7 @@ if(!defined('WP_CONTENT_DIR')){
|
|
24 |
define('WP_CONTENT_DIR', substr($tr,0,strrpos($tr,'/')));
|
25 |
}
|
26 |
|
27 |
-
define('YARPP_VERSION', '5.
|
28 |
|
29 |
define('YARPP_DIR', dirname(__FILE__));
|
30 |
/**
|
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.18.1
|
6 |
Author: YARPP
|
7 |
Author URI: https://yarpp.com/
|
8 |
Plugin URI: https://yarpp.com/
|
24 |
define('WP_CONTENT_DIR', substr($tr,0,strrpos($tr,'/')));
|
25 |
}
|
26 |
|
27 |
+
define('YARPP_VERSION', '5.18.1');
|
28 |
|
29 |
define('YARPP_DIR', dirname(__FILE__));
|
30 |
/**
|