3

Today I accidently happend to delete my category right after I've noticed there is no trash in categories. I wonder is there any way to include trash bin for it? I've made a little research over a wordpress documentation but didn't find anything like that. Does anyone know anything about that ? Is this possible?

1
  • I am working on this to make a plugin for this. I will update you here when done. – Aftab Jul 22 '16 at 15:12
2

This would be quite challenging to implement.

Posts can be trashed because:

  1. They have a concept of status and corresponding field in database table
  2. WordPress code "knows" to only deal with posts of appropriate status for most purposes

This solves issues of visibility (posts won't appear on front end) and interaction (trashed posts won't show up as belonging to a category and so on).

Taxonomies in general, including native categories, have no concept of status. They are always "on" until they are deleted.

Introducing concept of status to them would be extremely challenging to do cleanly. Just enumerating all the places where it would matter in core code would be a challenge. Overriding native behavior in all of those places might be straight impossible.

I could think of only one approach that could be reasonably practical: create a "virtual" taxonomy and whenever term is deleted "migrate" it to it, preserving all object assignments. Then undelete is possible by "migrating" it back to original taxonomy. Even these would probably be a lot of work to implement robustly.

2
  • Hi @Rarst, I am working on this to make a plugin for this. Hope I will be successfull. – Aftab Jul 22 '16 at 19:08
  • This is basically what I suggest doing using the hook I mentioned in my answer. – Fencer04 Jul 25 '16 at 11:58
1

It will take a bit of programming on your side but you can use the delete_term_taxonomy hook to create a trash for the categories. It is run just before the category is deleted.

2
  • So basically, I can use this hook for example to display alert box after clicking delete if I'm sure about deleting the category ? – Mateusz Winnicki Jul 25 '16 at 11:46
  • Or you could create a trash bin by saving the category details and the IDs of the posts in the category into another post type before the delete occurs. Then display a trash just like the regular posts. – Fencer04 Jul 25 '16 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.