Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allow limiting deletion of terms.
<?php
add_action( 'registered_taxonomy', 'cms_modify_default_delete_term_caps', 10, 3 );
function cms_modify_default_delete_term_caps( $taxonomy, $object_type, $args ) {
global $wp_taxonomies;
if ( 'category' == $taxonomy ) {
$wp_taxonomies[ $taxonomy ]->cap->delete_terms = 'cms-delete-terms';
}
}
add_filter('map_meta_cap', 'cms_map_meta_cap', 10, 4 );
function cms_map_meta_cap( $caps, $cap, $user_id, $args ) {
switch ($cap) {
case 'cbs-delete-terms':
$caps[] = 'do_not_allow';
break;
}
return $caps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.