Skip to content
Merged

Release #1388

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
6 changes: 5 additions & 1 deletion includes/abstract/feedzy-rss-feeds-admin-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,13 @@ public function feedzy_rss( $atts, $content = '' ) {
if ( 'feedData' === $key ) {
continue;
}
if ( is_array( $val ) ) {
if ( is_array( $val ) && array_filter( $val, 'is_scalar' ) === $val ) {
$val = implode( ',', $val );
}
// Objects and nested arrays, like the block options other plugins register, have no data attribute form.
if ( null !== $val && ! is_scalar( $val ) ) {
continue;
}
$printed[ $key ] = esc_attr( $val );
$attributes .= 'data-' . esc_attr( $key ) . '="' . $printed[ $key ] . '"';
}
Expand Down
41 changes: 39 additions & 2 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,11 @@ public function save_feedzy_import_feed_meta( $post_id, $post ) {
$data_meta['import_use_external_image'] = isset( $data_meta['import_use_external_image'] ) ? $data_meta['import_use_external_image'] : 'no';
// Check feeds remove html checkbox checked OR not.
$data_meta['import_remove_html'] = isset( $data_meta['import_remove_html'] ) ? $data_meta['import_remove_html'] : 'no';
$data_meta['import_post_term'] = isset( $data_meta['import_post_term'] ) ? $data_meta['import_post_term'] : '';
// An unselected multiselect submits nothing, so a missing value means "cleared" only once the
// taxonomy options have loaded; otherwise the selector never loaded and the saved value is kept.
if ( ! isset( $data_meta['import_post_term'] ) && isset( $_POST['feedzy_post_terms_loaded'] ) ) {
$data_meta['import_post_term'] = '';
}

// If it is filter_conditions we want to escape it.
if ( isset( $data_meta['filter_conditions'] ) ) {
Expand Down Expand Up @@ -1423,6 +1427,7 @@ private function get_taxonomies() {
check_ajax_referer( FEEDZY_BASEFILE, 'security' );

$post_type = isset( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : '';
$selected = isset( $_POST['selected'] ) ? (array) map_deep( wp_unslash( $_POST['selected'] ), 'sanitize_text_field' ) : array();
$taxonomies = get_object_taxonomies(
array(
'post_type' => $post_type,
Expand All @@ -1431,21 +1436,53 @@ private function get_taxonomies() {
$results = array();
if ( ! empty( $taxonomies ) ) {
foreach ( $taxonomies as $taxonomy ) {
$terms = get_terms(
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'fields' => 'id=>name',
'number' => apply_filters( 'feedzy_post_taxonomy_limit', 999, $taxonomy ),
)
);
// Saved terms past the limit must stay selectable, or the next save drops them.
$missing = is_array( $terms ) ? array_diff( $this->get_saved_term_ids( $selected, $taxonomy ), array_keys( $terms ) ) : array();
if ( ! empty( $missing ) ) {
$saved_terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'fields' => 'id=>name',
'include' => $missing,
)
);
$terms += is_array( $saved_terms ) ? $saved_terms : array();
}
$results[ $taxonomy ] = $terms;
}
}
echo wp_json_encode( $results );
wp_die();
}

/**
* Term IDs of a taxonomy among saved Post Taxonomy values.
*
* @param array<mixed> $selected Saved values, `<taxonomy>_<term id>` for terms.
* @param string $taxonomy Taxonomy name.
*
* @return list<int>
*/
private function get_saved_term_ids( array $selected, string $taxonomy ): array {
$ids = array();
$pattern = '/^' . preg_quote( $taxonomy, '/' ) . '_(\d+)$/';
foreach ( $selected as $value ) {
if ( is_string( $value ) && preg_match( $pattern, $value, $match ) ) {
$ids[] = (int) $match[1];
}
}
return $ids;
}

/**
* Run a specific job.
*
Expand Down
45 changes: 45 additions & 0 deletions includes/feedzy-rss-feeds-feed-tweaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,48 @@ function ( $value ) use ( &$protected_blocks, $placeholder_tpl ) {

return $base_content;
}

/**
* List the cron schedules for a schedule dropdown, keeping the saved schedule selectable.
*
* A saved schedule that is no longer registered still gets an option, so saving the
* form keeps it instead of silently switching to the first schedule.
*
* @param string $saved_slug The saved schedule slug, or an empty string.
* @param string $first_slug The schedule listed first.
*
* @return array<string, string> Option labels keyed by schedule slug.
*/
function feedzy_get_schedule_options( string $saved_slug, string $first_slug ): array {
$schedules = wp_get_schedules();
if ( isset( $schedules[ $first_slug ] ) ) {
$schedules = array( $first_slug => $schedules[ $first_slug ] ) + $schedules;
}

$internal_cron_schedules = apply_filters( 'feedzy_internal_cron_schedule_slugs', array() );
$listed_intervals = array();
$options = array();
foreach ( $schedules as $slug => $schedule ) {
if ( empty( $schedule['interval'] ) ) {
continue;
}
if ( in_array( $schedule['interval'], $listed_intervals, true ) && $saved_slug !== $slug ) {
continue;
}
$listed_intervals[] = $schedule['interval'];
$label = $schedule['display'];

if ( ! in_array( $slug, $internal_cron_schedules, true ) ) {
// translators: (externally created) is used to indicate that the schedule is created by another plugin or manually.
$label .= ' (' . __( 'externally created', 'feedzy-rss-feeds' ) . ')';
}
$options[ $slug ] = $label;
}

if ( '' !== $saved_slug && ! isset( $options[ $saved_slug ] ) ) {
// translators: %s is the slug of a saved import schedule that is no longer registered.
$options[ $saved_slug ] = sprintf( __( '%s (unavailable)', 'feedzy-rss-feeds' ), $saved_slug );
}

return $options;
}
26 changes: 1 addition & 25 deletions includes/layouts/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,33 +235,9 @@ class="btn btn-outline-primary fz-auto-cat-delete<?php echo 0 === $index ? ' dis
<label class="form-label"><?php esc_html_e( 'Default Importing Schedule', 'feedzy-rss-feeds' ); ?></label>
<?php
$save_schedule = ! empty( $settings['general']['fz_cron_schedule'] ) ? $settings['general']['fz_cron_schedule'] : '';

$schedules = wp_get_schedules();
if ( isset( $schedules['hourly'] ) ) {
$hourly = $schedules['hourly'];
unset( $schedules['hourly'] );
$schedules = array_merge( array( 'hourly' => $hourly ), $schedules );
}
$internal_cron_schedules = apply_filters( 'feedzy_internal_cron_schedule_slugs', array() );
?>
<select id="fz-event-schedule" class="form-control fz-select-control" name="fz_cron_schedule">
<?php
$duplicate_schedule = array();
foreach ( $schedules as $slug => $schedule ) :
if (
empty( $schedule['interval'] ) ||
in_array( $schedule['interval'], $duplicate_schedule, true )
) {
continue;
}
$duplicate_schedule[] = $schedule['interval'];
$display_text = $schedule['display'];

if ( ! in_array( $slug, $internal_cron_schedules, true ) ) {
// translators: (externally created) is used to indicate that the schedule is created by another plugin or manually.
$display_text .= ' (' . esc_html__( 'externally created', 'feedzy-rss-feeds' ) . ')';
}
?>
<?php foreach ( feedzy_get_schedule_options( $save_schedule, 'hourly' ) as $slug => $display_text ) : ?>
<option
value="<?php echo esc_attr( $slug ); ?>"
<?php selected( $save_schedule, $slug ); ?>
Expand Down
20 changes: 2 additions & 18 deletions includes/views/import-metabox-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class="dashicons dashicons-arrow-down-alt2"></span>
<select id="feedzy_post_terms" data-placeholder="<?php esc_attr_e( 'Select Some Options', 'feedzy-rss-feeds' ); ?>" multiple class="form-control feedzy-chosen<?php echo feedzy_is_pro() ? ' fz-chosen-custom-tag' : ''; ?>"
name="feedzy_meta_data[import_post_term][]">
</select>
<input type="hidden" id="feedzy_post_terms_loaded" name="feedzy_post_terms_loaded" value="1" disabled>
</div>
<div class="help-text pt-8">
<?php esc_html_e( 'If you don\'t select at least one taxonomy, posts will be assigned to Uncategorized by default.', 'feedzy-rss-feeds' ); ?>
Expand Down Expand Up @@ -645,24 +646,7 @@ class="fz-switch-toggle" type="checkbox" value="yes"
<?php
$save_schedule = ! empty( $import_schedule['fz_cron_schedule'] ) ? $import_schedule['fz_cron_schedule'] : '';

$schedules = wp_get_schedules();
if ( isset( $schedules['daily'] ) ) {
$daily = $schedules['daily'];
unset( $schedules['daily'] );
$schedules = array_merge( array( 'daily' => $daily ), $schedules );
}
$internal_cron_schedules = apply_filters( 'feedzy_internal_cron_schedule_slugs', array() );
$duplicate_schedule = array();
foreach ( $schedules as $slug => $schedule ) :
if ( empty( $schedule['interval'] ) || in_array( $schedule['interval'], $duplicate_schedule, true ) ) {
continue;
}
$duplicate_schedule[] = $schedule['interval'];
$display_text = $schedule['display'];

if ( ! in_array( $slug, $internal_cron_schedules, true ) ) {
$display_text .= ' (' . esc_html__( 'externally created', 'feedzy-rss-feeds' ) . ')';
}
foreach ( feedzy_get_schedule_options( $save_schedule, 'daily' ) as $slug => $display_text ) :
?>
<option data-slug="<?php echo esc_attr( $slug ); ?>" value="<?php echo esc_attr( $slug ); ?>"<?php selected( $save_schedule, $slug ); ?>
<?php disabled( ! feedzy_is_pro() && 'daily' !== $slug ); ?>
Expand Down
10 changes: 10 additions & 0 deletions includes/views/js/import-metabox-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@
return false;
}

let taxonomyRequest = 0;

function update_taxonomy() {
const request = ++taxonomyRequest;
const selected = $(this).val();
let tax_selected = $(this).data('tax');
const custom_tag = $(this).data('custom-tag');
Expand All @@ -365,16 +368,22 @@
action: 'feedzy',
_action: 'get_taxonomies',
post_type: selected,
selected: tax_selected,
};

$('#feedzy_post_terms')
.html($('#loading_select_tpl').html())
.trigger('chosen:updated');
$('#feedzy_post_terms_loaded').prop('disabled', true);

$.post(
ajaxurl,
data,
function (response) {
// Superseded by a later post type change.
if (request !== taxonomyRequest) {
return;
}
let show_terms = true;

let options = '';
Expand Down Expand Up @@ -475,6 +484,7 @@
}

$('#feedzy_post_terms').html(options).trigger('chosen:updated');
$('#feedzy_post_terms_loaded').prop('disabled', false);
},
'json'
);
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/mu-plugins/feedzy-e2e-order-feed-mock.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: Feedzy E2E Order Feed Mock
* Description: Serves a canned feed whose items are deliberately not in chronological document order, so Feed Order tests can tell sorted output from the original feed order.
* Description: Serves a canned feed whose items are deliberately not in chronological document order, so Feed Order tests can tell sorted output from the original feed order. Its items carry no images, so thumbnail tests get the default image.
*
* @package feedzy-rss-feeds
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/e2e/mu-plugins/feedzy-e2e-taxonomy-limit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Plugin Name: Feedzy E2E Taxonomy Limit
* Description: Lists one term per taxonomy in Post Taxonomy on requests that post feedzy_e2e_taxonomy_limit, so e2e tests can cover saved terms past the limit.
*
* @package feedzy-rss-feeds
*/

add_filter(
'feedzy_post_taxonomy_limit',
function ( $limit ) {
return isset( $_POST['feedzy_e2e_taxonomy_limit'] ) ? 1 : $limit;
}
);
Loading
Loading