1

I need to create a custom role that is only able to edit and publish his own page (page created by admin and afterwards assigned to the user with the custom role).

I have successfully created the new role, and the user under that role is able to edit his own page and publish it, but it still has too much "power" inside the panel. The role has access to comments, post creation, page creation, tools, and to the plugin Timeline Express. I've compared to the contributor panel, and the last item (the plugin Timeline Express) is not shown on this role.

I spent some time reading through WordPress documentation and web forums in order to achieve what I'm trying to do, but I'm still no closer than I was. I know there are plugins that would give me this functionality but I need a simple thing, and I believe there's no need to, "Buy a Ferrari to cross the street".

I'm doing these changes on child theme's functions.php:

remove_role( 'Supervisor');

$result = add_role( 
    'Supervisor', 
    __( 'Supervisor' ), 
    array( 
        'read' => true, 
        'edit_pages' => true, 
        'publish_pages' => true, 
        'edit_published_pages' => true,
        'create_pages' => false,
    ) 
);

Could you please take a look and help me?

0

I've managed to solve this with a little bit of "patching" and thanks to the explanation on both these threads: Remove ability to access certain admin menus & Hide Admin menus per role in Wordpress

I added to the restrict_menus function the items which access I needed forbidden, and hid in the remove_menus the list items I was able to. I've also enqueue an admin stylesheet to be launched when this role was active and with that hide the plugin items that were showing.

this is my final code now:

//remove_role( 'Supervisor'); // developing purposes only

$result = add_role( 'Supervisor', 
__('Supervisor' ),
  array( 

 'read' => true,
 'create_posts' => false,
 'create_pages' => false,
 'moderate_comments' => false,
 'edit_pages' => true, 
 'publish_pages' => true,
 'edit_published_pages' => true,
) 
);

function restrict_menus(){

$author = wp_get_current_user();
 if(isset($author->roles[0])){ 
 $current_role = $author->roles[0];
}else{
$current_role = 'no_role';
}

if($current_role == 'Supervisor'){  

$screen = get_current_screen();
$base = $screen->id;


if($base == 'edit-post' || $base == 'tools' || $base == 'edit-comments' || 
$base == 'page' && $action == 'add' || $base == 'te_announcements' && $action == 'add')
{  
wp_die('Não tem permissões para aceder a esta área');
}
}

}

add_action( 'current_screen', 'restrict_menus' );

function remove_menus()
{
global $menu;

$author = wp_get_current_user();
if(isset($author->roles[0])){ 
$current_role = $author->roles[0];
}else{
$current_role = 'no_role';
}

if($current_role == 'Supervisor')
{
$restricted = array(__('Comments'),
                    __('Appearance'),
                    __('Plugins'),
                    __('Tools'),
                    __('Settings'),
                    __('Posts'),

);
end ($menu);
while (prev($menu)){
    $value = explode(' ',$menu[key($menu)][0]);
    if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}// end while

}// end if
}
add_action('admin_menu', 'remove_menus');

If anybody has a better way, please tell me so.

-1

Yes,i am not getting you very well this may helpful.

http://easywebdesigntutorials.com/creating-a-custom-user-role/

  • Answers whose only information is a link are not really welcome here. Please improve your answer with more details, so it works without the link. Links die and so your answer can become useless (now or later). – flomei Jan 29 '16 at 14:51
  • I've seen the explanation on that link before, and it isn't helpful for what i need. In the role array i've set post and page creation to false, and it isn't working, so i'm probably missing something that expert and fresh eyes will spot. But thank you for taking the time to see my question Vasim. – Janica Jan 29 '16 at 16:28
  • you just want to allow user can see can't edit it. – Vasim Shaikh Jan 29 '16 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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