Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.8 compat #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@
.taxonomy-image-control .show {
visibility: visible;
}
body.taxonomy-images-modal {
background: #F1F1F1 !important;
}
3 changes: 2 additions & 1 deletion edit-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
29 changes: 23 additions & 6 deletions media-upload-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );
Expand Down Expand Up @@ -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( $( '<img />' ).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' );
} );

Expand Down
29 changes: 15 additions & 14 deletions taxonomy-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
);
}

Expand Down Expand Up @@ -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 ) ) {
Expand All @@ -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();
Expand All @@ -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' );
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = '<img id="' . esc_attr( 'taxonomy_image_plugin_' . $tt_id ) . '" src="' . esc_url( $img ) . '" alt="" style="width: 75px; height: auto;" />';
} else {
$img = '<span id="' . esc_attr( 'taxonomy_image_plugin_' . $tt_id ) . '" class="taxonomy-images-set-featured">Set Featured Image</span>';
}

$term = get_term( $term_id, $taxonomy->name );

$o = "\n" . '<div id="' . esc_attr( 'taxonomy-image-control-' . $tt_id ) . '" class="taxonomy-image-control hide-if-no-js">';
$o.= "\n" . '<a class="thickbox taxonomy-image-thumbnail" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=library&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Associate an image with the %1$s named &#8220;%2$s&#8221;.', 'taxonomy-images' ), $name, $term->name ) ) . '"><img id="' . esc_attr( 'taxonomy_image_plugin_' . $tt_id ) . '" src="' . esc_url( $img ) . '" alt="" /></a>';
$o.= "\n" . '<a class="control upload thickbox" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=type&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Upload a new image for this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Upload.', 'taxonomy-images' ) . '</a>';
$o.= "\n" . '<a class="control remove' . $hide . '" href="#" id="' . esc_attr( 'remove-' . $tt_id ) . '" rel="' . esc_attr( $tt_id ) . '" title="' . esc_attr( sprintf( __( 'Remove image from this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Delete', 'taxonomy-images' ) . '</a>';
$o.= "\n" . '<a class="thickbox taxonomy-image-thumbnail" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&width=800&tab=library&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Associate an image with the %1$s named &#8220;%2$s&#8221;.', 'taxonomy-images' ), $name, $term->name ) ) . '">'.$img.'</a>';
$o.= "\n" . '<a class="remove ' . $hide . '" href="#" id="' . esc_attr( 'remove-' . $tt_id ) . '" rel="' . esc_attr( $tt_id ) . '" title="' . esc_attr( sprintf( __( 'Remove image from this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Remove Featured Image' ) . '</a>';
$o.= "\n" . '<input type="hidden" class="tt_id" name="' . esc_attr( 'tt_id-' . $tt_id ) . '" value="' . esc_attr( $tt_id ) . '" />';

$o.= "\n" . '<input type="hidden" class="image_id" name="' . esc_attr( 'image_id-' . $tt_id ) . '" value="' . esc_attr( $attachment_id ) . '" />';
Expand Down Expand Up @@ -857,7 +858,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' => '<span class="taxonomy-images-set-featured">Set Featured Image</span>',
'tt_id' => 0,
'image_id' => 0,
) );
Expand Down