Auto Post Thumbnail - Version 3.2.1

Version Description

  • Added code to correctly link the featured/post thumbnail with the post so that the Media Library shows the association correctly.
  • Assigning title to the generated featured/post thumbnail by extracting it from the title of processed image.
Download this release

Release Info

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

Code changes from version 3.2 to 3.2.1

Files changed (2) hide show
  1. auto-post-thumbnail.php +13 -4
  2. readme.txt +6 -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
8
  Author: Aditya Mooley <adityamooley@sanisoft.com>
9
  Author URI: http://www.sanisoft.com/blog/author/adityamooley/
10
  */
@@ -252,7 +252,7 @@ function apt_publish_post($post_id)
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);
256
  }
257
 
258
  // If we succeed in generating thumg, let's update post meta
@@ -267,8 +267,17 @@ function apt_publish_post($post_id)
267
  /**
268
  * Function to fetch the image from URL and generate the required thumbnails
269
  */
270
- function apt_generate_post_thumb($matches, $key)
271
  {
 
 
 
 
 
 
 
 
 
272
  $imageUrl = $matches[1][$key];
273
 
274
  // Get the file name
@@ -319,7 +328,7 @@ function apt_generate_post_thumb($matches, $key)
319
  'post_mime_type' => $type,
320
  'guid' => $url,
321
  'post_parent' => null,
322
- 'post_title' => '',
323
  'post_content' => '',
324
  );
325
 
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
  */
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
  }
257
 
258
  // If we succeed in generating thumg, let's update post meta
267
  /**
268
  * Function to fetch the image from URL and generate the required thumbnails
269
  */
270
+ function apt_generate_post_thumb($matches, $key, $post_content, $post_id)
271
  {
272
+ // Make sure to assign correct title to the image. Extract it from img tag
273
+ $imageTitle = '';
274
+ preg_match_all('/<\s*img [^\>]*title\s*=\s*[\""\']?([^\""\'>]*)/i', $post_content, $matchesTitle);
275
+
276
+ if (count($matchesTitle) && isset($matchesTitle[1])) {
277
+ $imageTitle = $matchesTitle[1][$key];
278
+ }
279
+
280
+ // Get the URL now for further processing
281
  $imageUrl = $matches[1][$key];
282
 
283
  // Get the file name
328
  'post_mime_type' => $type,
329
  'guid' => $url,
330
  'post_parent' => null,
331
+ 'post_title' => $imageTitle,
332
  'post_content' => '',
333
  );
334
 
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.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
 
@@ -23,6 +23,10 @@ The plugin also provides a Batch Processing capability to generate post thumbnai
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
 
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
 
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.
29
+
30
  = 3.2 =
31
  Added support for creating featured thumbnails for custom post types as well. Batch processing will also generate thumbnails for any type of post.
32