Auto Post Thumbnail - Version 3.2.2

Version Description

  • Added back publish_post action so that regular posts work without any issues.
  • Added code to check whether the image exists in database before trying to fetch it.
Download this release

Release Info

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

Code changes from version 3.2.1 to 3.2.2

Files changed (2) hide show
  1. auto-post-thumbnail.php +13 -2
  2. readme.txt +8 -2
auto-post-thumbnail.php CHANGED
@@ -4,7 +4,7 @@
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.1
8
  Author: Aditya Mooley <adityamooley@sanisoft.com>
9
  Author URI: http://www.sanisoft.com/blog/author/adityamooley/
10
  */
@@ -26,8 +26,12 @@ 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
  // 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
@@ -249,8 +253,15 @@ function apt_publish_post($post_id)
249
  */
250
  preg_match('/wp-image-([\d]*)/i', $image, $thumb_id);
251
  $thumb_id = $thumb_id[1];
 
 
 
 
 
 
 
252
 
253
- // Ok. No id found. Some other way used to insert the image in post. Fetch the image from URL and do the needful.
254
  if (!$thumb_id) {
255
  $thumb_id = apt_generate_post_thumb($matches, $key, $post[0]->post_content, $post_id);
256
  }
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.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
+
30
+ add_action('publish_post', 'apt_publish_post');
31
+
32
  // This hook will now handle all sort publishing including posts, custom types, scheduled posts, etc.
33
  add_action('transition_post_status', 'apt_check_required_transition');
34
+
35
  add_action('admin_notices', 'apt_check_perms');
36
  add_action('admin_menu', 'apt_add_admin_menu'); // Add batch process capability
37
  add_action('admin_enqueue_scripts', 'apt_admin_enqueues'); // Plugin hook for adding CSS and JS files required for this plugin
253
  */
254
  preg_match('/wp-image-([\d]*)/i', $image, $thumb_id);
255
  $thumb_id = $thumb_id[1];
256
+
257
+ // If thumb id is not found, try to look for the image in DB. Thanks to "Erwin Vrolijk" for providing this code.
258
+ if (!$thumb_id) {
259
+ $image = substr($image, strpos($image, '"')+1);
260
+ $result = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE guid = '".$image."'");
261
+ $thumb_id = $result[0]->ID;
262
+ }
263
 
264
+ // Ok. Still no id found. Some other way used to insert the image in post. Now we must fetch the image from URL and do the needful.
265
  if (!$thumb_id) {
266
  $thumb_id = apt_generate_post_thumb($matches, $key, $post[0]->post_content, $post_id);
267
  }
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.0.2
6
- Stable tag: 3.2.1
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
 
@@ -15,6 +15,8 @@ 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.
16
  The plugin also provides a Batch Processing capability to generate post thumbnails for already published posts. A new menu item **Gen. Post Thumbnails** will get added under Tools menu after this plugin is installed.
17
 
 
 
18
  == Installation ==
19
 
20
  1. Upload directory 'auto-post-thumbnail' to the '/wp-content/plugins/' directory
@@ -23,6 +25,10 @@ The plugin also provides a Batch Processing capability to generate post thumbnai
23
 
24
  == Changelog ==
25
 
 
 
 
 
26
  = 3.2.1 =
27
  * Added code to correctly link the featured/post thumbnail with the post so that the Media Library shows the association correctly.
28
  * Assigning **title** to the generated featured/post thumbnail by extracting it from the title of processed image.
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.4
6
+ Stable tag: 3.2.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
 
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.
16
  The plugin also provides a Batch Processing capability to generate post thumbnails for already published posts. A new menu item **Gen. Post Thumbnails** will get added under Tools menu after this plugin is installed.
17
 
18
+ For more details, see http://www.sanisoft.com/blog/2010/04/19/wordpress-plugin-automatic-post-thumbnail/
19
+
20
  == Installation ==
21
 
22
  1. Upload directory 'auto-post-thumbnail' to the '/wp-content/plugins/' directory
25
 
26
  == Changelog ==
27
 
28
+ = 3.2.2 =
29
+ * Added back publish_post action so that regular posts work without any issues.
30
+ * Added code to check whether the image exists in database before trying to fetch it.
31
+
32
  = 3.2.1 =
33
  * Added code to correctly link the featured/post thumbnail with the post so that the Media Library shows the association correctly.
34
  * Assigning **title** to the generated featured/post thumbnail by extracting it from the title of processed image.