From 6a7e723f77c993ee82a237fb0e1afb4e2bd24b58 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Mon, 16 Nov 2026 18:29:35 +0530 Subject: [PATCH 1/6] fix: preserve unloaded post taxonomy selections --- includes/admin/feedzy-rss-feeds-import.php | 6 ++- includes/views/import-metabox-edit.php | 1 + includes/views/js/import-metabox-edit.js | 2 + tests/test-import.php | 58 ++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index a9cdbb5d..ad999abf 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'] ) ) { diff --git a/includes/views/import-metabox-edit.php b/includes/views/import-metabox-edit.php index 8bea31e6..67eb0bfd 100644 --- a/includes/views/import-metabox-edit.php +++ b/includes/views/import-metabox-edit.php @@ -184,6 +184,7 @@ class="dashicons dashicons-arrow-down-alt2"> +
diff --git a/includes/views/js/import-metabox-edit.js b/includes/views/js/import-metabox-edit.js index 21cc01b8..f50ce40c 100644 --- a/includes/views/js/import-metabox-edit.js +++ b/includes/views/js/import-metabox-edit.js @@ -370,6 +370,7 @@ $('#feedzy_post_terms') .html($('#loading_select_tpl').html()) .trigger('chosen:updated'); + $('#feedzy_post_terms_loaded').prop('disabled', true); $.post( ajaxurl, @@ -475,6 +476,7 @@ } $('#feedzy_post_terms').html(options).trigger('chosen:updated'); + $('#feedzy_post_terms_loaded').prop('disabled', false); }, 'json' ); diff --git a/tests/test-import.php b/tests/test-import.php index 6d8842eb..3bf488cd 100644 --- a/tests/test-import.php +++ b/tests/test-import.php @@ -684,6 +684,64 @@ public function test_clear_error_logs_ajax_allows_owner() { $this->assertEmpty( get_post_meta( $import_id, 'import_errors', true ) ); } + /** + * Saving without the taxonomy selector having loaded keeps the saved Post Taxonomy (#1385). + */ + public function test_save_keeps_post_terms_when_selector_not_loaded_1385() { + $import_id = $this->create_import_with_post_terms_1385(); + + $this->save_import_without_post_terms_1385( $import_id, false ); + + $this->assertEquals( '[#auto_categories],category_1', get_post_meta( $import_id, 'import_post_term', true ) ); + } + + /** + * Deselecting every term once the taxonomy selector has loaded still clears the saved Post Taxonomy (#1385). + */ + public function test_save_clears_post_terms_when_selector_loaded_1385() { + $import_id = $this->create_import_with_post_terms_1385(); + + $this->save_import_without_post_terms_1385( $import_id, true ); + + $this->assertFalse( metadata_exists( 'post', $import_id, 'import_post_term' ) ); + } + + /** + * Creates an import owned by an administrator with a saved Post Taxonomy selection. + * + * @return int The import post ID. + */ + private function create_import_with_post_terms_1385(): int { + $admin_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + wp_set_current_user( $admin_id ); + $import_id = $this->create_import( $admin_id ); + update_post_meta( $import_id, 'import_post_term', '[#auto_categories],category_1' ); + + return $import_id; + } + + /** + * Submits the import editor form with no Post Taxonomy option selected. + * + * @param int $import_id The import post ID. + * @param bool $selector_loaded Whether the taxonomy selector finished loading its options. + */ + private function save_import_without_post_terms_1385( int $import_id, bool $selector_loaded ): void { + $_POST = array( + 'feedzy_post_nonce' => wp_create_nonce( 'feedzy_post_nonce' ), + 'post_type' => 'feedzy_imports', + 'feedzy_meta_data' => array( + 'import_post_type' => 'post', + 'import_post_status' => 'publish', + ), + ); + if ( $selector_loaded ) { + $_POST['feedzy_post_terms_loaded'] = '1'; + } + + do_action( 'save_post_feedzy_imports', $import_id, get_post( $import_id ) ); + } + /** * Parses the given XML and returns the nodes requested as key value pairs. */ From df916193e576acc127fb4459dcdcb20c66ab8929 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 17 Nov 2026 12:20:52 +0530 Subject: [PATCH 2/6] fix: enhance taxonomy handling during post import --- includes/views/js/import-metabox-edit.js | 7 + tests/e2e/specs/import.spec.js | 209 +++++++++++++++++++++++ 2 files changed, 216 insertions(+) diff --git a/includes/views/js/import-metabox-edit.js b/includes/views/js/import-metabox-edit.js index f50ce40c..bbd3539e 100644 --- a/includes/views/js/import-metabox-edit.js +++ b/includes/views/js/import-metabox-edit.js @@ -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'); @@ -376,6 +379,10 @@ ajaxurl, data, function (response) { + // Superseded by a later post type change. + if (request !== taxonomyRequest) { + return; + } let show_terms = true; let options = ''; diff --git a/tests/e2e/specs/import.spec.js b/tests/e2e/specs/import.spec.js index cf051df8..133c1621 100644 --- a/tests/e2e/specs/import.spec.js +++ b/tests/e2e/specs/import.spec.js @@ -671,4 +671,213 @@ test.describe('Feed Import', () => { page.getByRole('heading', { name: 'Add actions to this tag' }) ).not.toBeVisible(); }); + + test.describe('Post Taxonomy', () => { + const TERM = 'category_1'; + const TAXONOMY_REQUEST = '_action=get_taxonomies'; + + /** + * @param {import('playwright').Page} page The page object. + * @return {Promise} + */ + const openMapContent = async (page) => { + await page + .getByRole('button', { name: 'Step 3 Map content ' }) + .click(); + }; + + /** + * @param {import('playwright').Page} page The page object. + * @return {Promise} + */ + const waitForTermsLoaded = async (page) => { + await expect( + page.locator('#feedzy_post_terms_loaded') + ).toBeEnabled(); + }; + + /** + * @param {import('playwright').Page} page The page object. + * @return {Promise} The selected Post Taxonomy values. + */ + const getSelectedTerms = (page) => + page + .locator('#feedzy_post_terms') + .evaluate((select) => + Array.from(select.selectedOptions, (option) => option.value) + ); + + /** + * @param {import('playwright').Page} page The page object. + * @param {string[]} terms The Post Taxonomy values to select. + * @return {Promise} + */ + const setSelectedTerms = (page, terms) => + page + .locator('#feedzy_post_terms') + .evaluate( + (select, values) => + window + .jQuery(select) + .val(values) + .trigger('chosen:updated'), + terms + ); + + /** + * @param {import('playwright').Page} page The page object. + * @param {string} postType The post type to switch to. + * @return {Promise} + */ + const setPostType = (page, postType) => + page + .locator('#feedzy_post_type') + .evaluate( + (select, value) => + window.jQuery(select).val(value).trigger('change'), + postType + ); + + /** + * Save the import and reopen its edit screen. + * + * @param {import('playwright').Page} page The page object. + * @return {Promise} + */ + const saveImport = async (page) => { + const postId = await page.locator('#post_ID').inputValue(); + await page.evaluate(() => { + window.onbeforeunload = null; + window.jQuery(window).off('beforeunload'); + }); + await Promise.all([ + page.waitForURL(/edit\.php\?post_type=feedzy_imports/), + page.getByRole('button', { name: 'Save', exact: true }).click(), + ]); + await page.goto(`/wp-admin/post.php?post=${postId}&action=edit`); + await tryCloseTourModal(page); + }; + + /** + * @param {import('playwright').Page} page The page object. + * @return {Promise} + */ + const createImportWithTerm = async (page) => { + await page.goto('/wp-admin/post-new.php?post_type=feedzy_imports'); + await tryCloseTourModal(page); + await page + .getByPlaceholder('Add a name for your import') + .fill('Post Taxonomy import'); + await addFeeds(page, [FEED_URL]); + await openMapContent(page); + await waitForTermsLoaded(page); + await setSelectedTerms(page, [TERM]); + await saveImport(page); + }; + + /** + * @param {import('playwright').Page} page The page object. + * @param {string[]} terms The expected Post Taxonomy values. + * @return {Promise} + */ + const expectSavedTerms = async (page, terms) => { + await openMapContent(page); + await waitForTermsLoaded(page); + expect(await getSelectedTerms(page)).toEqual(terms); + }; + + test('keeps terms when saved without opening Map Content', async ({ + page, + }) => { + await createImportWithTerm(page); + + await saveImport(page); + + await expectSavedTerms(page, [TERM]); + }); + + test('clears terms removed after they loaded', async ({ page }) => { + await createImportWithTerm(page); + + await openMapContent(page); + await waitForTermsLoaded(page); + await setSelectedTerms(page, []); + await saveImport(page); + + await expectSavedTerms(page, []); + }); + + test('keeps terms when saved while they are loading', async ({ + page, + }) => { + await createImportWithTerm(page); + + let releaseTaxonomies; + const taxonomiesHeld = new Promise((resolve) => { + releaseTaxonomies = resolve; + }); + await page.route(/admin-ajax\.php/, async (route) => { + if (!route.request().postData()?.includes(TAXONOMY_REQUEST)) { + return route.fallback(); + } + await taxonomiesHeld; + return route.abort(); + }); + + await openMapContent(page); + await expect( + page.locator('#feedzy_post_terms_loaded') + ).toBeDisabled(); + await saveImport(page); + releaseTaxonomies(); + await page.unrouteAll({ behavior: 'ignoreErrors' }); + + await expectSavedTerms(page, [TERM]); + }); + + test('ignores taxonomies of a superseded post type', async ({ + page, + }) => { + await createImportWithTerm(page); + await openMapContent(page); + await waitForTermsLoaded(page); + + let releaseStale; + const staleHeld = new Promise((resolve) => { + releaseStale = resolve; + }); + await page.route(/admin-ajax\.php/, async (route) => { + const body = route.request().postData() ?? ''; + if ( + body.includes(TAXONOMY_REQUEST) && + body.includes('post_type=page') + ) { + await staleHeld; + } + return route.fallback(); + }); + + await setPostType(page, 'page'); + await setPostType(page, 'post'); + await waitForTermsLoaded(page); + + await page.evaluate(() => { + window + .jQuery(document) + .on('ajaxComplete', (event, xhr, settings) => { + if (String(settings.data).includes('post_type=page')) { + window.feedzyStaleTaxonomiesHandled = true; + } + }); + }); + releaseStale(); + await page.waitForFunction( + () => window.feedzyStaleTaxonomiesHandled === true + ); + + expect(await getSelectedTerms(page)).toEqual([TERM]); + await saveImport(page); + await expectSavedTerms(page, [TERM]); + }); + }); }); From e907fac13e26f83e8f1464ecc2221d06208f49d0 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 17 Nov 2026 12:58:39 +0530 Subject: [PATCH 3/6] test: cover disabled taxonomy loaded flag on reload --- tests/e2e/specs/import.spec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/e2e/specs/import.spec.js b/tests/e2e/specs/import.spec.js index 133c1621..a864e65a 100644 --- a/tests/e2e/specs/import.spec.js +++ b/tests/e2e/specs/import.spec.js @@ -811,6 +811,9 @@ test.describe('Feed Import', () => { page, }) => { await createImportWithTerm(page); + // Load once so the flag starts enabled; the reload must disable it. + await openMapContent(page); + await waitForTermsLoaded(page); let releaseTaxonomies; const taxonomiesHeld = new Promise((resolve) => { @@ -824,7 +827,7 @@ test.describe('Feed Import', () => { return route.abort(); }); - await openMapContent(page); + await setPostType(page, 'post'); await expect( page.locator('#feedzy_post_terms_loaded') ).toBeDisabled(); From 6306c1c02a905d55fc73f0d65d78dc84630178e9 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 17 Nov 2026 13:08:44 +0530 Subject: [PATCH 4/6] fix: preserve saved terms beyond the taxonomy limit --- includes/admin/feedzy-rss-feeds-import.php | 35 ++++++++++- includes/views/js/import-metabox-edit.js | 1 + .../mu-plugins/feedzy-e2e-taxonomy-limit.php | 14 +++++ tests/e2e/specs/import.spec.js | 55 +++++++++++++++++ tests/test-import.php | 60 +++++++++++++++++++ 5 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/mu-plugins/feedzy-e2e-taxonomy-limit.php diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index ad999abf..fc81096c 100644 --- a/includes/admin/feedzy-rss-feeds-import.php +++ b/includes/admin/feedzy-rss-feeds-import.php @@ -1427,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, @@ -1435,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, @@ -1443,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; } } @@ -1450,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/views/js/import-metabox-edit.js b/includes/views/js/import-metabox-edit.js index bbd3539e..2aafe906 100644 --- a/includes/views/js/import-metabox-edit.js +++ b/includes/views/js/import-metabox-edit.js @@ -368,6 +368,7 @@ action: 'feedzy', _action: 'get_taxonomies', post_type: selected, + selected: tax_selected, }; $('#feedzy_post_terms') diff --git a/tests/e2e/mu-plugins/feedzy-e2e-taxonomy-limit.php b/tests/e2e/mu-plugins/feedzy-e2e-taxonomy-limit.php new file mode 100644 index 00000000..b8014f16 --- /dev/null +++ b/tests/e2e/mu-plugins/feedzy-e2e-taxonomy-limit.php @@ -0,0 +1,14 @@ + { await expectSavedTerms(page, [TERM]); }); + test('keeps saved terms past the taxonomy limit', async ({ + page, + requestUtils, + }) => { + // The saved "Uncategorized" sorts between these, so the limit lists only the first. + const createCategory = (name) => + requestUtils.rest({ + method: 'POST', + path: '/wp/v2/categories', + data: { name }, + }); + const categories = [ + await createCategory('AAA taxonomy limit'), + await createCategory('ZZZ taxonomy limit'), + ]; + + try { + await createImportWithTerm(page); + await page.route(/admin-ajax\.php/, (route) => { + const body = route.request().postData() ?? ''; + if (!body.includes(TAXONOMY_REQUEST)) { + return route.fallback(); + } + return route.fallback({ + postData: `${body}&feedzy_e2e_taxonomy_limit=1`, + }); + }); + + await openMapContent(page); + await waitForTermsLoaded(page); + expect( + await page + .locator( + '#feedzy_post_terms optgroup[label="Category"] option' + ) + .evaluateAll((options) => + options.map((option) => option.value).sort() + ) + ).toEqual([`category_${categories[0].id}`, TERM].sort()); + await saveImport(page); + + await expectSavedTerms(page, [TERM]); + } finally { + await Promise.all( + categories.map((category) => + requestUtils.rest({ + method: 'DELETE', + path: `/wp/v2/categories/${category.id}`, + params: { force: true }, + }) + ) + ); + } + }); + test('ignores taxonomies of a superseded post type', async ({ page, }) => { diff --git a/tests/test-import.php b/tests/test-import.php index 3bf488cd..694bbb92 100644 --- a/tests/test-import.php +++ b/tests/test-import.php @@ -742,6 +742,66 @@ private function save_import_without_post_terms_1385( int $import_id, bool $sele do_action( 'save_post_feedzy_imports', $import_id, get_post( $import_id ) ); } + /** + * Saved terms past the taxonomy limit are still returned, so the selector keeps them selected. + */ + public function test_get_taxonomies_returns_saved_terms_past_limit(): void { + wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); + $first_id = $this->factory->category->create( array( 'name' => 'AAA first' ) ); + $saved_id = $this->factory->category->create( array( 'name' => 'ZZZ saved' ) ); + $limit = static function (): int { + return 1; + }; + add_filter( 'feedzy_post_taxonomy_limit', $limit ); + + try { + $response = $this->get_taxonomies_response( 'post', array( '[#auto_categories]', 'category_' . $saved_id, 'post_tag_' . $saved_id ) ); + } finally { + remove_filter( 'feedzy_post_taxonomy_limit', $limit ); + } + + $this->assertSame( + array( + $first_id => 'AAA first', + $saved_id => 'ZZZ saved', + ), + $response['category'] + ); + $this->assertSame( array(), $response['post_tag'] ); + } + + /** + * Runs the get_taxonomies AJAX action. + * + * @param string $post_type Post type to list taxonomies for. + * @param list $selected Saved Post Taxonomy values. + * + * @return array> Term names keyed by taxonomy and term ID. + */ + private function get_taxonomies_response( string $post_type, array $selected ): array { + $_POST = array( + 'security' => wp_create_nonce( FEEDZY_BASEFILE ), + 'post_type' => $post_type, + 'selected' => $selected, + ); + $_REQUEST['security'] = $_POST['security']; + $import = new Feedzy_Rss_Feeds_Import( 'feedzy-rss-feeds', '1.2.0' ); + $method = new ReflectionMethod( $import, 'get_taxonomies' ); + $method->setAccessible( true ); + + ob_start(); + try { + $method->invoke( $import ); + } catch ( WPDieException $e ) { + // wp_die() ends the AJAX response. + } finally { + $output = (string) ob_get_clean(); + unset( $_REQUEST['security'] ); + } + + return json_decode( $output, true ); + } + /** * Parses the given XML and returns the nodes requested as key value pairs. */ From 1d5e9b1c47ddc228318585b07b3a68d7288e03a4 Mon Sep 17 00:00:00 2001 From: Girish Panchal <79647963+girishpanchal30@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:31:41 +0530 Subject: [PATCH 5/6] Fixed skip object attributes in lazy feeds (#1386) * fix: skip object attributes in lazy feeds * fix: e2e tests --- .../feedzy-rss-feeds-admin-abstract.php | 6 +++- .../mu-plugins/feedzy-e2e-order-feed-mock.php | 2 +- tests/e2e/specs/loop.spec.js | 7 ++++- tests/test-admin-abstract-helpers.php | 31 +++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) 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/tests/e2e/mu-plugins/feedzy-e2e-order-feed-mock.php b/tests/e2e/mu-plugins/feedzy-e2e-order-feed-mock.php index aa92af85..cead6912 100644 --- a/tests/e2e/mu-plugins/feedzy-e2e-order-feed-mock.php +++ b/tests/e2e/mu-plugins/feedzy-e2e-order-feed-mock.php @@ -1,7 +1,7 @@ { const FEED_URL = 'https://s3.amazonaws.com/verti-utils/sample-feed-import.xml'; @@ -226,7 +231,7 @@ test.describe('Feedzy Loop', () => { attributes: { feed: { type: 'url', - source: 'https://fasterthanli.me/index.xml', + source: getOrderFeedUrl(page, 'svg-thumbnail'), }, query: { max: 1, diff --git a/tests/test-admin-abstract-helpers.php b/tests/test-admin-abstract-helpers.php index fa25caa8..346e77df 100644 --- a/tests/test-admin-abstract-helpers.php +++ b/tests/test-admin-abstract-helpers.php @@ -644,6 +644,37 @@ public function lazy_placeholder_attributes() { 'lazy' => 'yes', ), ), + 'objects' => array( $this->widget_options_block_attributes() ), + ); + } + + /** + * Test issue 1360: object and nested array block attributes are left out of the lazy placeholder. + */ + public function test_lazy_placeholder_skips_object_block_attributes_issue_1360() { + $html = $this->lazy_feedzy()->feedzy_rss( $this->widget_options_block_attributes() ); + + $this->assertStringNotContainsString( 'data-extended_widget_opts=', $html ); + $this->assertStringNotContainsString( 'data-extended_widget_opts_block=', $html ); + $this->assertStringContainsString( 'data-extended_widget_opts_state=""', $html ); + } + + /** + * Lazy block attributes with the options Widget Options adds to every block: an empty + * object by default, and nested arrays once its settings are saved. + * + * @return array + */ + private function widget_options_block_attributes() { + return array( + 'feeds' => 'https://example.com/feed', + 'lazy' => true, + 'extended_widget_opts_block' => new stdClass(), + 'extended_widget_opts' => array( + 'id_base' => 'feedzy', + 'visibility' => array( 'options' => 'hide' ), + ), + 'extended_widget_opts_state' => '', ); } From e88462dcda1e659862c59766fcede11a7b68d844 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Thu, 19 Nov 2026 15:44:28 +0530 Subject: [PATCH 6/6] fix: preserve unavailable saved import intervals --- includes/feedzy-rss-feeds-feed-tweaks.php | 45 +++++++ includes/layouts/settings.php | 26 +--- includes/views/import-metabox-edit.php | 19 +-- tests/test-import-schedule-options.php | 154 ++++++++++++++++++++++ 4 files changed, 201 insertions(+), 43 deletions(-) create mode 100644 tests/test-import-schedule-options.php 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() ); ?> #s', $markup, $matches ) ); + + return $matches[0]; + } + + /** + * Returns the slugs of the selected options in a select's markup. + * + * @param string $markup Select markup. + * + * @return list + */ + private function selected_slugs( string $markup ): array { + preg_match_all( '#value="([^"]*)"\s*selected=#', $markup, $matches ); + + return $matches[1]; + } +}