Skip to content

Commit

Permalink
another fix for #1498
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Aug 9, 2017
1 parent 7120253 commit 85b7b99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 4 additions & 11 deletions controls/image/class-kirki-control-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,13 @@ protected function render_content() {}
protected function content_template() {
?>
<#
var saveAs = 'url',
url = '';

var saveAs = 'url';
if ( ! _.isUndefined( data.choices ) && ! _.isUndefined( data.choices.save_as ) ) {
saveAs = data.choices.save_as;
}
if ( 'url' === saveAs ) {
url = data.value;
}
if ( 'array' === saveAs && data.value['url'] ) {
url = data.value['url'];
}
if ( 'id' === saveAs ) {
url = <?php echo ( is_int( $this->value() ) ) ? wp_get_attachment_url( $this->value() ) : "''"; ?>
url = data.value;
if ( _.isObject( data.value ) && ! _.isUndefined( data.value.url ) ) {
url = data.value.url;
}
#>
<label>
Expand Down
10 changes: 10 additions & 0 deletions controls/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ wp.customize.controlConstructor['kirki-image'] = wp.customize.Control.extend({

control.container.find( '.kirki-controls-loading-spinner' ).hide();

// Tweaks for save_as = id.
if ( ( 'id' === saveAs || 'ID' === saveAs ) && '' !== value ) {
wp.media.attachment( value ).fetch().then( function( mediaData ) {
setTimeout( function() {
var url = wp.media.attachment( value ).get( 'url' );
preview.removeClass().addClass( 'thumbnail thumbnail-image' ).html( '<img src="' + url + '" alt="" />' );
}, 700 );
} );
}

// If value is not empty, hide the "default" button.
if ( ( 'url' === saveAs && '' !== value ) || ( 'array' === saveAs && ! _.isUndefined( value.url ) && '' !== value.url ) ) {
control.container.find( 'image-default-button' ).hide();
Expand Down

0 comments on commit 85b7b99

Please sign in to comment.