Skip to content

Instantly share code, notes, and snippets.

@mjangda
Created January 16, 2013 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjangda/4545052 to your computer and use it in GitHub Desktop.
Save mjangda/4545052 to your computer and use it in GitHub Desktop.
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