0

I have created a custom user role but something strange happens.

This is the role:

add_role('custom-role', 'Custom Role', array(
'activate_plugins' => false,
'delete_others_pages' => true,
'delete_others_posts' => false,
'delete_pages' => true,
'delete_posts' => false,
'delete_private_pages' => true,
'delete_private_posts' => false,
'delete_published_pages' => true,
'delete_published_posts' => false,
'edit_dashboard' => false,
'edit_others_pages' => false,
'edit_others_posts' => false,
'edit_pages' => true,
'edit_posts' => false,
'edit_private_pages' => true,
'edit_private_posts' => false,
'edit_published_pages' => true,
'edit_published_posts' => false,
'edit_theme_options' => false,
'export' => false,
'import' => false,
'list_users' => true,
'manage_categories' => false,
'manage_links' => false,
'manage_options' => false,
'moderate_comments' => false,
'promote_users' => false,
'publish_pages' => true,
'publish_posts' => false,
'read_private_pages' => false,
'read_private_posts' => false,
'read' => false,
'remove_users' => true,
'switch_themes' => false,
'upload_files' => true,
'update_core' => false,
'update_plugins' => false,
'update_themes' => false,
'install_plugins' => false,
'install_themes' => false,
'delete_themes' => false,
'delete_plugins' => false,
'edit_plugins' => false,
'edit_theme' => false,
'edit_files' => false,
'edit_users' => true,
'create_users' => true,
'delete_users' => true,
'unfiltered_html' => false
));

This is nothing fancy. But the problem is that at first I set all the values to false. If I log a user in with the chosen role it shows Dashboard, posts, reactions, profile and extra.

The problem is that if I change a value from false to true nothing changes.
I have loged out and in, removed my cookies and deleted my cache.

I don't know how to fix this.

8
  • When and how are you using that code? Which capabilities are not working when you change them from false to true?
    – cybmeta
    Commented Sep 4, 2015 at 13:12
  • I use this in my functions.php and it doesn't matter what I change the only thing the users sees is: Dashboard, posts, reactions, profile and extra. Commented Sep 4, 2015 at 13:15
  • 2
    in WP doocumentation: NB: This setting is saved to the database (in table wp_options, field wp_user_roles), so it might be better to run this on theme/plugin activation It means that when you first run your code it is saved to db, and if you try to do it one more time it will not be changed becouse it is already in DB.. you should remove role before making changes..
    – Maikal
    Commented Sep 4, 2015 at 13:16
  • Sorry but when I asked "when and how you use that code" I wanted to know if you use it on some action hook, if so, which one. Please, show us. It doesn't matter if you use it in functions.php or in a plugin (by the way, a plugin is really better place to manage user roles).
    – cybmeta
    Commented Sep 4, 2015 at 13:18
  • @Maikal. That was indeed the problem. Thnx Commented Sep 4, 2015 at 13:24

1 Answer 1

0

in WP documentation:

NB: This setting is saved to the database (in table wp_options, field wp_user_roles), so it might be better to run this on theme/plugin activation

It means that when you first run your code it is saved to db, and if you try to do it one more time it will not be changed becouse it is already in DB.. you should remove role before making changes..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.