WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#21150 closed defect (bug) (invalid)

Add a way to prevent a term from being deleted

Reported by: wpsmith Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords:
Focuses: Cc:

Description

Currently, WordPress uses an option ('default_category') to prevent the deletion of the default WordPress category. However, someone creates a default term for a custom taxonomy, there is currently no easy method to prevent the deletion of the term.

I propose a simple filter that would enable this.

Attachments (1)

delete_term.patch (544 bytes) - added by wpsmith 9 years ago.

Download all attachments as: .zip

Change History (10)

@wpsmith
9 years ago

#1 @wpsmith
9 years ago

Just saw this in WP_Terms_List_Table:

$default_term = get_option( 'default_' . $taxonomy );

#2 @wpsmith
9 years ago

  • Keywords has-patch 2nd-opinion dev-feedback removed
  • Resolution set to wontfix
  • Status changed from new to closed

#3 @helenyhou
9 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

#4 @helenyhou
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

#5 @maxaud
8 years ago

I currently don't see a way to stop a term from being deleted in wp_delete_term function.
I can recreate it after it's already been deleted using the do_action at the end but this is after all the associations have been removed.

I have a custom taxonomy that I need to prevent some terms from being removed.

#6 @markoheijnen
8 years ago

This ticket is about having a default term for a taxonomy. You can set the option 'default' . $taxonomy to the id of the default term. You can also use a filter if desired or needed. But this only works for the list table row actions and not when using wp_delete_term() directly. What happens when you do bulk delete.

In your case you can use tag_row_actions or {$taxonomy}_row_actions with the same flaws. I don't think the filter 'has_cap' will do any good. Not sure if there is a ticket for meta_cap support for taxonomies.

#7 @maxaud
8 years ago

I don't think this ticket is about having a default term set for taxonomies.
The reason it was brought up as a solution is because the current code only checks if it's the default term and doesn't delete if it is. It's an incorrect approach to fix the real problem.

Essentially there should be a way to easily block the removal of any term just by using a filter before anything happens.

#8 @markoheijnen
8 years ago

The title of this ticket says something different then the description. This ticket is about having a default term for a custom taxonomy. Otherwise I don't think that the reporter would close it himself.

You want capabilities like delete_term and then you would need something like meta_caps. You can create a ticket for that.

#9 @maxaud
8 years ago

What I would like is the ability to stop a couple terms from being deleted (preferably from a certain taxonomy by ID). The title and ticket description say just this. The comments following focused on only current way that it's being stopped and only works for one term rather than multiple.

The recommended approach in the above comments is to remove the delete button on the front end where the function itself needs the ability to prevent terms from being deleted through plugins and other ways that circumvent the UI.

Additionally, a capability would lead me to believe that you want to block the ability to delete all terms for a specific roles. This is not what I see this ticket being.

Last edited 8 years ago by maxaud (previous) (diff)
Note: See TracTickets for help on using tickets.