diff --git a/admin.css b/admin.css
index 3aab59f..597e1b4 100644
--- a/admin.css
+++ b/admin.css
@@ -55,3 +55,6 @@
.taxonomy-image-control .show {
visibility: visible;
}
+body.taxonomy-images-modal {
+ background: #F1F1F1 !important;
+}
\ No newline at end of file
diff --git a/edit-tags.js b/edit-tags.js
index fd9bcc7..80313f0 100644
--- a/edit-tags.js
+++ b/edit-tags.js
@@ -20,7 +20,8 @@ jQuery( document ).ready( function( $ ) {
success: function ( response ) {
if ( 'good' === response.status ) {
$( '#remove-' + taxonomyImagesPlugin.tt_id ).addClass( 'hide' );
- $( '#taxonomy_image_plugin_' + taxonomyImagesPlugin.tt_id ).attr( 'src', taxonomyImagesPlugin.img_src );
+ var imgId = 'taxonomy_image_plugin_' + taxonomyImagesPlugin.tt_id;
+ $( '#' + imgId ).replaceWith( $( taxonomyImagesPlugin.no_img ).attr( 'id', imgId ) ).remove();
}
else if ( 'bad' === response.status ) {
alert( response.why );
diff --git a/media-upload-popup.js b/media-upload-popup.js
index 05a403b..8b28f86 100644
--- a/media-upload-popup.js
+++ b/media-upload-popup.js
@@ -58,8 +58,19 @@ jQuery( document ).ready( function( $ ) {
if ( 'good' === response.status ) {
button.html( TaxonomyImagesModal.removed ).fadeOut( 200, function() {
$( this ).hide();
- var selector = parent.document.getElementById( 'taxonomy_image_plugin_' + ID );
- $( selector ).attr( 'src', below.taxonomyImagesPlugin.img_src );
+
+ // remove the thumbnail & replace it with "set featured image"
+ var oldImage = parent.document.getElementById( 'taxonomy_image_plugin_' + ID );
+ $( oldImage ).replaceWith( $( below.taxonomyImagesPlugin.no_img ).attr( 'id', 'taxonomy_image_plugin_' + ID ) );
+
+ // hide the remove button that was under the thumbnail
+ var removeBtn = parent.document.getElementById( 'remove-' + ID );
+ $( removeBtn ).addClass( 'hide' );
+
+ // update the hidden image id field
+ $( parent.document.getElementById( 'taxonomy-image-control-' + ID ) ).find( '.image_id' ).val( '0' );
+
+ // show the create association button
$( this ).parent().find( '.create-association' ).show();
$( this ).html( originalText );
} );
@@ -105,15 +116,21 @@ jQuery( document ).ready( function( $ ) {
$( e ).find( '.remove-association' ).hide();
} );
- selector = parent.document.getElementById( 'taxonomy-image-control-' + ID );
+ var $selector = $( parent.document.getElementById( 'taxonomy-image-control-' + ID ) );
/* Update the image on the screen below */
- $( selector ).find( '.taxonomy-image-thumbnail img' ).each( function ( i, e ) {
- $( e ).attr( 'src', response.attachment_thumb_src );
+ $selector.find( '.taxonomy-images-set-featured' ).each( function ( i, e ) {
+ $( e ).replaceWith( $( '' ).attr({
+ 'src' : response.attachment_thumb_src,
+ 'id' : $( e ).attr( 'id' )
+ }) );
} );
+ // Update the hidden image_id field
+ $selector.find( '.image_id' ).val( response.image_id );
+
/* Show delete control on the screen below */
- $( selector ).find( '.remove' ).each( function ( i, e ) {
+ $selector.find( '.remove' ).each( function ( i, e ) {
$( e ).removeClass( 'hide' );
} );
diff --git a/taxonomy-images.php b/taxonomy-images.php
index ff5312c..8bcf256 100644
--- a/taxonomy-images.php
+++ b/taxonomy-images.php
@@ -69,7 +69,7 @@ function taxonomy_image_plugin_url( $file = '' ) {
function taxonomy_image_plugin_detail_image_size() {
return array(
'name' => 'detail',
- 'size' => array( 75, 75, true )
+ 'size' => array( 150, 150, true )
);
}
@@ -173,11 +173,7 @@ function taxonomy_image_plugin_get_image_src( $id ) {
if ( is_file( $path ) ) {
/* Attempt to create a new downsized version of the original image. */
- $new = image_resize( $path,
- $detail['size'][0],
- $detail['size'][1],
- $detail['size'][2]
- );
+ $new = wp_get_image_editor( $path, $detail['size'] );
/* Image creation successful. Generate and cache image metadata. Return url. */
if ( ! is_wp_error( $new ) ) {
@@ -203,10 +199,9 @@ function taxonomy_image_plugin_get_image_src( $id ) {
/*
* No image can be found.
- * This is most likely caused by a user deleting an attachment before deleting it's association with a taxonomy.
* If we are in the administration panels:
* - Delete the association.
- * - Return uri to default.png.
+ * - Return false.
*/
if ( is_admin() ) {
$assoc = taxonomy_image_plugin_get_associations();
@@ -216,11 +211,12 @@ function taxonomy_image_plugin_get_image_src( $id ) {
}
}
update_option( 'taxonomy_image_plugin', $assoc );
- return taxonomy_image_plugin_url( 'default.png' );
+ return false;
}
/*
* No image can be found.
+ * This is most likely caused by a user deleting an attachment before deleting it's association with a taxonomy.
* Return path to blank-image.png.
*/
return taxonomy_image_plugin_url( 'blank.png' );
@@ -555,7 +551,8 @@ function taxonomy_image_plugin_create_association() {
taxonomy_image_plugin_json_response( array(
'status' => 'good',
'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
- 'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id )
+ 'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id ),
+ 'image_id' => $image_id,
) );
}
else {
@@ -795,13 +792,17 @@ function taxonomy_image_plugin_control_image( $term_id, $taxonomy ) {
}
$img = taxonomy_image_plugin_get_image_src( $attachment_id );
+ if ( $img ) {
+ $img = '
';
+ } else {
+ $img = 'Set Featured Image';
+ }
$term = get_term( $term_id, $taxonomy->name );
$o = "\n" . '