From 48040a56a18bc5762f298e27e91c6b029dbf4a2d Mon Sep 17 00:00:00 2001 From: jessica Date: Sat, 22 Mar 2014 17:58:28 -0400 Subject: [PATCH 1/5] Make images retina sized --- taxonomy-images.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taxonomy-images.php b/taxonomy-images.php index ff5312c..b6e7027 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 ) ); } From 8ddb24cdb549a9bd259fdc8e6d2bdef980f475c3 Mon Sep 17 00:00:00 2001 From: jessica Date: Sat, 22 Mar 2014 17:58:42 -0400 Subject: [PATCH 2/5] Stop using deprecated image_resize() function --- taxonomy-images.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/taxonomy-images.php b/taxonomy-images.php index b6e7027..78b7a31 100644 --- a/taxonomy-images.php +++ b/taxonomy-images.php @@ -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 ) ) { From 9312ac12cce812aaebd2b587b6234e47376b41d2 Mon Sep 17 00:00:00 2001 From: jessica Date: Sat, 22 Mar 2014 23:41:40 -0400 Subject: [PATCH 3/5] Use set/remove featured image text to match featured image UI on posts --- edit-tags.js | 3 ++- media-upload-popup.js | 13 +++++++++---- taxonomy-images.php | 18 +++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) 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..852e18a 100644 --- a/media-upload-popup.js +++ b/media-upload-popup.js @@ -58,8 +58,10 @@ 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 ); + var oldImage = parent.document.getElementById( 'taxonomy_image_plugin_' + ID ); + $( oldImage ).replaceWith( $(below.taxonomyImagesPlugin.no_img).attr( 'id', 'taxonomy_image_plugin_' + ID ) ); + var removeBtn = parent.document.getElementById( 'remove-' + ID ); + $( removeBtn ).addClass( 'hide' ); $( this ).parent().find( '.create-association' ).show(); $( this ).html( originalText ); } ); @@ -108,8 +110,11 @@ jQuery( document ).ready( function( $ ) { 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' ) + }) ); } ); /* Show delete control on the screen below */ diff --git a/taxonomy-images.php b/taxonomy-images.php index 78b7a31..5357fd3 100644 --- a/taxonomy-images.php +++ b/taxonomy-images.php @@ -199,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(); @@ -212,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' ); @@ -791,13 +791,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" . '
'; - $o.= "\n" . ''; - $o.= "\n" . '' . esc_html__( 'Upload.', 'taxonomy-images' ) . ''; - $o.= "\n" . '' . esc_html__( 'Delete', 'taxonomy-images' ) . ''; + $o.= "\n" . ''.$img.''; + $o.= "\n" . '' . esc_html__( 'Remove Featured Image' ) . ''; $o.= "\n" . ''; $o.= "\n" . ''; @@ -853,7 +857,7 @@ function taxonomy_image_plugin_edit_tags_js() { ); wp_localize_script( 'taxonomy-image-plugin-edit-tags', 'taxonomyImagesPlugin', array ( 'nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ), - 'img_src' => taxonomy_image_plugin_url( 'default.png' ), + 'no_img' => 'Set Featured Image', 'tt_id' => 0, 'image_id' => 0, ) ); From 274416cd5d82b7e2180542535fa6d7477dde7702 Mon Sep 17 00:00:00 2001 From: jessica Date: Sat, 22 Mar 2014 23:56:14 -0400 Subject: [PATCH 4/5] Make create / remove association buttons in modal work properly on second modal open --- media-upload-popup.js | 20 ++++++++++++++++---- taxonomy-images.php | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/media-upload-popup.js b/media-upload-popup.js index 852e18a..8b28f86 100644 --- a/media-upload-popup.js +++ b/media-upload-popup.js @@ -58,10 +58,19 @@ jQuery( document ).ready( function( $ ) { if ( 'good' === response.status ) { button.html( TaxonomyImagesModal.removed ).fadeOut( 200, function() { $( this ).hide(); + + // 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 ) ); + $( 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 ); } ); @@ -107,18 +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-images-set-featured' ).each( function ( i, e ) { + $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 5357fd3..8bcf256 100644 --- a/taxonomy-images.php +++ b/taxonomy-images.php @@ -551,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 { From bc733226cd0a0e10cd25fb361209370f32c9f488 Mon Sep 17 00:00:00 2001 From: jessica Date: Sun, 23 Mar 2014 00:07:34 -0400 Subject: [PATCH 5/5] Set background in modal window to light gray, to avoid color switch --- admin.css | 3 +++ 1 file changed, 3 insertions(+) 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