latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Editor can create any new user except adminis

Home Forums Community Forum Editor can create any new user except adminis

This topic contains 1 reply, has 2 voices. Last updated by  Raam Dev 4 years, 2 months ago.

Topic Author Topic
Posted: Wednesday Oct 17th, 2012 at 5:39 am #28647

Hi

I don’t want the editor to able to add, edit or delete the admin. I found this code below on http://wordpress.stackexchange.com/questions/4479/editor-can-create-any-new-user-except-administrator except that it is for members plugin.

What could the adjustments be for s2member? Thanks in advance.

Code:
class JPB_User_Caps {

// Add our filters
function JPB_User_Caps(){
add_filter( ‘editable_roles’, array(&$this, ‘editable_roles’));
add_filter( ‘map_meta_cap’, array(&$this, ‘map_meta_cap’),10,4);
}

// Remove ‘Administrator’ from the list of roles if the current user is not an admin
function editable_roles( $roles ){
if( isset( $roles[‘administrator’] ) && !current_user_can(‘administrator’) ){
unset( $roles[‘administrator’]);
}
return $roles;
}

// If someone is trying to edit or delete and admin and that user isn’t an admin, don’t allow it
function map_meta_cap( $caps, $cap, $user_id, $args ){

switch( $cap ){
case ‘edit_user’:
case ‘remove_user’:
case ‘promote_user’:
if( isset($args[0]) && $args[0] == $user_id )
break;
elseif( !isset($args[0]) )
$caps[] = ‘do_not_allow’;
$other = new WP_User( absint($args[0]) );
if( $other->has_cap( ‘administrator’ ) ){
if(!current_user_can(‘administrator’)){
$caps[] = ‘do_not_allow’;
}
}
break;
case ‘delete_user’:
case ‘delete_users’:
if( !isset($args[0]) )
break;
$other = new WP_User( absint($args[0]) );
if( $other->has_cap( ‘administrator’ ) ){
if(!current_user_can(‘administrator’)){
$caps[] = ‘do_not_allow’;
}
}
break;
default:
break;
}
return $caps;
}

}

$jpb_user_caps = new JPB_User_Caps();

List Of Topic Replies

Viewing 1 replies (of 1 total)
Author Replies
Author Replies
Posted: Wednesday Oct 17th, 2012 at 4:49 pm #28748
Raam Dev
Username: Raam
Staff Member

Hello,

s2Member is not designed to work outside the Subscriber role capabilities, as all s2Member Levels are based on the WordPress Subscriber role. This means that s2Member users do not have access to edit/create/delete posts/pages or obtain any access to the WordPress Dashboard.

Any customizations outside the intended design of s2Member would be considered custom coding and unfortunately that is not covered by our Support Policy. I recommend posting your question in the Community Forum or hiring a programmer on jobs.wordpress.net to help you. If you have any specific questions about s2Member, please let us know and we’ll do our best to help.

Viewing 1 replies (of 1 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.