Posted By

zreedeecom on 03/10/11


Tagged

wordpress role permisions


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

devilspride


Add/remove permissions/capabilities for a specific role in wordpress


 / Published in: PHP
 

URL: http://zreedee.com

  1. /**
  2.  * Paste the code into your functions.php
  3.  * For more info about the options available visit: http://codex.wordpress.org/Roles_and_Capabilities
  4.  */
  5.  
  6.  
  7. /**
  8.  * Add new permissions/capabilities to a specific role
  9.  *
  10.  * @param string $role
  11.  * @param string $cap
  12.  */
  13. function add_capability($role,$cap) {
  14. $role_obj = get_role($role); // get the the role object
  15. $role_obj->add_cap($cap); // add $cap capability to this role object
  16. }
  17. //add_capability('subscriber','read_private_pages'); //Example
  18.  
  19. /**
  20.  * Remove existing permissions/capabilities to a specific role
  21.  *
  22.  * @param string $role
  23.  * @param string $cap
  24.  */
  25. function remove_capability($role,$cap) {
  26. $role_obj = get_role($role); // get the the role object
  27. $role_obj->remove_cap($cap); // add $cap capability to this role object
  28. }
  29. //remove_capability('subscriber','read_private_pages'); //Example

Report this snippet  

You need to login to post a comment.