WordPress.org

Ready to get started?Download WordPress

Forums

Creating a role based on another (2 posts)

  1. molnarm
    Member
    Posted 3 years ago #

    Hi!

    I'd like to create a new role for my plugin based on 'editor' but I haven't found a function in the Codex which would allow 'cloning' a role. The goal is to have a new role with all capabilities an Editor has, plus some new ones for managing plugin data. I don't want to add new capabilities to all editors. Is there a way to get all capabilities granted to a role (so I could apply them via add_cap)?

  2. molnarm
    Member
    Posted 3 years ago #

    OK, I figured it out. My solution (in case someone would have the same question):

    $editor=get_role('editor');
     $newrole=add_role('newrole','New Role',$editor->capabilities);
     $newrole->add_cap('new_capability');

    These functions aren't very well documented in the Codex so I had to figure it out from the source.

Topic Closed

This topic has been closed to new replies.

About this Topic