Custom Post Type with Role Users


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. add_role('monitor', 'Monitor', array(
  2. 'edit_monitoramento' => true,
  3. 'edit_monitoramentos' => true,
  4. 'edit_private_monitoramento' => true,
  5. 'edit_other_monitoramento' => true,
  6. 'read_monitoramento' => true,
  7. 'read_private_monitoramentos' => true,
  8. 'publish_monitoramentos' => true,
  9. 'delete_monitoramento' => true,
  10. 'delete_monitoramentos' => true,
  11. 'delete_others_monitoramentos' => true,
  12. 'delete_published_monitoramentos' => true,
  13. 'delete_private_monitoramentos' => true,
  14. 'edit_posts' => false
  15. ));
  16.  
  17. $admin_role = get_role( 'administrator' );
  18. $admin_role->add_cap( 'edit_monitoramentos' );
  19. $admin_role->add_cap( 'edit_monitoramento' );
  20. $admin_role->add_cap( 'edit_private_monitoramento' );
  21. $admin_role->add_cap( 'publish_monitoramentos' );
  22. $admin_role->add_cap( 'manage_tipo' );
  23. $admin_role->add_cap( 'edit_tipo' );
  24. $admin_role->add_cap( 'delete_tipo' );
  25. $admin_role->add_cap( 'assign_tipo' );
  26.  
  27.  
  28. $monitor_role = get_role( 'monitor' );
  29. $monitor_role->add_cap( 'edit_monitoramentos' );
  30. $monitor_role->add_cap( 'edit_monitoramento' );
  31. $monitor_role->add_cap( 'edit_private_monitoramento');
  32. $monitor_role->add_cap( 'publish_monitoramentos');
  33. $monitor_role->add_cap( 'manage_tipo' );
  34. $monitor_role->add_cap( 'edit_tipo' );
  35. $monitor_role->add_cap( 'delete_tipo' );
  36. $monitor_role->add_cap( 'assign_tipo' );
  37. $monitor_role->remove_cap( 'manage_categories');
  38. $monitor_role->remove_cap( 'edit_posts');
  39.  
  40.  
  41. add_action('init', 'monitoramento_register');
  42.  
  43. function monitoramento_register() {
  44. $labels = array(
  45. 'name' => _x('Monitoramento', 'post type general name'),
  46. 'singular_name' => _x('Monitoramento', 'post type singular name'),
  47. 'add_new' => _x('Adicionar', 'monitoramento item'),
  48. 'add_new_item' => __('Adicionar novo'),
  49. 'edit_item' => __('Editar'),
  50. 'new_item' => __('Novo'),
  51. 'view_item' => __('Visualizar'),
  52. 'search_items' => __('Busca'),
  53. 'not_found' => __('Nada encontrado'),
  54. 'not_found_in_trash' => __('Nada encontrado na Lixeira'),
  55. 'parent_item_colon' => ''
  56. );
  57. $args = array(
  58. 'labels' => $labels,
  59. 'public' => true,
  60. 'publicly_queryable' => true,
  61. 'show_ui' => true,
  62. 'query_var' => true,
  63. 'has_archive' => true,
  64.  
  65. 'rewrite' => array('slug' => 'monitoramento'),
  66. // 'capability_type' => 'post',
  67. 'capabilities' => array(
  68. 'edit_post' => 'edit_monitoramento',
  69. 'edit_posts' => 'edit_monitoramentos',
  70. 'edit_private_posts' => 'edit_private_monitoramento',
  71. 'edit_others_posts' => 'edit_other_monitoramento',
  72. 'read_post' => 'read_monitoramento',
  73. 'read_private_posts' => 'read_private_monitoramentos',
  74. 'publish_posts' => 'publish_monitoramentos',
  75. 'delete_post' => 'delete_monitoramento',
  76. 'delete_posts' => 'delete_monitoramentos',
  77. 'delete_others_posts' => 'delete_others_monitoramentos',
  78. 'delete_published_posts' => 'delete_published_monitoramentos',
  79. 'delete_private_posts' => 'delete_private_monitoramentos'
  80. ),
  81. 'hierarchical' => false,
  82. 'menu_position' => 5,
  83.  
  84. 'supports' => array('title', 'editor', 'excerpt', 'thumbnail')
  85. );
  86.  
  87. register_post_type('monitoramento' , $args);
  88.  
  89. };
  90.  
  91. register_taxonomy("tipo", array("monitoramento"),
  92. "hierarchical" => true,
  93. "label" => "Tipo",
  94. "singular_label" =>
  95. "Formato", "rewrite" => true,
  96. "all_items" => __('Todos'),
  97. "add_new_item" => __('Adicionar um novo'),
  98. 'capabilities' => array(
  99. 'manage_terms'=>'manage_tipo',
  100. 'edit_terms'=>'edit_tipo',
  101. 'delete_terms'=>'delete_tipo',
  102. 'assign_terms'=>'assign_tipo')
  103. )
  104. );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.