Auto Post Thumbnail - Version 3.2

Version Description

Added support for creating featured thumbnails for custom post types as well. Batch processing will also generate thumbnails for any type of post.

Download this release

Release Info

Developer adityamooley
Plugin Icon 128x128 Auto Post Thumbnail
Version 3.2
Comparing to
See all releases

Code changes from version 3.1 to 3.2

Files changed (2) hide show
  1. auto-post-thumbnail.php +11 -10
  2. readme.txt +7 -4
auto-post-thumbnail.php CHANGED
@@ -3,8 +3,8 @@
3
  /*
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 from the first image in post only if Post Thumbnail is not set manually.
7
- Version: 3.1
8
  Author: Aditya Mooley <adityamooley@sanisoft.com>
9
  Author URI: http://www.sanisoft.com/blog/author/adityamooley/
10
  */
@@ -26,9 +26,8 @@ Author URI: http://www.sanisoft.com/blog/author/adityamooley/
26
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
29
-
30
- add_action('publish_post', 'apt_publish_post');
31
- add_action('transition_post_status', 'apt_check_required_transition'); // Plugin should work for scheduled posts as well
32
  add_action('admin_notices', 'apt_check_perms');
33
  add_action('admin_menu', 'apt_add_admin_menu'); // Add batch process capability
34
  add_action('admin_enqueue_scripts', 'apt_admin_enqueues'); // Plugin hook for adding CSS and JS files required for this plugin
@@ -66,7 +65,7 @@ function apt_interface() {
66
  check_admin_referer( 'generate-post-thumbnails' );
67
 
68
  // Get id's of all the published posts for which post thumbnails does not exist.
69
- $query = "SELECT * FROM {$wpdb->posts} p where p.post_status = 'publish' AND post_type = 'post' AND p.ID NOT IN (
70
  SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ('_thumbnail_id', 'skip_post_thumb')
71
  )";
72
  $posts = $wpdb->get_results($query);
@@ -172,11 +171,11 @@ function apt_ajax_process_post() {
172
  }
173
 
174
  $id = (int) $_POST['id'];
175
-
176
  if ( empty($id) ) {
177
  die('-1');
178
  }
179
-
180
  set_time_limit( 60 );
181
 
182
  // Pass on the id to our 'publish' callback function.
@@ -215,8 +214,10 @@ function apt_check_perms() {
215
  * @return void
216
  */
217
  function apt_check_required_transition($new_status='', $old_status='', $post='') {
218
- if ('publish' == $new_status && 'future' == $old_status) {
219
- apt_publish_post($post->ID);
 
 
220
  }
221
  }
222
 
3
  /*
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.2
8
  Author: Aditya Mooley <adityamooley@sanisoft.com>
9
  Author URI: http://www.sanisoft.com/blog/author/adityamooley/
10
  */
26
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
29
+ // This hook will now handle all sort publishing including posts, custom types, scheduled posts, etc.
30
+ add_action('transition_post_status', 'apt_check_required_transition');
 
31
  add_action('admin_notices', 'apt_check_perms');
32
  add_action('admin_menu', 'apt_add_admin_menu'); // Add batch process capability
33
  add_action('admin_enqueue_scripts', 'apt_admin_enqueues'); // Plugin hook for adding CSS and JS files required for this plugin
65
  check_admin_referer( 'generate-post-thumbnails' );
66
 
67
  // Get id's of all the published posts for which post thumbnails does not exist.
68
+ $query = "SELECT * FROM {$wpdb->posts} p where p.post_status = 'publish' AND p.ID NOT IN (
69
  SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ('_thumbnail_id', 'skip_post_thumb')
70
  )";
71
  $posts = $wpdb->get_results($query);
171
  }
172
 
173
  $id = (int) $_POST['id'];
174
+
175
  if ( empty($id) ) {
176
  die('-1');
177
  }
178
+
179
  set_time_limit( 60 );
180
 
181
  // Pass on the id to our 'publish' callback function.
214
  * @return void
215
  */
216
  function apt_check_required_transition($new_status='', $old_status='', $post='') {
217
+ global $post_ID; // Using the post id from global reference since it is not available in $post object. Strange!
218
+
219
+ if ('publish' == $new_status) {
220
+ apt_publish_post($post_ID);
221
  }
222
  }
223
 
readme.txt CHANGED
@@ -1,15 +1,15 @@
1
  === Auto Post Thumbnail ===
2
  Contributors: adityamooley
3
- Tags: Post, thumbnail, automatic, posts, image, images, admin
4
  Requires at least: 2.9.1
5
  Tested up to: 3.0.1
6
- Stable tag: 3.1
7
 
8
- Automatically generate the Post Thumbnail from the first image in post only if Post Thumbnail is not set manually.
9
 
10
  == Description ==
11
 
12
- Auto post thumbnail is a plugin to generate post thumbnail from first image in post. If the first image doesn't work it will automatically search for the next one and so on until the post thumbnail is inserted.
13
 
14
  If the post thumbnail is already present, the plugin will do nothing.
15
  If you don't want a post thumbnail for some post with images, just add a custom field *skip_post_thumb* to the post and the plugin will restrain itself from generating post thumbnail.
@@ -23,6 +23,9 @@ The plugin also provides a Batch Processing capability to generate post thumbnai
23
 
24
  == Changelog ==
25
 
 
 
 
26
  = 3.1 =
27
  Renamed **Gen. Post Thumbnails** to **Auto Post Thumbnail** and moved it under Settings menu.
28
 
1
  === Auto Post Thumbnail ===
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.0.1
6
+ Stable tag: 3.2
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
 
10
  == Description ==
11
 
12
+ Auto post thumbnail is a plugin to generate post thumbnail from first image in post or any custom post type. If the first image doesn't work it will automatically search for the next one and so on until the post thumbnail is inserted.
13
 
14
  If the post thumbnail is already present, the plugin will do nothing.
15
  If you don't want a post thumbnail for some post with images, just add a custom field *skip_post_thumb* to the post and the plugin will restrain itself from generating post thumbnail.
23
 
24
  == Changelog ==
25
 
26
+ = 3.2 =
27
+ Added support for creating featured thumbnails for custom post types as well. Batch processing will also generate thumbnails for any type of post.
28
+
29
  = 3.1 =
30
  Renamed **Gen. Post Thumbnails** to **Auto Post Thumbnail** and moved it under Settings menu.
31