Remove delete button on some categories

Remove delete button on some categoriesThere is another interesting snippet function add-on for your WordPress sites. Currently there is no way to disable or remove/delete button on WordPress Categories or other lists, so for example, your “MAD” or “DRUNK” Editor can suddenly remove categories.

That’s why I come to idea that this snippet should be interesting and thanks to S_HA_DUM, moderator of Stackexchange, there was already available snippet for this.

For those fields WordPress uses WP_List_Table class and some other extension, in this case WP_Terms_List_Table class and that class contains a filter called {$taxonomy}_row_actions.

$actions = apply_filters( “{$taxonomy}_row_actions”, $actions, $tag );

Remove “delete” button on some categories

[php]
/**
* Snippet Name: Remove delete button on some categories
* Snippet URL: http://wperror.com/remove-delete-button-on-some-categories.html
*/

add_filter(
‘bulk_category_remove’,
function($actions, $tag) {
$no_del = array(7,13);
if (in_array($tag->term_id,$no_del)) {
unset($actions[‘delete’]);
}
return $actions;
},
10,2
);
[/php]

Even with this tutorial I believe your WordPress categories are not 100% secured as there is bulk edit >> delete option still available and categories selected trough ID’s from earlier snippet are not protected.

This is why I’m thinking to write another snippet for bulk remove control!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>