Version Description
- Added fix for featured images behaving differently in Wordpress version 3.4. NOTE: This version will fix only images in future posts. For fixing images of past posts see http://www.clickthrough-marketing.com/how-to-fix-auto-post-thumbnail-on-wordpress-3.4-seo-friendly-800610805/
Download this release
Release Info
Developer | tariquesani |
Plugin | Auto Post Thumbnail |
Version | 3.3.0 |
Comparing to | |
See all releases |
Code changes from version 3.2.3 to 3.3.0
- auto-post-thumbnail.php +33 -30
- readme.txt +6 -3
auto-post-thumbnail.php
CHANGED
@@ -4,9 +4,10 @@
|
|
4 |
Plugin Name: Auto Post Thumbnail
|
5 |
Plugin URI: http://www.sanisoft.com/blog/2010/04/19/wordpress-plugin-automatic-post-thumbnail/
|
6 |
Description: Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post (or any custom post type) only if Post Thumbnail is not set manually.
|
7 |
-
Version: 3.
|
8 |
-
Author: Aditya Mooley <adityamooley@sanisoft.com>
|
9 |
Author URI: http://www.sanisoft.com/blog/author/adityamooley/
|
|
|
10 |
*/
|
11 |
|
12 |
/* Copyright 2009 Aditya Mooley (email : adityamooley@sanisoft.com)
|
@@ -44,10 +45,10 @@ function apt_add_admin_menu() {
|
|
44 |
|
45 |
/**
|
46 |
* Admin user interface plus post thumbnail generator
|
47 |
-
*
|
48 |
-
* Most of the code in this function is copied from -
|
49 |
* Regenerate Thumbnails plugin (http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/)
|
50 |
-
*
|
51 |
* @return void
|
52 |
*/
|
53 |
function apt_interface() {
|
@@ -57,8 +58,8 @@ function apt_interface() {
|
|
57 |
|
58 |
<div class="wrap genpostthumbs">
|
59 |
<h2>Generate Post Thumbnails</h2>
|
60 |
-
|
61 |
-
<?php
|
62 |
// If the button was clicked
|
63 |
if ( !empty($_POST['generate-post-thumbnails']) ) {
|
64 |
// Capability check
|
@@ -67,18 +68,18 @@ function apt_interface() {
|
|
67 |
|
68 |
// Form nonce check
|
69 |
check_admin_referer( 'generate-post-thumbnails' );
|
70 |
-
|
71 |
// Get id's of all the published posts for which post thumbnails does not exist.
|
72 |
$query = "SELECT * FROM {$wpdb->posts} p where p.post_status = 'publish' AND p.ID NOT IN (
|
73 |
SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ('_thumbnail_id', 'skip_post_thumb')
|
74 |
)";
|
75 |
$posts = $wpdb->get_results($query);
|
76 |
-
|
77 |
if (empty($posts)) {
|
78 |
echo '<p>Currently there are no published posts available to generate thumbnails.</p>';
|
79 |
} else {
|
80 |
echo '<p>We are generating post thumbnails. Please be patient!</p>';
|
81 |
-
|
82 |
// Generate the list of IDs
|
83 |
$ids = array();
|
84 |
foreach ( $posts as $post )
|
@@ -130,7 +131,7 @@ function apt_interface() {
|
|
130 |
}
|
131 |
} else {
|
132 |
?>
|
133 |
-
|
134 |
<p>Use this tool to generate Post Thumbnail (Featured Thumbnail) for your Published posts.</p>
|
135 |
<p>If the script stops executing for any reason, just <strong>Reload</strong> the page and it will continue from where it stopped.</p>
|
136 |
|
@@ -151,7 +152,7 @@ function apt_interface() {
|
|
151 |
|
152 |
/**
|
153 |
* Add our JS and CSS files
|
154 |
-
*
|
155 |
* @param $hook_suffix
|
156 |
* @return void
|
157 |
*/
|
@@ -160,26 +161,26 @@ function apt_admin_enqueues($hook_suffix) {
|
|
160 |
return;
|
161 |
}
|
162 |
|
163 |
-
// WordPress 3.1 vs older version compatibility
|
164 |
-
if ( wp_script_is( 'jquery-ui-widget', 'registered' ) ) {
|
165 |
wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'jquery-ui/jquery.ui.progressbar.min.js', __FILE__ ), array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.7.2' );
|
166 |
-
}
|
167 |
-
else {
|
168 |
wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'jquery-ui/ui.progressbar.js', __FILE__ ), array( 'jquery-ui-core' ), '1.7.2' );
|
169 |
}
|
170 |
-
|
171 |
wp_enqueue_style( 'jquery-ui-genpostthumbs', plugins_url( 'jquery-ui/redmond/jquery-ui-1.7.2.custom.css', __FILE__ ), array(), '1.7.2' );
|
172 |
} //End apt_admin_enqueues
|
173 |
|
174 |
/**
|
175 |
* Process single post to generate the post thumbnail
|
176 |
-
*
|
177 |
* @return void
|
178 |
*/
|
179 |
function apt_ajax_process_post() {
|
180 |
if ( !current_user_can( 'manage_options' ) ) {
|
181 |
die('-1');
|
182 |
-
}
|
183 |
|
184 |
$id = (int) $_POST['id'];
|
185 |
|
@@ -188,10 +189,10 @@ function apt_ajax_process_post() {
|
|
188 |
}
|
189 |
|
190 |
set_time_limit( 60 );
|
191 |
-
|
192 |
// Pass on the id to our 'publish' callback function.
|
193 |
apt_publish_post($id);
|
194 |
-
|
195 |
die(-1);
|
196 |
} //End apt_ajax_process_post()
|
197 |
|
@@ -218,7 +219,7 @@ function apt_check_perms() {
|
|
218 |
|
219 |
/**
|
220 |
* Function to check whether scheduled post is being published. If so, apt_publish_post should be called.
|
221 |
-
*
|
222 |
* @param $new_status
|
223 |
* @param $old_status
|
224 |
* @param $post
|
@@ -260,7 +261,7 @@ function apt_publish_post($post_id)
|
|
260 |
*/
|
261 |
preg_match('/wp-image-([\d]*)/i', $image, $thumb_id);
|
262 |
$thumb_id = $thumb_id[1];
|
263 |
-
|
264 |
// If thumb id is not found, try to look for the image in DB. Thanks to "Erwin Vrolijk" for providing this code.
|
265 |
if (!$thumb_id) {
|
266 |
$image = substr($image, strpos($image, '"')+1);
|
@@ -310,17 +311,17 @@ function apt_generate_post_thumb($matches, $key, $post_content, $post_id)
|
|
310 |
|
311 |
// Move the file to the uploads dir
|
312 |
$new_file = $uploads['path'] . "/$filename";
|
313 |
-
|
314 |
if (!ini_get('allow_url_fopen')) {
|
315 |
$file_data = curl_get_file_contents($imageUrl);
|
316 |
} else {
|
317 |
$file_data = @file_get_contents($imageUrl);
|
318 |
}
|
319 |
-
|
320 |
if (!$file_data) {
|
321 |
return null;
|
322 |
}
|
323 |
-
|
324 |
file_put_contents($new_file, $file_data);
|
325 |
|
326 |
// Set correct file permissions
|
@@ -353,8 +354,10 @@ function apt_generate_post_thumb($matches, $key, $post_content, $post_id)
|
|
353 |
$thumb_id = wp_insert_attachment($attachment, $file, $post_id);
|
354 |
if ( !is_wp_error($thumb_id) ) {
|
355 |
require_once(ABSPATH . '/wp-admin/includes/image.php');
|
356 |
-
|
|
|
357 |
wp_update_attachment_metadata( $thumb_id, wp_generate_attachment_metadata( $thumb_id, $new_file ) );
|
|
|
358 |
|
359 |
return $thumb_id;
|
360 |
}
|
@@ -364,7 +367,7 @@ function apt_generate_post_thumb($matches, $key, $post_content, $post_id)
|
|
364 |
|
365 |
/**
|
366 |
* Function to fetch the contents of URL using curl in absense of allow_url_fopen.
|
367 |
-
*
|
368 |
* Copied from user comment on php.net (http://in.php.net/manual/en/function.file-get-contents.php#82255)
|
369 |
*/
|
370 |
function curl_get_file_contents($URL) {
|
@@ -377,6 +380,6 @@ function curl_get_file_contents($URL) {
|
|
377 |
if ($contents) {
|
378 |
return $contents;
|
379 |
}
|
380 |
-
|
381 |
return FALSE;
|
382 |
-
}
|
4 |
Plugin Name: Auto Post Thumbnail
|
5 |
Plugin URI: http://www.sanisoft.com/blog/2010/04/19/wordpress-plugin-automatic-post-thumbnail/
|
6 |
Description: Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post (or any custom post type) only if Post Thumbnail is not set manually.
|
7 |
+
Version: 3.3.0
|
8 |
+
Author: Aditya Mooley <adityamooley@sanisoft.com>, Tarique Sani <tarique@sanisoft.com>
|
9 |
Author URI: http://www.sanisoft.com/blog/author/adityamooley/
|
10 |
+
Modified by Dr. Tarique Sani <tarique@sanisoft.com> to make it work with Wordpress 3.4
|
11 |
*/
|
12 |
|
13 |
/* Copyright 2009 Aditya Mooley (email : adityamooley@sanisoft.com)
|
45 |
|
46 |
/**
|
47 |
* Admin user interface plus post thumbnail generator
|
48 |
+
*
|
49 |
+
* Most of the code in this function is copied from -
|
50 |
* Regenerate Thumbnails plugin (http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/)
|
51 |
+
*
|
52 |
* @return void
|
53 |
*/
|
54 |
function apt_interface() {
|
58 |
|
59 |
<div class="wrap genpostthumbs">
|
60 |
<h2>Generate Post Thumbnails</h2>
|
61 |
+
|
62 |
+
<?php
|
63 |
// If the button was clicked
|
64 |
if ( !empty($_POST['generate-post-thumbnails']) ) {
|
65 |
// Capability check
|
68 |
|
69 |
// Form nonce check
|
70 |
check_admin_referer( 'generate-post-thumbnails' );
|
71 |
+
|
72 |
// Get id's of all the published posts for which post thumbnails does not exist.
|
73 |
$query = "SELECT * FROM {$wpdb->posts} p where p.post_status = 'publish' AND p.ID NOT IN (
|
74 |
SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ('_thumbnail_id', 'skip_post_thumb')
|
75 |
)";
|
76 |
$posts = $wpdb->get_results($query);
|
77 |
+
|
78 |
if (empty($posts)) {
|
79 |
echo '<p>Currently there are no published posts available to generate thumbnails.</p>';
|
80 |
} else {
|
81 |
echo '<p>We are generating post thumbnails. Please be patient!</p>';
|
82 |
+
|
83 |
// Generate the list of IDs
|
84 |
$ids = array();
|
85 |
foreach ( $posts as $post )
|
131 |
}
|
132 |
} else {
|
133 |
?>
|
134 |
+
|
135 |
<p>Use this tool to generate Post Thumbnail (Featured Thumbnail) for your Published posts.</p>
|
136 |
<p>If the script stops executing for any reason, just <strong>Reload</strong> the page and it will continue from where it stopped.</p>
|
137 |
|
152 |
|
153 |
/**
|
154 |
* Add our JS and CSS files
|
155 |
+
*
|
156 |
* @param $hook_suffix
|
157 |
* @return void
|
158 |
*/
|
161 |
return;
|
162 |
}
|
163 |
|
164 |
+
// WordPress 3.1 vs older version compatibility
|
165 |
+
if ( wp_script_is( 'jquery-ui-widget', 'registered' ) ) {
|
166 |
wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'jquery-ui/jquery.ui.progressbar.min.js', __FILE__ ), array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.7.2' );
|
167 |
+
}
|
168 |
+
else {
|
169 |
wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'jquery-ui/ui.progressbar.js', __FILE__ ), array( 'jquery-ui-core' ), '1.7.2' );
|
170 |
}
|
171 |
+
|
172 |
wp_enqueue_style( 'jquery-ui-genpostthumbs', plugins_url( 'jquery-ui/redmond/jquery-ui-1.7.2.custom.css', __FILE__ ), array(), '1.7.2' );
|
173 |
} //End apt_admin_enqueues
|
174 |
|
175 |
/**
|
176 |
* Process single post to generate the post thumbnail
|
177 |
+
*
|
178 |
* @return void
|
179 |
*/
|
180 |
function apt_ajax_process_post() {
|
181 |
if ( !current_user_can( 'manage_options' ) ) {
|
182 |
die('-1');
|
183 |
+
}
|
184 |
|
185 |
$id = (int) $_POST['id'];
|
186 |
|
189 |
}
|
190 |
|
191 |
set_time_limit( 60 );
|
192 |
+
|
193 |
// Pass on the id to our 'publish' callback function.
|
194 |
apt_publish_post($id);
|
195 |
+
|
196 |
die(-1);
|
197 |
} //End apt_ajax_process_post()
|
198 |
|
219 |
|
220 |
/**
|
221 |
* Function to check whether scheduled post is being published. If so, apt_publish_post should be called.
|
222 |
+
*
|
223 |
* @param $new_status
|
224 |
* @param $old_status
|
225 |
* @param $post
|
261 |
*/
|
262 |
preg_match('/wp-image-([\d]*)/i', $image, $thumb_id);
|
263 |
$thumb_id = $thumb_id[1];
|
264 |
+
|
265 |
// If thumb id is not found, try to look for the image in DB. Thanks to "Erwin Vrolijk" for providing this code.
|
266 |
if (!$thumb_id) {
|
267 |
$image = substr($image, strpos($image, '"')+1);
|
311 |
|
312 |
// Move the file to the uploads dir
|
313 |
$new_file = $uploads['path'] . "/$filename";
|
314 |
+
|
315 |
if (!ini_get('allow_url_fopen')) {
|
316 |
$file_data = curl_get_file_contents($imageUrl);
|
317 |
} else {
|
318 |
$file_data = @file_get_contents($imageUrl);
|
319 |
}
|
320 |
+
|
321 |
if (!$file_data) {
|
322 |
return null;
|
323 |
}
|
324 |
+
|
325 |
file_put_contents($new_file, $file_data);
|
326 |
|
327 |
// Set correct file permissions
|
354 |
$thumb_id = wp_insert_attachment($attachment, $file, $post_id);
|
355 |
if ( !is_wp_error($thumb_id) ) {
|
356 |
require_once(ABSPATH . '/wp-admin/includes/image.php');
|
357 |
+
|
358 |
+
// Added fix by misthero as suggested
|
359 |
wp_update_attachment_metadata( $thumb_id, wp_generate_attachment_metadata( $thumb_id, $new_file ) );
|
360 |
+
update_attached_file( $thumb_id, $new_file );
|
361 |
|
362 |
return $thumb_id;
|
363 |
}
|
367 |
|
368 |
/**
|
369 |
* Function to fetch the contents of URL using curl in absense of allow_url_fopen.
|
370 |
+
*
|
371 |
* Copied from user comment on php.net (http://in.php.net/manual/en/function.file-get-contents.php#82255)
|
372 |
*/
|
373 |
function curl_get_file_contents($URL) {
|
380 |
if ($contents) {
|
381 |
return $contents;
|
382 |
}
|
383 |
+
|
384 |
return FALSE;
|
385 |
+
}
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: adityamooley
|
3 |
Tags: Post, thumbnail, automatic, posts, featured image, image, featured, images, admin
|
4 |
Requires at least: 2.9.1
|
5 |
-
Tested up to: 3.
|
6 |
-
Stable tag: 3.
|
7 |
|
8 |
Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post or any custom post type only if Post Thumbnail is not set manually.
|
9 |
|
@@ -25,6 +25,9 @@ For more details, see http://www.sanisoft.com/blog/2010/04/19/wordpress-plugin-a
|
|
25 |
|
26 |
== Changelog ==
|
27 |
|
|
|
|
|
|
|
28 |
= 3.2.3 =
|
29 |
* Added fix for jquery progress bar error causing due to Wordpress version 3.1
|
30 |
|
@@ -53,4 +56,4 @@ Added functionality to generate Post Thumbnail for scheduled posts. Thumbnail wi
|
|
53 |
Added a wrapper function using cURL for file_get_contents in case 'allow_url_fopen' ini setting is off.
|
54 |
|
55 |
= 1.0 =
|
56 |
-
First release
|
2 |
Contributors: adityamooley
|
3 |
Tags: Post, thumbnail, automatic, posts, featured image, image, featured, images, admin
|
4 |
Requires at least: 2.9.1
|
5 |
+
Tested up to: 3.4
|
6 |
+
Stable tag: 3.3.0
|
7 |
|
8 |
Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post or any custom post type only if Post Thumbnail is not set manually.
|
9 |
|
25 |
|
26 |
== Changelog ==
|
27 |
|
28 |
+
= 3.3.0 =
|
29 |
+
* Added fix for featured images behaving differently in Wordpress version 3.4. NOTE: This version will fix only images in future posts. For fixing images of past posts see http://www.clickthrough-marketing.com/how-to-fix-auto-post-thumbnail-on-wordpress-3.4-seo-friendly-800610805/
|
30 |
+
|
31 |
= 3.2.3 =
|
32 |
* Added fix for jquery progress bar error causing due to Wordpress version 3.1
|
33 |
|
56 |
Added a wrapper function using cURL for file_get_contents in case 'allow_url_fopen' ini setting is off.
|
57 |
|
58 |
= 1.0 =
|
59 |
+
First release
|