Skip to content

Instantly share code, notes, and snippets.

@sudar
Last active August 29, 2015 13:57
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 sudar/9749465 to your computer and use it in GitHub Desktop.
Save sudar/9749465 to your computer and use it in GitHub Desktop.
Code to prevent users from adding new terms to custom taxonomy in WordPress. More details at http://sudarmuthu.com/blog/prevent-users-from-adding-new-terms-to-custom-taxonomy-in-wordpress/
<?php
add_action( 'pre_insert_term', 'prevent_terms', 1, 2 );
function prevent_terms ( $term, $taxonomy ) {
if ( 'areas' === $taxonomy && !current_user_can( 'activate_plugins' ) ) {
return new WP_Error( 'term_addition_blocked', __( 'You cannot add terms to this taxonomy' ) );
}
return $term;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment