Auto Post Thumbnail - Version 2.0

Version Description

  • Added functionality to generate Post Thumbnail for scheduled posts. Thumbnail will be generated when scheduled post gets published.
Download this release

Release Info

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

Code changes from version 1.1 to 2.0

Files changed (2) hide show
  1. auto-post-thumbnail.php +18 -1
  2. readme.txt +5 -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 from the first image in post only if Post Thumbnail is not set manually.
7
- Version: 1.1
8
  Author: Aditya Mooley <adityamooley@sanisoft.com>
9
  Author URI: http://www.sanisoft.com/blog/author/adityamooley/
10
  */
@@ -28,6 +28,7 @@ Author URI: http://www.sanisoft.com/blog/author/adityamooley/
28
 
29
 
30
  add_action('publish_post', 'apt_publish_post');
 
31
  add_action( 'admin_notices', 'apt_check_perms');
32
 
33
  /**
@@ -50,6 +51,20 @@ function apt_check_perms() {
50
  }
51
  }
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  /**
54
  * Function to save first image in post as post thumbmail.
55
  */
@@ -154,6 +169,8 @@ function apt_generate_post_thumb($matches, $key)
154
 
155
  $thumb_id = wp_insert_attachment($attachment, $file, $post_id);
156
  if ( !is_wp_error($thumb_id) ) {
 
 
157
  wp_update_attachment_metadata( $thumb_id, wp_generate_attachment_metadata( $thumb_id, $new_file ) );
158
 
159
  return $thumb_id;
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: 2.0
8
  Author: Aditya Mooley <adityamooley@sanisoft.com>
9
  Author URI: http://www.sanisoft.com/blog/author/adityamooley/
10
  */
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
 
34
  /**
51
  }
52
  }
53
 
54
+ /**
55
+ * Function to check whether scheduled post is being published. If so, apt_publish_post should be called.
56
+ *
57
+ * @param $new_status
58
+ * @param $old_status
59
+ * @param $post
60
+ * @return void
61
+ */
62
+ function apt_check_required_transition($new_status='', $old_status='', $post='') {
63
+ if ('publish' == $new_status && 'future' == $old_status) {
64
+ apt_publish_post($post->ID);
65
+ }
66
+ }
67
+
68
  /**
69
  * Function to save first image in post as post thumbmail.
70
  */
169
 
170
  $thumb_id = wp_insert_attachment($attachment, $file, $post_id);
171
  if ( !is_wp_error($thumb_id) ) {
172
+ require_once(ABSPATH . '/wp-admin/includes/image.php');
173
+
174
  wp_update_attachment_metadata( $thumb_id, wp_generate_attachment_metadata( $thumb_id, $new_file ) );
175
 
176
  return $thumb_id;
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: adityamooley
3
  Tags: post thumbnail
4
  Requires at least: 2.9.1
5
- Tested up to: 3.0-RC3
6
- Stable tag: 1.1
7
 
8
  Automatically generate the Post Thumbnail from the first image in post only if Post Thumbnail is not set manually.
9
 
@@ -22,6 +22,9 @@ If you don't want a post thumbnail for some post with images, just add a custom
22
 
23
  == Changelog ==
24
 
 
 
 
25
  = 1.1 =
26
  * Added a wrapper function using cURL for file_get_contents in case 'allow_url_fopen' ini setting is off.
27
 
2
  Contributors: adityamooley
3
  Tags: post thumbnail
4
  Requires at least: 2.9.1
5
+ Tested up to: 3.0
6
+ Stable tag: 2.0
7
 
8
  Automatically generate the Post Thumbnail from the first image in post only if Post Thumbnail is not set manually.
9
 
22
 
23
  == Changelog ==
24
 
25
+ = 2.0 =
26
+ * Added functionality to generate Post Thumbnail for scheduled posts. Thumbnail will be generated when scheduled post gets published.
27
+
28
  = 1.1 =
29
  * Added a wrapper function using cURL for file_get_contents in case 'allow_url_fopen' ini setting is off.
30