The MU forums have moved to WordPress.org

Edit Roles and Capabilities (6 posts)

  1. anth0ny
    Member
    Posted 19 years ago #

    I would like to change the role of "Contributor" so they have the ability to upload images only (not the rights of an Author).

    I realize there is a plug-in for Wordpress ( http://redalt.com/Resources/Plugins/Role+Manager ) but unfortunately it is not working in WordpressMU.

    Has anybody successfully changed the default roles?

  2. drmike
    Member
    Posted 19 years ago #

    Yes, many times. There's already a number of threads on teh subject as well.

    Open up the wp-admin/upgrade-schema.php file for editing. Towards the bottom is where the different levels get determined and what access they can receive.

    Hope this helps,
    -drmike

  3. anth0ny
    Member
    Posted 19 years ago #

    Okay, I see this in the upgrade-scheme.php:

    // Add caps for Contributor role
    $role = get_role('contributor');
    $role->add_cap('edit_posts');
    $role->add_cap('read');
    $role->add_cap('level_1');
    $role->add_cap('level_0');
    $role->add_cap('upload_files');

    I've added the last line, "$role->add_cap('upload_files');" and that was easy enough (assuming that is all I needed to update).

    I tried logging into the WPMU main dashboard and then just manually typing in the address to the file (http://mydomain.com/wp-admin/upgrade-shema.php). The page did not return any errors but when I log in as a contributor to this particular blog I still do not see the option to upload a file.

    I'm guessing these options are already set somewhere in the DB for already created blogs but nothing jumped out to my untrained Wordpress eye while looking at the code.

    Any tips?

  4. anth0ny
    Member
    Posted 19 years ago #

    Actually, I was just able to figure it out. Here is what I did so if anybody stumbles on this thread they can figure out how.

    1. I updated the upgrade-schema.php file as I indicated above.

    2. I found in the wp_XX_options table (where XX is the ID of the existing blog) and the column wp_XX_user_roles insdie of this table which was setting the permission levels for the different roles.

    3. I created a new blog, which by default would reference by updated upgrade-schema.php file, and then went into the new blogs wp_XX_options table and copied the value from the wp_XX_user_roles.

    4. I pasted the value from the the new blog into the existing blog's table wp_XX_user_roles column and now the roles are working as I set in upgrade-schema.php.

    So now I updated the old blog to have the same permissions as any new blog that gets created on the site.

    If you have questions, let me know.

  5. drmike
    Member
    Posted 19 years ago #

    You did good. :)

    I should have mentioned the existing users would be an issue. Sorry about that.

    Regards,
    -drmike

  6. slounsbury
    Member
    Posted 19 years ago #

    If you want to add capabilities to any role site-wide, here is a script to help out. Drop the script in the wp-admin folder and make sure to login as admin, then just run the script from your browser.

    <?php
    require_once('admin.php');
    // Add roles you want to modify here.
    $roles = Array("contributor");
    // Capabilities to add to each role here.
    $caps = Array("upload_files");
    $blogs = get_blog_list(0, 'all');
    foreach($blogs as $blog)
    {
      switch_to_blog($blog['blog_id']);
      foreach ($roles as $role)
      {
        $r = get_role($role);
        foreach($caps as $cap)
        {
          $r->add_cap($cap);
        }
        print "Finished adding capabilities: " . implode(',', $caps) . " to role '$role' on blog {$blog['path']}<br/>";
      }
      restore_current_blog();
    }
    ?>

About this Topic

  • Started 19 years ago by anth0ny
  • Latest reply from slounsbury