Permalink
Browse files

Prevent last uploaded image automatically being set as featured image

  • Loading branch information...
1 parent c077271 commit 4c081fbc29e0114d07582797bbda8f0ae35f0c25 @mrdavidlaing mrdavidlaing committed Jul 17, 2011
Showing with 25 additions and 32 deletions.
  1. +2 −2 vspi_image_metabox.css
  2. +1 −2 vspi_image_metabox.js
  3. +22 −28 vspi_image_metabox.php
View
@@ -18,11 +18,11 @@ div.vspi_image a.vspi_thumb {
left:5px;
}
-div.vspi_thumb {
+div.vspi_is_featured_image {
border: 5px solid #66cc00;
}
-div.vspi_thumb .featured_marker {
+div.vspi_is_featured_image .featured_marker {
background-image: url('featured.png');
background-repeat: no-repeat;
z-index: 999;
View
@@ -38,8 +38,7 @@ function scImageReload() {
var holder = jQuery('#vspi_image_box')
if(holder.length > 0){
var post_id = holder.data('post_id');
- var getUrl = vspi_image_globals.ajax_url + '?action=vspi_image&vspi_action=reload&_wpnonce=' +
- vspi_image_globals.vspi_nonce + '&id=' + post_id;
+ var getUrl = vspi_image_globals.ajax_url + '?action=vspi_image&vspi_action=reload&_wpnonce=' + vspi_image_globals.vspi_nonce + '&id=' + post_id;
jQuery.getJSON(getUrl, '', function(response) {
holder.empty();
jQuery.each(response, function(a, b) {
View
@@ -3,9 +3,9 @@
Plugin Name: Very Simple Post Images
Plugin URI: http://www.simplecreativity.co.uk
Description: Image Metabox using uploadify
-Version: 0.1
-Author: Dave Tonge
-Author URI: http://www.simplecreativity.co.uk
+Version: 0.2
+Author: Dave Tonge & David Laing
+Author URI: http://www.simplecreativity.co.uk & http://davidlaing.com
*/
@@ -131,16 +131,10 @@ function insert_attachment($file_handler, $post_id, $setthumb = 'false')
return $attach_id;
}
- function vspi_check_thumb()
- {
- $postid = $_REQUEST['postid'];
- if (get_post_meta($postid, '_thumbnail_id')) return false;
- return true;
- }
-
if (!empty($_FILES)) {
- $image_id = insert_attachment('Filedata', $_REQUEST['post_id'], vspi_check_thumb());
+ $image_id = insert_attachment('Filedata', $_REQUEST['post_id']);
}
+
echo $image_id;
break;
@@ -164,28 +158,28 @@ function vspi_get_images($post_id)
'numberposts' => -1,
'post_status' => NULL
);
- $attachs = get_posts($args);
+ $attachments = get_posts($args);
- if (!isset($thumbnail_id)) $thumbnail_id = $attachs[0]->ID;
+ if (!isset($thumbnail_id)) $thumbnail_id = $attachments[0]->ID;
$vspi_images = array();
$i = 1;
- foreach ($attachs as $att) {
- $thumbnail = wp_get_attachment_image_src($att->ID, 'thumbnail');
- $medium = wp_get_attachment_image_src($att->ID, 'medium');
- $large = wp_get_attachment_image_src($att->ID, 'large');
- $full = wp_get_attachment_image_src($att->ID, 'full');
- $sc = wp_get_attachment_image_src($att->ID, 'vspi_thumb');
+ foreach ($attachments as $attachment) {
+ $thumbnail = wp_get_attachment_image_src($attachment->ID, 'thumbnail');
+ $medium = wp_get_attachment_image_src($attachment->ID, 'medium');
+ $large = wp_get_attachment_image_src($attachment->ID, 'large');
+ $full = wp_get_attachment_image_src($attachment->ID, 'full');
+ $sc = wp_get_attachment_image_src($attachment->ID, 'vspi_thumb');
$vspi_images[$i] = array(
- 'id' => $att->ID,
+ 'id' => $attachment->ID,
'large' => $large,
'medium' => $medium,
'thumbnail' => $thumbnail,
'full' => $full,
'sc' => $sc
);
- if ($thumbnail_id == $att->ID) $vspi_images[$i]['thumb'] = true;
+ if ($thumbnail_id == $attachment->ID) $vspi_images[$i]['thumb'] = true;
$i++;
}
return $vspi_images;
@@ -200,22 +194,22 @@ function vspi_get_thumbs($post_id)
'numberposts' => -1,
'post_status' => NULL
);
- $attachs = get_posts($args);
+ $attachments = get_posts($args);
- if (!isset($thumbnail_id)) $thumbnail_id = $attachs[0]->ID;
+ if (!isset($thumbnail_id)) $thumbnail_id = $attachments[0]->ID;
$vspi_images = array();
$i = 1;
- foreach ($attachs as $att) {
- $thumbnail = wp_get_attachment_image_src($att->ID, 'thumbnail');
+ foreach ($attachments as $attachment) {
+ $thumbnail = wp_get_attachment_image_src($attachment->ID, 'thumbnail');
$vspi_images[$i] = array(
- 'id' => $att->ID,
+ 'id' => $attachment->ID,
'src' => $thumbnail[0],
'width' => $thumbnail[1],
'height' => $thumbnail[2]
);
- if ($thumbnail_id == $att->ID) {
- $vspi_images[$i]['class'] = 'vspi_image vspi_thumb';
+ if ($thumbnail_id == $attachment->ID) {
+ $vspi_images[$i]['class'] = 'vspi_image vspi_is_featured_image';
} else {
$vspi_images[$i]['class'] = 'vspi_image';
}

0 comments on commit 4c081fb

Please sign in to comment.