Version Description
- Changed default thumbnail title to image file name
- Bug fixes for thumbnailer
- Fixed compatibility issues with Open Graph plugins
Download this release
Release Info
Developer | zemanta-panco |
Plugin | WordPress Related Posts |
Version | 3.3.2 |
Comparing to | |
See all releases |
Code changes from version 3.3.1 to 3.3.2
- config.php +9 -3
- readme.txt +6 -1
- recommendations.php +1 -2
- thumbnailer.php +32 -26
- wp_related_posts.php +3 -3
config.php
CHANGED
@@ -243,15 +243,21 @@ function wp_rp_is_classic() {
|
|
243 |
return false;
|
244 |
}
|
245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
function wp_rp_migrate_3_3() {
|
247 |
global $wpdb;
|
248 |
|
249 |
$wp_rp_meta = get_option('wp_rp_meta');
|
250 |
$wp_rp_meta['version'] = '3.3.1';
|
251 |
$wp_rp_meta['new_user'] = false;
|
252 |
-
if (floatval($wp_rp_meta['first_version']) < 2.8 && strpos(get_bloginfo('language'), 'en') === 0) { // Enable widget to all "old" users out there (old = users that started with plugin version 2.7 or below), that have their interface in english.
|
253 |
-
$wp_rp_meta['classic_user'] = true;
|
254 |
-
}
|
255 |
$wp_rp_options = get_option('wp_rp_options');
|
256 |
$wp_rp_options['only_admins_can_edit_related_posts'] = false;
|
257 |
update_option('wp_rp_meta', $wp_rp_meta);
|
243 |
return false;
|
244 |
}
|
245 |
|
246 |
+
function wp_rp_migrate_3_3_1() {
|
247 |
+
global $wpdb;
|
248 |
+
|
249 |
+
$wp_rp_meta = get_option('wp_rp_meta');
|
250 |
+
$wp_rp_meta['version'] = '3.3.2';
|
251 |
+
$wp_rp_meta['new_user'] = false;
|
252 |
+
update_option('wp_rp_meta', $wp_rp_meta);
|
253 |
+
}
|
254 |
+
|
255 |
function wp_rp_migrate_3_3() {
|
256 |
global $wpdb;
|
257 |
|
258 |
$wp_rp_meta = get_option('wp_rp_meta');
|
259 |
$wp_rp_meta['version'] = '3.3.1';
|
260 |
$wp_rp_meta['new_user'] = false;
|
|
|
|
|
|
|
261 |
$wp_rp_options = get_option('wp_rp_options');
|
262 |
$wp_rp_options['only_admins_can_edit_related_posts'] = false;
|
263 |
update_option('wp_rp_meta', $wp_rp_meta);
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: related,posts,post,related posts,plugin
|
|
4 |
License: GPLv2
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 3.8
|
7 |
-
Stable tag: 3.3.
|
8 |
|
9 |
WordPress Related Posts generates a list of related posts with thumbnails and gives you click-through statistics.
|
10 |
|
@@ -82,6 +82,11 @@ Fix for security vulnerability. Upgrade immediately.
|
|
82 |
|
83 |
== Changelog ==
|
84 |
|
|
|
|
|
|
|
|
|
|
|
85 |
= 3.3.1 =
|
86 |
* Added setting for admins to restrict the ability to edit automatically added Related posts to admins only
|
87 |
* Getting ready to reorganize settings page
|
4 |
License: GPLv2
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 3.8
|
7 |
+
Stable tag: 3.3.2
|
8 |
|
9 |
WordPress Related Posts generates a list of related posts with thumbnails and gives you click-through statistics.
|
10 |
|
82 |
|
83 |
== Changelog ==
|
84 |
|
85 |
+
= 3.3.2 =
|
86 |
+
* Changed default thumbnail title to image file name
|
87 |
+
* Bug fixes for thumbnailer
|
88 |
+
* Fixed compatibility issues with Open Graph plugins
|
89 |
+
|
90 |
= 3.3.1 =
|
91 |
* Added setting for admins to restrict the ability to edit automatically added Related posts to admins only
|
92 |
* Getting ready to reorganize settings page
|
recommendations.php
CHANGED
@@ -165,7 +165,6 @@ function wp_rp_fetch_related_posts_v2($limit = 10, $exclude_ids = array()) {
|
|
165 |
$related_posts_query_result_cache = get_post_meta($post->ID, '_wp_rp_related_posts_query_result_cache_'.$options['max_related_posts'], true);
|
166 |
|
167 |
if (!$related_posts_query_result_cache || !$related_posts_query_result_cache_expiration || $related_posts_query_result_cache_expiration < $timestamp) { // Cache empty or never cached or cache expired
|
168 |
-
|
169 |
$related_post_ids = null;
|
170 |
$exclude_ids_str = wp_rp_get_exclude_ids_list_string($exclude_ids);
|
171 |
|
@@ -230,7 +229,7 @@ function wp_rp_fetch_related_posts_v2($limit = 10, $exclude_ids = array()) {
|
|
230 |
}
|
231 |
|
232 |
// Update the cache
|
233 |
-
if ($timestamp - $post->post_date > 30 * 24 * 60 * 60) { // Post is older than one month
|
234 |
update_post_meta($post->ID, '_wp_rp_related_posts_query_result_cache_expiration', $timestamp + 30 * 24 * 60 * 60); // Cache for one month
|
235 |
} else {
|
236 |
update_post_meta($post->ID, '_wp_rp_related_posts_query_result_cache_expiration', $timestamp + 24 * 60 * 60); // Cache for one day
|
165 |
$related_posts_query_result_cache = get_post_meta($post->ID, '_wp_rp_related_posts_query_result_cache_'.$options['max_related_posts'], true);
|
166 |
|
167 |
if (!$related_posts_query_result_cache || !$related_posts_query_result_cache_expiration || $related_posts_query_result_cache_expiration < $timestamp) { // Cache empty or never cached or cache expired
|
|
|
168 |
$related_post_ids = null;
|
169 |
$exclude_ids_str = wp_rp_get_exclude_ids_list_string($exclude_ids);
|
170 |
|
229 |
}
|
230 |
|
231 |
// Update the cache
|
232 |
+
if ($timestamp - strtotime($post->post_date) > 30 * 24 * 60 * 60) { // Post is older than one month
|
233 |
update_post_meta($post->ID, '_wp_rp_related_posts_query_result_cache_expiration', $timestamp + 30 * 24 * 60 * 60); // Cache for one month
|
234 |
} else {
|
235 |
update_post_meta($post->ID, '_wp_rp_related_posts_query_result_cache_expiration', $timestamp + 24 * 60 * 60); // Cache for one day
|
thumbnailer.php
CHANGED
@@ -70,7 +70,7 @@ function wp_rp_upload_attachment($url, $post_id) {
|
|
70 |
|
71 |
$post_data = array(
|
72 |
'guid' => $url,
|
73 |
-
'post_title' => '
|
74 |
);
|
75 |
|
76 |
$attachment_id = media_handle_sideload($file_array, $post_id, null, $post_data);
|
@@ -138,26 +138,9 @@ function wp_rp_update_attachment_id($attachment_id) {
|
|
138 |
$platform_options = wp_rp_get_platform_options();
|
139 |
if (!$img_path) { return false; }
|
140 |
|
141 |
-
if (!empty($platform_options['custom_size_thumbnail_enabled'])) {
|
142 |
-
// generate_attachment_metadata works with media thumbnail settings only
|
143 |
-
// store user's options to restore them after update
|
144 |
-
$media_thumb_width = get_option('thumbnail_size_w');
|
145 |
-
$media_thumb_height = get_option('thumbnail_size_h');
|
146 |
-
$media_crop = get_option('thumbnail_crop');
|
147 |
-
update_option('thumbnail_size_w', $platform_options['custom_thumbnail_width']);
|
148 |
-
update_option('thumbnail_size_h', $platform_options['custom_thumbnail_height']);
|
149 |
-
update_option('thumbnail_crop', 1);
|
150 |
-
}
|
151 |
-
|
152 |
$attach_data = wp_generate_attachment_metadata($attachment_id, $img_path);
|
153 |
wp_update_attachment_metadata($attachment_id, $attach_data);
|
154 |
|
155 |
-
if (!empty($platform_options['custom_size_thumbnail_enabled'])) {
|
156 |
-
update_option('thumbnail_size_w', $media_thumb_width);
|
157 |
-
update_option('thumbnail_size_h', $media_thumb_height);
|
158 |
-
update_option('thumbnail_crop', $media_crop);
|
159 |
-
}
|
160 |
-
|
161 |
return $attachment_id;
|
162 |
}
|
163 |
|
@@ -184,7 +167,9 @@ function wp_rp_cron_do_extract_images_from_post($post_id, $attachment_id) {
|
|
184 |
add_action('wp_rp_cron_extract_images_from_post', 'wp_rp_cron_do_extract_images_from_post', 10, 2);
|
185 |
|
186 |
function wp_rp_extract_images_from_post($post, $attachment_id=null) {
|
187 |
-
|
|
|
|
|
188 |
|
189 |
delete_post_meta($post->ID, '_wp_rp_image');
|
190 |
wp_schedule_single_event(time(), 'wp_rp_cron_extract_images_from_post', array($post->ID, $attachment_id));
|
@@ -205,6 +190,10 @@ function wp_rp_post_save_update_image($post_id) {
|
|
205 |
delete_post_meta($post->ID, '_wp_rp_image');
|
206 |
|
207 |
wp_rp_get_post_thumbnail_img($post);
|
|
|
|
|
|
|
|
|
208 |
}
|
209 |
add_action('save_post', 'wp_rp_post_save_update_image');
|
210 |
|
@@ -242,11 +231,32 @@ function wp_rp_get_image_with_exact_size($image_data, $size) {
|
|
242 |
|
243 |
$img_url = wp_get_attachment_url($image_data['id']);
|
244 |
$img_url_basename = wp_basename($img_url);
|
|
|
245 |
|
246 |
// Calculate exact dimensions for proportional images
|
247 |
if (!$size[0]) { $size[0] = (int) ($image_data['data']['width'] / $image_data['data']['height'] * $size[1]); }
|
248 |
if (!$size[1]) { $size[1] = (int) ($image_data['data']['height'] / $image_data['data']['width'] * $size[0]); }
|
249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
foreach ($image_data['data']['sizes'] as $_size => $data) {
|
251 |
// width and height can be both string and integers. WordPress..
|
252 |
if (($size[0] == $data['width']) && ($size[1] == $data['height'])) {
|
@@ -266,7 +276,6 @@ function wp_rp_get_image_with_exact_size($image_data, $size) {
|
|
266 |
|
267 |
function wp_rp_get_image_data($image_id) {
|
268 |
if (!$image_id || is_wp_error($image_id)) { return false; }
|
269 |
-
|
270 |
$imagedata = wp_get_attachment_metadata($image_id);
|
271 |
if (!$imagedata || !is_array($imagedata) || !isset($imagedata['sizes']) || !is_array($imagedata['sizes'])) {
|
272 |
return false;
|
@@ -308,7 +317,6 @@ function wp_rp_get_attached_img_url($related_post, $size) {
|
|
308 |
wp_rp_extract_images_from_post($related_post);
|
309 |
return false;
|
310 |
}
|
311 |
-
|
312 |
if ($img_src = wp_rp_get_image_with_exact_size($image_data, $size)) {
|
313 |
return $img_src['url'];
|
314 |
}
|
@@ -399,12 +407,10 @@ function wp_rp_img_html_to_post_id( $html, &$matched_html = null ) {
|
|
399 |
if ( ! preg_match_all( '#class=([\'"])(.+?)\1#is', $matched_html, $matches ) || empty( $matches ) )
|
400 |
return $attachment_id;
|
401 |
|
402 |
-
$
|
403 |
-
foreach ( $matches[1] as $key => $attribute_name )
|
404 |
-
$attr[ $attribute_name ] = $matches[2][ $key ];
|
405 |
|
406 |
-
if ( ! $attachment_id && ! empty( $
|
407 |
-
if ( preg_match( '#wp-image-([0-9]+)#i', $
|
408 |
$attachment_id = absint( $matches[1] );
|
409 |
|
410 |
return $attachment_id;
|
70 |
|
71 |
$post_data = array(
|
72 |
'guid' => $url,
|
73 |
+
'post_title' => 'rp_' . $file_array['name'],
|
74 |
);
|
75 |
|
76 |
$attachment_id = media_handle_sideload($file_array, $post_id, null, $post_data);
|
138 |
$platform_options = wp_rp_get_platform_options();
|
139 |
if (!$img_path) { return false; }
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
$attach_data = wp_generate_attachment_metadata($attachment_id, $img_path);
|
142 |
wp_update_attachment_metadata($attachment_id, $attach_data);
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
return $attachment_id;
|
145 |
}
|
146 |
|
167 |
add_action('wp_rp_cron_extract_images_from_post', 'wp_rp_cron_do_extract_images_from_post', 10, 2);
|
168 |
|
169 |
function wp_rp_extract_images_from_post($post, $attachment_id=null) {
|
170 |
+
//WP quirk: posts can have an image, but still no attachment
|
171 |
+
//if(empty($post->post_content) && !$attachment_id) { return; }
|
172 |
+
if(empty($post->post_content)) { return; }
|
173 |
|
174 |
delete_post_meta($post->ID, '_wp_rp_image');
|
175 |
wp_schedule_single_event(time(), 'wp_rp_cron_extract_images_from_post', array($post->ID, $attachment_id));
|
190 |
delete_post_meta($post->ID, '_wp_rp_image');
|
191 |
|
192 |
wp_rp_get_post_thumbnail_img($post);
|
193 |
+
|
194 |
+
$options = wp_rp_get_options();
|
195 |
+
delete_post_meta($post->ID, '_wp_rp_related_posts_query_result_cache_expiration');
|
196 |
+
delete_post_meta($post->ID, '_wp_rp_related_posts_query_result_cache_'.$options['max_related_posts']);
|
197 |
}
|
198 |
add_action('save_post', 'wp_rp_post_save_update_image');
|
199 |
|
231 |
|
232 |
$img_url = wp_get_attachment_url($image_data['id']);
|
233 |
$img_url_basename = wp_basename($img_url);
|
234 |
+
$platform_options = wp_rp_get_platform_options();
|
235 |
|
236 |
// Calculate exact dimensions for proportional images
|
237 |
if (!$size[0]) { $size[0] = (int) ($image_data['data']['width'] / $image_data['data']['height'] * $size[1]); }
|
238 |
if (!$size[1]) { $size[1] = (int) ($image_data['data']['height'] / $image_data['data']['width'] * $size[0]); }
|
239 |
|
240 |
+
if (!$image_data['data']['sizes']) {
|
241 |
+
$w = $image_data['data']['width'];
|
242 |
+
$h = $image_data['data']['height'];
|
243 |
+
|
244 |
+
$thumb_width = $platform_options['custom_size_thumbnail_enabled'] ? $platform_options['custom_thumbnail_width'] : WP_RP_THUMBNAILS_WIDTH;
|
245 |
+
$thumb_height = $platform_options['custom_size_thumbnail_enabled'] ? $platform_options['custom_thumbnail_height'] : WP_RP_THUMBNAILS_HEIGHT;
|
246 |
+
|
247 |
+
if ($w == $thumb_width && $h == $thumb_height) {
|
248 |
+
$file = explode("/", $image_data['data']['file']);
|
249 |
+
$file = $file[count($file) - 1];
|
250 |
+
$img_url = str_replace($img_url_basename, wp_basename($file), $img_url);
|
251 |
+
return array(
|
252 |
+
'url' => $img_url,
|
253 |
+
'file' => $file,
|
254 |
+
'width' => $w,
|
255 |
+
'height' => $h
|
256 |
+
);
|
257 |
+
}
|
258 |
+
}
|
259 |
+
|
260 |
foreach ($image_data['data']['sizes'] as $_size => $data) {
|
261 |
// width and height can be both string and integers. WordPress..
|
262 |
if (($size[0] == $data['width']) && ($size[1] == $data['height'])) {
|
276 |
|
277 |
function wp_rp_get_image_data($image_id) {
|
278 |
if (!$image_id || is_wp_error($image_id)) { return false; }
|
|
|
279 |
$imagedata = wp_get_attachment_metadata($image_id);
|
280 |
if (!$imagedata || !is_array($imagedata) || !isset($imagedata['sizes']) || !is_array($imagedata['sizes'])) {
|
281 |
return false;
|
317 |
wp_rp_extract_images_from_post($related_post);
|
318 |
return false;
|
319 |
}
|
|
|
320 |
if ($img_src = wp_rp_get_image_with_exact_size($image_data, $size)) {
|
321 |
return $img_src['url'];
|
322 |
}
|
407 |
if ( ! preg_match_all( '#class=([\'"])(.+?)\1#is', $matched_html, $matches ) || empty( $matches ) )
|
408 |
return $attachment_id;
|
409 |
|
410 |
+
$img_class = $matches[2][0];
|
|
|
|
|
411 |
|
412 |
+
if ( ! $attachment_id && ! empty( $img_class ) && false !== strpos( $img_class, 'wp-image-' ) )
|
413 |
+
if ( preg_match( '#wp-image-([0-9]+)#i', $img_class, $matches ) )
|
414 |
$attachment_id = absint( $matches[1] );
|
415 |
|
416 |
return $attachment_id;
|
wp_related_posts.php
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: WordPress Related Posts
|
4 |
-
Version: 3.3.
|
5 |
Plugin URI: http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/
|
6 |
Description: Quickly increase your readers' engagement with your posts by adding Related Posts in the footer of your content. Click on <a href="admin.php?page=wordpress-related-posts">Related Posts tab</a> to configure your settings.
|
7 |
Author: Zemanta Ltd.
|
8 |
Author URI: http://www.zemanta.com
|
9 |
*/
|
10 |
|
11 |
-
define('WP_RP_VERSION', '3.3.
|
12 |
|
13 |
define('WP_RP_PLUGIN_FILE', plugin_basename(__FILE__));
|
14 |
|
@@ -60,7 +60,7 @@ function wp_rp_add_related_posts_hook($content) {
|
|
60 |
|
61 |
$options = wp_rp_get_options();
|
62 |
|
63 |
-
if ($post->post_type === 'post' && (($options["on_single_post"] && is_single()) || (is_feed() && $options["on_rss"]))) {
|
64 |
if (!isset($wp_rp_output[$post->ID])) {
|
65 |
$wp_rp_output[$post->ID] = wp_rp_get_related_posts();
|
66 |
}
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: WordPress Related Posts
|
4 |
+
Version: 3.3.2
|
5 |
Plugin URI: http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/
|
6 |
Description: Quickly increase your readers' engagement with your posts by adding Related Posts in the footer of your content. Click on <a href="admin.php?page=wordpress-related-posts">Related Posts tab</a> to configure your settings.
|
7 |
Author: Zemanta Ltd.
|
8 |
Author URI: http://www.zemanta.com
|
9 |
*/
|
10 |
|
11 |
+
define('WP_RP_VERSION', '3.3.2');
|
12 |
|
13 |
define('WP_RP_PLUGIN_FILE', plugin_basename(__FILE__));
|
14 |
|
60 |
|
61 |
$options = wp_rp_get_options();
|
62 |
|
63 |
+
if ($content != "" && $post->post_type === 'post' && (($options["on_single_post"] && is_single()) || (is_feed() && $options["on_rss"]))) {
|
64 |
if (!isset($wp_rp_output[$post->ID])) {
|
65 |
$wp_rp_output[$post->ID] = wp_rp_get_related_posts();
|
66 |
}
|