Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. function disallow_insert_term($term, $taxonomy) {
  2.  
  3.     $user = wp_get_current_user();
  4.  
  5.     error_log("{$term, $taxonomy}"); //inspect term and taxonomy
  6.     error_log(implode(', ', $user->roles); //inspect the user roles
  7.  
  8.     if ( $taxonomy === 'post_tag' && in_array('somerole', $user->roles) ) {
  9.  
  10.         error_log('yes, disallow this term...'); //do we get into the conditional
  11.  
  12.         return new WP_Error(
  13.             'disallow_insert_term',
  14.             __('Your role does not have permission to add terms to this taxonomy')
  15.         );
  16.  
  17.     }
  18.  
  19. }
  20.  
  21. add_action( 'pre_insert_term', 'disallow_insert_term', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement