Skip to content

Commit 50daceb

Browse files
refactor: add explicit fallback image option for importer (#1120)
The user can select between general settings and their custom fallback image.
1 parent 5835fea commit 50daceb

File tree

4 files changed

+1005
-608
lines changed

4 files changed

+1005
-608
lines changed

css/settings.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,32 @@ li.draggable-item .components-panel__body-toggle.components-button{
25592559
border-bottom: 0;
25602560
padding: 24px 0 0;
25612561
}
2562+
.fz-fallback-images {
2563+
display: flex;
2564+
flex-wrap: wrap;
2565+
gap: 1em;
2566+
margin: 1em 0 1em;
2567+
}
2568+
.feedzy-wrap .fz-spacing{
2569+
margin: 1em 0 1em;
2570+
}
2571+
.fz-radio-label {
2572+
font-weight: 600;
2573+
color: #333;
2574+
margin-bottom: 4px;
2575+
}
2576+
.fz-radio-description {
2577+
color: #666;
2578+
font-size: 13px;
2579+
line-height: 1.4;
2580+
display: block;
2581+
}
2582+
.fz-radio-title {
2583+
font-size: 16px;
2584+
font-weight: 600;
2585+
color: #050505;
2586+
}
2587+
25622588
@-webkit-keyframes spin {
25632589
100% { -webkit-transform: rotate(360deg); }
25642590
}

includes/admin/feedzy-rss-feeds-import.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,12 @@ public function feedzy_import_feed_options() {
524524
$import_feed_limit = 10;
525525
}
526526

527-
$default_thumbnail_id = 0;
527+
$default_thumbnail_id = 0;
528+
$inherited_thumbnail_id = ! empty( $this->free_settings['general']['default-thumbnail-id'] ) ? (int) $this->free_settings['general']['default-thumbnail-id'] : 0;
528529
if ( feedzy_is_pro() ) {
529530
$default_thumbnail_id = get_post_meta( $post->ID, 'default_thumbnail_id', true );
530-
if (
531-
empty( $default_thumbnail_id ) &&
532-
'0' !== $default_thumbnail_id // Can use the fallback image from Global Settings.
533-
) {
534-
$default_thumbnail_id = ! empty( $this->free_settings['general']['default-thumbnail-id'] ) ? (int) $this->free_settings['general']['default-thumbnail-id'] : 0;
535-
}
536531
}
532+
537533
$import_schedule = array(
538534
'fz_cron_schedule' => ! empty( $this->free_settings['general']['fz_cron_schedule'] ) ? $this->free_settings['general']['fz_cron_schedule'] : '',
539535
);

includes/views/import-metabox-edit.php

Lines changed: 151 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -702,42 +702,154 @@ class="fz-switch-toggle" type="checkbox" value="yes"
702702
<div class="form-block form-block-two-column <?php echo esc_attr( apply_filters( 'feedzy_upsell_class', '' ) ); ?>">
703703
<?php echo wp_kses_post( apply_filters( 'feedzy_upsell_content', '', 'fallback-image', 'import' ) ); ?>
704704
<div class="fz-left">
705-
<h4 class="h4"><?php esc_html_e( 'Fallback Image', 'feedzy-rss-feeds' ); ?> <?php echo ! feedzy_is_pro() ? ' <span class="pro-label">PRO</span>' : ''; ?></h4>
705+
<h4 class="h4">
706+
<?php esc_html_e( 'Fallback Image', 'feedzy-rss-feeds' ); ?> <?php echo ! feedzy_is_pro() ? ' <span class="pro-label">PRO</span>' : ''; ?>
707+
</h4>
706708
</div>
707709
<div class="fz-right">
708710
<div class="fz-form-group">
709-
<label class="form-label"><?php esc_html_e( 'Select an image to be the fallback featured image.', 'feedzy-rss-feeds' ); ?></label>
710-
<?php
711-
$btn_label = esc_html__( 'Choose image', 'feedzy-rss-feeds' );
712-
$default_thumbnail_id = ! empty( $default_thumbnail_id ) ? explode( ',', (string) $default_thumbnail_id ) : array();
713-
if ( ! empty( $default_thumbnail_id ) ) :
714-
$btn_label = esc_html__( 'Replace image', 'feedzy-rss-feeds' );
715-
?>
716-
<div class="fz-form-group mb-20 feedzy-media-preview">
717-
<?php
718-
if ( count( $default_thumbnail_id ) > 1 ) {
711+
<div class="form-label">
712+
<?php esc_html_e( 'Which fallback featured image should be used for this feed?', 'feedzy-rss-feeds' ); ?>
713+
</div>
714+
715+
<?php
716+
$fallback_option = ! empty( $default_thumbnail_id ) ? 'custom' : 'general';
717+
?>
718+
719+
<div class="fz-spacing">
720+
<input
721+
type="radio"
722+
id="use-general-fallback"
723+
name="feedzy_meta_data[fallback_image_option]"
724+
value="general"
725+
<?php checked( $fallback_option, 'general' ); ?>
726+
>
727+
<label for="use-general-fallback" class="fz-radio-label">
728+
<strong class="fz-radio-title">
729+
<?php esc_html_e( 'Use general setting', 'feedzy-rss-feeds' ); ?>
730+
</strong>
731+
<br>
732+
<span class="fz-radio-description">
733+
<?php esc_html_e( 'Updates automatically when the general fallback image changes.', 'feedzy-rss-feeds' ); ?>
734+
</span>
735+
</label>
736+
</div>
737+
738+
<div
739+
id="general-fallback-preview"
740+
class="fz-spacing"
741+
style="<?php echo 'general' === $fallback_option ? '' : 'display: none;'; ?>"
742+
>
743+
<?php if ( ! empty( $inherited_thumbnail_id ) ) : ?>
744+
<div class="fz-form-group">
745+
<?php
746+
$image = wp_get_attachment_image( $inherited_thumbnail_id, 'thumbnail' );
747+
if ( $image ) {
748+
echo wp_kses_post( $image );
749+
} else {
750+
echo '<div class="help-text">' . esc_html__( 'General fallback image not found (may have been deleted)', 'feedzy-rss-feeds' ) . '</div>';
751+
}
719752
?>
720-
<a href="javascript:;" class="btn btn-outline-primary feedzy-images-selected">
721-
<?php
722-
// translators: %d select images count.
723-
echo esc_html( sprintf( __( '(%d) images selected', 'feedzy-rss-feeds' ), count( $default_thumbnail_id ) ) );
753+
</div>
754+
<?php else : ?>
755+
<div class="fz-form-group mb-20">
756+
<div class="help-text">
757+
<?php
758+
echo wp_kses_post(
759+
__( 'No general fallback image set. ', 'feedzy-rss-feeds' )
760+
);
724761
?>
725-
</a>
726-
<?php
727-
} else {
728-
echo wp_get_attachment_image( reset( $default_thumbnail_id ), 'thumbnail' );
729-
}
762+
</div>
763+
</div>
764+
<?php endif; ?>
765+
766+
<div class="help-text pt-8">
767+
<?php
768+
echo wp_kses_post(
769+
sprintf(
770+
/* translators: %s is replaced with a link to the Feedzy Settings page */
771+
__( 'You can update the general fallback image in %s.', 'feedzy-rss-feeds' ),
772+
'<a href="' . esc_url( admin_url( 'admin.php?page=feedzy-settings' ) ) . '" target="_blank">' . esc_html__( 'Feedzy Settings', 'feedzy-rss-feeds' ) . '</a>'
773+
)
774+
);
730775
?>
731776
</div>
732-
<?php endif; ?>
733-
<div class="fz-cta-group pb-8">
734-
<a href="javascript:;" class="feedzy-open-media btn btn-outline-primary"><?php echo esc_html( $btn_label ); ?></a>
735-
<a href="javascript:;" class="feedzy-remove-media btn btn-outline-primary <?php echo ! empty( $default_thumbnail_id ) ? esc_attr( 'is-show' ) : ''; ?>"><?php esc_html_e( 'Remove', 'feedzy-rss-feeds' ); ?></a>
736-
<input type="hidden" name="feedzy_meta_data[default_thumbnail_id]" id="feed-post-default-thumbnail" value="<?php echo esc_attr( implode( ',', $default_thumbnail_id ) ); ?>">
737777
</div>
738-
<div class="help-text pt-8">
739-
<?php esc_html_e( 'Helpful for setting a fallback image for feed items without an image. If multiple fallback images are selected, one of them will be randomly assigned to each post without an image during the import process.', 'feedzy-rss-feeds' ); ?>
778+
779+
<div class="fz-spacing">
780+
<input
781+
type="radio"
782+
id="use-custom-fallback"
783+
name="feedzy_meta_data[fallback_image_option]"
784+
value="custom"
785+
<?php checked( $fallback_option, 'custom' ); ?>
786+
>
787+
<label for="use-custom-fallback" class="fz-radio-label">
788+
<strong class="fz-radio-title">
789+
<?php esc_html_e( 'Add custom fallback image', 'feedzy-rss-feeds' ); ?>
790+
</strong>
791+
<br>
792+
<span class="fz-radio-description small">
793+
<?php esc_html_e( 'Use a specific image just for this feed.', 'feedzy-rss-feeds' ); ?>
794+
</span>
795+
</label>
740796
</div>
797+
798+
<div
799+
id="custom-fallback-section"
800+
style="<?php echo 'custom' === $fallback_option ? '' : 'display: none;'; ?>"
801+
>
802+
<?php
803+
$btn_label = esc_html__( 'Choose image', 'feedzy-rss-feeds' );
804+
$saved_fallback_thumbnail_ids = is_string( $default_thumbnail_id ) ? explode( ',', $default_thumbnail_id ) : array();
805+
$valid_thumbnail_ids = array_filter( $saved_fallback_thumbnail_ids, 'is_numeric' );
806+
$valid_thumbnail_ids = array_filter(
807+
$valid_thumbnail_ids,
808+
function ( $id ) {
809+
return wp_attachment_is_image( intval( $id ) );
810+
}
811+
);
812+
813+
if ( ! empty( $valid_thumbnail_ids ) ) :
814+
$btn_label = esc_html__( 'Replace image', 'feedzy-rss-feeds' );
815+
?>
816+
<div class="fz-form-group feedzy-media-preview ">
817+
<div class="fz-fallback-images">
818+
<?php
819+
foreach ( $valid_thumbnail_ids as $thumbnail_id ) {
820+
echo wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
821+
}
822+
?>
823+
</div>
824+
</div>
825+
<?php endif; ?>
826+
827+
<div class="fz-cta-group pb-8">
828+
<a
829+
href="javascript:;"
830+
class="feedzy-open-media btn btn-outline-primary"
831+
>
832+
<?php
833+
echo esc_html( $btn_label );
834+
?>
835+
</a>
836+
<a
837+
href="javascript:;"
838+
class="feedzy-remove-media btn btn-outline-primary <?php echo ! empty( $valid_thumbnail_ids ) ? esc_attr( 'is-show' ) : ''; ?>"
839+
>
840+
<?php esc_html_e( 'Remove', 'feedzy-rss-feeds' ); ?>
841+
</a>
842+
<input
843+
type="hidden"
844+
name="feedzy_meta_data[default_thumbnail_id]"
845+
id="feed-post-default-thumbnail"
846+
value="<?php echo esc_attr( implode( ',', $valid_thumbnail_ids ) ); ?>"
847+
>
848+
</div>
849+
</div>
850+
</div>
851+
<div class="help-text pt-8">
852+
<?php esc_html_e( 'Helpful for setting a fallback image for feed items without an image during the import process.', 'feedzy-rss-feeds' ); ?>
741853
</div>
742854
</div>
743855
</div>
@@ -748,15 +860,22 @@ class="fz-switch-toggle" type="checkbox" value="yes"
748860

749861
<div class="form-block form-block-two-column no-border">
750862
<div class="fz-left">
751-
<h4 class="h4"><?php esc_html_e( 'Remove Duplicates', 'feedzy-rss-feeds' ); ?></h4>
863+
<h4 class="h4">
864+
<?php esc_html_e( 'Remove Duplicates', 'feedzy-rss-feeds' ); ?>
865+
</h4>
752866
</div>
753867
<div class="fz-right">
754868
<div class="fz-form-group">
755869
<div class="fz-form-switch">
756-
<input id="remove-duplicates" name="feedzy_meta_data[import_remove_duplicates]"
757-
class="fz-switch-toggle" type="checkbox" value="yes"
758-
<?php echo esc_attr( $import_remove_duplicates ); ?>>
759-
<label class="feedzy-inline form-label" for="remove-duplicates"><?php esc_html_e( 'Remove Duplicate Items', 'feedzy-rss-feeds' ); ?></label>
870+
<input
871+
id="remove-duplicates"
872+
name="feedzy_meta_data[import_remove_duplicates]"
873+
class="fz-switch-toggle" type="checkbox" value="yes"
874+
<?php echo esc_attr( $import_remove_duplicates ); ?>
875+
>
876+
<label class="feedzy-inline form-label" for="remove-duplicates">
877+
<?php esc_html_e( 'Remove Duplicate Items', 'feedzy-rss-feeds' ); ?>
878+
</label>
760879
</div>
761880
</div>
762881
<div class="help-text">

0 commit comments

Comments
 (0)