Skip to content

Content Types: Add checkbox for deletion of terms - #78629

Closed
im3dabasia wants to merge 2 commits into
WordPress:trunkfrom
im3dabasia:feat/delete-terms
Closed

im3dabasia wants to merge 2 commits into
WordPress:trunkfrom
im3dabasia:feat/delete-terms

Conversation

@im3dabasia

@im3dabasia im3dabasia commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

What?

Part of #77600

This PR adds a checkbox to delete terms associated with a taxonomy when the taxonomy/taxonomies are deleted in the UI.

Why?

Cleans up database with orphan terms in the db.

How?

Introduced delete_terms a extra key in the API, which when passed assumes we want to delete the terms in the DB .

Testing Instructions

  1. Add a taxonomy
  2. Delete the recently added taxonomy
  3. Observe that the terms are now deleted in the database by visiting this URL, http://localhost:9000/index.php?route=/database/structure&db=wordpress, depends if you are using docker based development setup.

Screenshots or screencast

Before

Screen.Recording.2026-05-25.at.5.50.35.PM.mov

After

Screen.Recording.2026-05-25.at.5.47.45.PM.mov

@im3dabasia
im3dabasia requested review from ntsekouras and tyxla May 25, 2026 12:27
@im3dabasia
im3dabasia marked this pull request as ready for review May 25, 2026 12:27
@im3dabasia
im3dabasia requested a review from spacedmonkey as a code owner May 25, 2026 12:27
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ntsekouras ntsekouras left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've left some initial comments to iterate.

$response = parent::delete_item( $request );
$taxonomy_slug = $existing instanceof WP_Post ? $existing->post_name : '';

// Delete all terms belonging to this taxonomy before removing the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we deleted the terms and then the taxonomy deletion failed, it would be a way bigger problem than the current one (orphaned terms).

// Delete all terms belonging to this taxonomy before removing the
// record, so no orphaned rows are left in wp_terms / wp_term_taxonomy.
// Note: only active (published) taxonomies are registered in-memory;
// terms under inactive taxonomies are not cleaned up here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to address this feature properly, we should also handle the inactive entities, even though the active/inactive feature might also be removed later..

Maybe a way for this would be to to register on the fly the inactive taxonomy in order to properly delete terms? 🤔

// record, so no orphaned rows are left in wp_terms / wp_term_taxonomy.
// Note: only active (published) taxonomies are registered in-memory;
// terms under inactive taxonomies are not cleaned up here.
if ( $request['delete_terms'] && '' !== $taxonomy_slug && taxonomy_exists( $taxonomy_slug ) ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any request param (e.g. delete_terms) handled by the controller should be properly declared as one in the controller. We shouldn't read from $request like that.

@im3dabasia im3dabasia mentioned this pull request May 26, 2026
23 of 49 tasks
@@ -150,6 +154,16 @@ function DeleteTaxonomyModal( {
items[ 0 ].title.raw
) }
</Text>
<CheckboxControl

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're not clear in the interface that this only applies to active taxonomies. Perhaps this checkbox should only appear for active taxonomies?

// record, so no orphaned rows are left in wp_terms / wp_term_taxonomy.
// Note: only active (published) taxonomies are registered in-memory;
// terms under inactive taxonomies are not cleaned up here.
if ( $request['delete_terms'] && '' !== $taxonomy_slug && taxonomy_exists( $taxonomy_slug ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so we're limiting deletion of terms just to active taxonomies. But what happens to the terms of taxonomies that were once active and were deactivated later? Won't these remain orphans forever as well? How are we handling them?

// record, so no orphaned rows are left in wp_terms / wp_term_taxonomy.
// Note: only active (published) taxonomies are registered in-memory;
// terms under inactive taxonomies are not cleaned up here.
if ( $request['delete_terms'] && '' !== $taxonomy_slug && taxonomy_exists( $taxonomy_slug ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be useful to have some tests for the deletion of terms, especially ones that handle various cases (active/inactive taxonomies for example).

);
if ( is_array( $term_ids ) ) {
foreach ( $term_ids as $term_id ) {
wp_delete_term( (int) $term_id, $taxonomy_slug );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we handling term deletion errors?

// record, so no orphaned rows are left in wp_terms / wp_term_taxonomy.
// Note: only active (published) taxonomies are registered in-memory;
// terms under inactive taxonomies are not cleaned up here.
if ( $request['delete_terms'] && '' !== $taxonomy_slug && taxonomy_exists( $taxonomy_slug ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it doesn't seem like we're handling permissions correctly, specifically: can the current user delete terms? The endpoint will only check if the user can delete these posts (wp_user_taxonomy) but not terms from that taxonomy - it needs a delete_terms or similar cap check and should most likely be handled at the controller level.

@@ -150,6 +154,16 @@ function DeleteTaxonomyModal( {
items[ 0 ].title.raw
) }
</Text>
<CheckboxControl

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we don't seem to be checking if the current user is authorized to delete terms from these taxonomies.

);
if ( is_array( $term_ids ) ) {
foreach ( $term_ids as $term_id ) {
wp_delete_term( (int) $term_id, $taxonomy_slug );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also imagine this is deleting thousands of terms. With all term and post hooks and cache cleanup that fire here, this might be disastrous - might make sense to consider batching. Another alternative is doing it asynchronously outside of the main request (a wp cron job or something), since it may not necessarily make sense to block the main request.

{ force: true },
{
force: true,
...( deleteTerms ? { delete_terms: true } : {} ),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be tricky. Maybe the user didn't mean to delete terms for all taxonomies that they're deleting? Are we clear enough that this is happening?

Comment on lines +160 to +161
? __( 'Also delete all terms in these taxonomies' )
: __( 'Also delete all terms in this taxonomy' )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a pretty destructive checkbox. Should we think about how to make this a bit more "dangerous" and find a way for the user to double-confirm that this is the intent?

@ntsekouras

Copy link
Copy Markdown
Contributor

Thanks for your work! I'm closing though since the experiment was removed here: #81340.

@ntsekouras ntsekouras closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants