Skip to content

Commit

Permalink
Merge pull request #941 from Codeinwp/fix/global-fallback-img
Browse files Browse the repository at this point in the history
fix: allow user to exclude global fallback image in feed settings
  • Loading branch information
vytisbulkevicius authored May 30, 2024
2 parents 802cfaf + 079628c commit 958e2b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
8 changes: 7 additions & 1 deletion includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ public function feedzy_import_feed_options() {
$default_thumbnail_id = 0;
if ( feedzy_is_pro() ) {
$default_thumbnail_id = get_post_meta( $post->ID, 'default_thumbnail_id', true );
if ( empty( $default_thumbnail_id ) ) {
if (
empty( $default_thumbnail_id ) &&
'0' !== $default_thumbnail_id // Can use the fallback image from Global Settings.
) {
$default_thumbnail_id = ! empty( $this->free_settings['general']['default-thumbnail-id'] ) ? (int) $this->free_settings['general']['default-thumbnail-id'] : 0;
}
}
Expand Down Expand Up @@ -525,6 +528,9 @@ public function save_feedzy_import_feed_meta( $post_id, $post ) {
add_post_meta( $post_id, $key, $value );
}
if ( ! $value ) {
if ( 'default_thumbnail_id' === $key && '0' === $value ) { // Mark the feed as having no default fallback image (including the global fallback).
continue;
}
delete_post_meta( $post_id, $key );
}
}
Expand Down
29 changes: 19 additions & 10 deletions includes/views/js/import-metabox-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
feedzyAccordion();
feedzyTab();
feedzyMediaUploader();
initRemoveFallbackImageBtn();
});

function initImportScreen() {
Expand Down Expand Up @@ -859,15 +860,23 @@
$( '.feedzy-open-media' ).html( feedzy.i10n.action_btn_text_2 );
} ).open();
});

// on remove button click
$( 'body' ).on( 'click', '.feedzy-remove-media', function( e ) {
e.preventDefault();
var button = $( this );
button.parent().prev( '.feedzy-media-preview' ).remove();
button.removeClass( 'is-show' );
button.parent().find( 'input:hidden' ).val( '' ).trigger( 'change' );
$( '.feedzy-open-media' ).html( feedzy.i10n.action_btn_text_1 );
});
}
}(jQuery, feedzy));

/**
* Initialize the remove fallback image button from General Feed Settings tab.
*/
function initRemoveFallbackImageBtn() {
const removeFallbackImage = document.querySelector('.feedzy-remove-media');
removeFallbackImage?.addEventListener('click', (e) => {
e.preventDefault();

// Reset the image preview.
document.querySelector('.feedzy-media-preview').remove();
removeFallbackImage.classList.remove('is-show');

// Reset the input.
document.querySelector('input[name="feedzy_meta_data[default_thumbnail_id]"]').value = '0';
document.querySelector('.feedzy-open-media').innerHTML = feedzy.i10n.action_btn_text_1;
});
}

0 comments on commit 958e2b2

Please sign in to comment.