diff --git a/includes/abstract/feedzy-rss-feeds-admin-abstract.php b/includes/abstract/feedzy-rss-feeds-admin-abstract.php index 8385d521..6a8445cb 100644 --- a/includes/abstract/feedzy-rss-feeds-admin-abstract.php +++ b/includes/abstract/feedzy-rss-feeds-admin-abstract.php @@ -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 ] . '"'; } diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index a9cdbb5d..fc81096c 100644 --- a/includes/admin/feedzy-rss-feeds-import.php +++ b/includes/admin/feedzy-rss-feeds-import.php @@ -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'] ) ) { @@ -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, @@ -1431,7 +1436,7 @@ 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, @@ -1439,6 +1444,19 @@ private function get_taxonomies() { '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; } } @@ -1446,6 +1464,25 @@ private function get_taxonomies() { wp_die(); } + /** + * Term IDs of a taxonomy among saved Post Taxonomy values. + * + * @param array $selected Saved values, `_` for terms. + * @param string $taxonomy Taxonomy name. + * + * @return list + */ + 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. * diff --git a/includes/feedzy-rss-feeds-feed-tweaks.php b/includes/feedzy-rss-feeds-feed-tweaks.php index a082dcb9..3f789bf7 100644 --- a/includes/feedzy-rss-feeds-feed-tweaks.php +++ b/includes/feedzy-rss-feeds-feed-tweaks.php @@ -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 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; +} diff --git a/includes/layouts/settings.php b/includes/layouts/settings.php index 6c927385..f7e4cf00 100644 --- a/includes/layouts/settings.php +++ b/includes/layouts/settings.php @@ -235,33 +235,9 @@ class="btn btn-outline-primary fz-auto-cat-delete $hourly ), $schedules ); - } - $internal_cron_schedules = apply_filters( 'feedzy_internal_cron_schedule_slugs', array() ); ?> +
@@ -645,24 +646,7 @@ class="fz-switch-toggle" type="checkbox" value="yes" $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 ) : ?>