From 7119f37d4f32959ba83d8b9be476e068d8007d45 Mon Sep 17 00:00:00 2001 From: umesh Date: Fri, 13 Nov 2026 12:01:30 +0530 Subject: [PATCH] Administration: Use the taxonomy's `not_found` label when the last term is deleted via AJAX. When the last term in a taxonomy list table was removed with the AJAX Delete link, `tags.js` inserted an empty-state row with the hardcoded string "No tags found.". This was shown for every taxonomy, so Categories and custom taxonomies displayed the wrong message until the page was reloaded, when `WP_Terms_List_Table::no_items()` printed the correct label. Localize the current taxonomy's `not_found` label for the `admin-tags` script on `edit-tags.php` and use it for the empty-state row. The label is inserted as text, because it is filterable and may contain markup. If the data is missing, fall back to a generic "No items found." string. Adds an end-to-end test that deletes the last matching term on the Categories and Tags screens and checks the empty-state message. --- src/js/_enqueues/admin/tags.js | 21 ++++++++------- src/wp-admin/edit-tags.php | 8 ++++++ tests/e2e/specs/taxonomies.test.js | 43 ++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/js/_enqueues/admin/tags.js b/src/js/_enqueues/admin/tags.js index 8d449ca986863..f410a51b1cda0 100644 --- a/src/js/_enqueues/admin/tags.js +++ b/src/js/_enqueues/admin/tags.js @@ -135,17 +135,20 @@ jQuery( function($) { ); if ( itemCount < 1 ) { - // No tags remain: show the empty-state row and hide the navigation. + // No terms remain: show the empty-state row and hide the navigation. var $list = $( '#the-list' ); - if ( ! $list.find( 'tr.no-items' ).length ) { - var colspan = $list.closest( 'table' ).find( 'thead > tr' ).first().children( ':not(.hidden)' ).length; - $list.append( - '' + - wp.i18n.__( 'No tags found.' ) + - '' - ); - } + if ( ! $list.find( 'tr.no-items' ).length ) { + var colspan = $list.closest( 'table' ).find( 'thead > tr' ).first().children( ':not(.hidden)' ).length; + + $( '' ) + .find( 'td' ) + .attr( 'colspan', colspan ) + // The label is filterable and may contain markup, so insert it as text. + .text( window.tagsL10n && window.tagsL10n.notFound || wp.i18n.__( 'No items found.' ) ) + .end() + .appendTo( $list ); + } $( '.tablenav > *' ).hide(); $( 'p.search-box' ).hide(); } else { diff --git a/src/wp-admin/edit-tags.php b/src/wp-admin/edit-tags.php index 6efdeb9b0527d..8e2cc70d2c00e 100644 --- a/src/wp-admin/edit-tags.php +++ b/src/wp-admin/edit-tags.php @@ -241,6 +241,14 @@ } wp_enqueue_script( 'admin-tags' ); +wp_localize_script( + 'admin-tags', + 'tagsL10n', + array( + // The taxonomy's "not found" label, used when the last term is removed via AJAX. + 'notFound' => $tax->labels->not_found, + ) +); if ( current_user_can( $tax->cap->edit_terms ) ) { wp_enqueue_script( 'inline-edit-tax' ); } diff --git a/tests/e2e/specs/taxonomies.test.js b/tests/e2e/specs/taxonomies.test.js index 2849e086e01b5..63d7a904bebdc 100644 --- a/tests/e2e/specs/taxonomies.test.js +++ b/tests/e2e/specs/taxonomies.test.js @@ -164,6 +164,49 @@ for ( const { taxonomy, endpoint, label } of [ expect( terms ).toEqual( [] ); } ); + test( 'shows the taxonomy label when the last matching term is deleted', async ( { + admin, + page, + requestUtils, + } ) => { + const term = await createTerm( requestUtils, 'delete-last' ); + await admin.visitAdminPage( + '/edit-tags.php', + `taxonomy=${ taxonomy }&s=${ prefix }` + ); + const row = page.locator( `#tag-${ term.id }` ); + await expect( row ).toBeVisible(); + await row.hover(); + await Promise.all( [ + page + .waitForEvent( 'dialog' ) + .then( ( dialog ) => dialog.accept() ), + row + .getByRole( 'button', { + name: `Delete “${ term.name }”`, + exact: true, + } ) + .click(), + ] ); + + // The row inserted by JavaScript must match the server-rendered message. + await expect( + page.getByRole( 'cell', { + name: + taxonomy === 'category' + ? 'No categories found.' + : 'No tags found.', + exact: true, + } ) + ).toBeVisible(); + await expect( + page.getByRole( 'cell', { + name: 'No tags found.', + exact: true, + } ) + ).toHaveCount( taxonomy === 'category' ? 0 : 1 ); + } ); + test( 'shows an empty result when searching for a missing term', async ( { admin, page,