Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Four roles to restrict user access on backend? WordPress

  • SOLVED

Hi guys, I'm trying to achieve this, shouldn't be hard, right?

1) A role w/capabilities to publish/edit a custom post type (i.e. products), select themes and edit theme options.
2) Another role w/ same capabilities as (1) but they can also publish/edit POSTS.
3) Another role w/ same capabilities as (1) but they can also publish/edit PAGES.
4) Another role w/ same capabilities as (1) but they can also publish/edit PAGES AND POSTS.

I need these restrictions to work as if a subscriber role would like to access http://...com/wp-admin/edit.php and WordPress would say: "You do not have sufficient permissions to access this page."

I'd like this to be set with Roles so they can later on apply for a different Role with more priviliges and I can see from the backend who has X privilige..

Thanks!

Joaquin

BTW: It's a WPMS install, so I want users to have any of these roles, a regular plugin won't do the job..

/* Edit: Jan 17th */

Thanks for your replies guys. On WPMS each blog have their own wp_user_capabilities so I'm having a hard time doing what you suggest..

Answers (3)

2011-01-15

Sébastien | French WordpressDesigner answers:

You can create your self roles ! That's a very good solution
[[LINK href="http://codex.wordpress.org/Function_Reference/add_role"]]http://codex.wordpress.org/Function_Reference/add_role[[/LINK]]


Sébastien | French WordpressDesigner comments:

Example :
if you add this code in your file functions.php
add_role('basic_contributor', 'Basic Contributor', array(
'read' => true, // True allows that capability
'edit_posts' => true,
'delete_posts' => false, // Use false to explicitly deny
));

a new role is created, his name is "basic_contributor"
with this role, i can read, delete post but no edit post.

You can custom your role as you want.
"red", "edit_posts" or "delete_posts" are capabilities and the list af all capabilities is here : http://codex.wordpress.org/Roles_and_Capabilities
Easy !


Sébastien | French WordpressDesigner comments:

<blockquote>Thanks for your replies guys. On WPMS each blog have their own wp_user_capabilities so I'm having a hard time doing what you suggest.. </blockquote>
why ?

You must just add the new role in a file (functions.php)
and after you must assign this role to a user...


chocks comments:

Yeap, I've done that:

$admin = get_role('administrator');
$caps = $admin->capabilities;

add_role('manejo_basico', 'Nivel Basico', $caps);
$role = get_role('manejo_basico');
$role->add_cap('manejo_basico');

add_role('manejo_paginas', 'Nivel Paginas', $caps);
$role2 = get_role('manejo_paginas');
$role2->add_cap('manejo_paginas');

add_role('manejo_paginas_posts', 'Nivel Paginas Posts', $caps);
$role3 = get_role('manejo_paginas_posts');
$role3->add_cap('manejo_posts');
$role3->add_cap('manejo_paginas');


But when I create a new user I can't assign any of those roles on the new subdomain.. and when I login into it I can then change the role of the user.

The other biggy is that new user with new role can't see the movies post type menu.. (gosh I don't know why!) which makes all this senseless.. I'm so close to finish the project: it's not for a client, it's for me, and it's driving me up the wall.

I don't mind (and this if for you as well Pippin) raising the amount of this question if you could help me out!.

Thanks

Joaquin.

If you want I can send you the details of the WP install.

2011-01-15

Pippin Williamson answers:

Use [[LINK href="http://wordpress.org/extend/plugins/role-scoper/"]]WordPress Role Scoper[[/LINK]]


Pippin Williamson comments:

A regular plugin should work fine if you couple it with [[LINK href="http://wordpress.org/extend/plugins/multisite-user-management/"]]WordPress Multisite User Management[[/LINK]], which syncs all your blog's users.


Pippin Williamson comments:

If you're only running a few sites (say less than 20) and not adding new sites all the time, you could set up each site manually with the role scoper plugin, then also use the other plugin I told you about.


chocks comments:

I thought so.. but hopefully the site will get more than that!

2011-01-15

Denzel Chia answers:

Hi,

Use this plugin http://justintadlock.com/archives/2009/09/17/members-wordpress-plugin
you can do the following with this plugin.

* Edit Roles: Edit your user roles and their capabilities.
* New Roles: Create new roles for use on your site.
* Content Permissions: Adds a meta box on your write post/page editor that allows you to restrict content to specific roles.
* Widgets: Adds a login form widget and user-listing widget that you can use in any widget area on your site.
* Shortcodes: Creates shortcodes that you can use to restrict or allow access to certain parts of your posts and pages (or any other shortcode-capable area).
* Template Tags: New functions for use within your WordPress theme for various things.
* Private Blog: Allows you to create a private blog that can only be accessed by users that are logged in (redirects them to the login page).

<blockquote>BTW: It's a WPMS install, so I want users to have any of these roles, a regular plugin won't do the job.. </blockquote>

If you are familiar with multi site installation, you should know that there is only one user table for all sites. User table does not duplicate for other sites. Look in your database table and you will see. Therefore, it the plugin work for single site, it will work for multi site installation.

Thanks.