0

I would like to add edit.php to user dashboard who registers as subscriber on a website. Code which i using is

add_action( 'admin_menu', 'remove_menus' );
function remove_menus(){
if(!current_user_can('subscriber'))
    add_menu_page( 'edit.php' ); //dashboard
}

even has administrator instead subscriber didn't work

  • Welcome to WPSE, could you clarify what you actually want to add to the subscriber role. Do you want the user to see all postings because edit.php allows to enter the listing which holds all the posts. And what do you mean with user dashboard because Dashboard is a Tab on the Administration panel in the back-end. – Charles Dec 28 '18 at 17:34
0

Please update the code as below

add_action( 'admin_menu', 'remove_menus' );
function remove_menus(){
   $user = wp_get_current_user();
    $role = ( array ) $user->roles;
        if($role[0]==subscriber)
    add_menu_page( 'edit.php' ); //dashboard

}

  • no it doesnt show up – Ferna Dec 28 '18 at 12:01
  • updated code please check it once – Pratik bhatt Dec 28 '18 at 12:09
  • sorry didnt work – Ferna Dec 28 '18 at 12:31
  • 1
    @Pratikbhatt, you realize that even for displaying the post listing there must be another cap added to that role. And til this moment(6 hours after the question) it is not clear from the question if the OP also wants to give/allow the option to edit/create a post. I assume not because(imho) then he/she would simply add the user to contributor role and maybe add restriction and so on. – Charles Dec 28 '18 at 17:59
  • yes changed role to author and now it working thanks. need to put all links in array adding end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} – Ferna Dec 29 '18 at 6:03
-1

function add_custom_caps() { global $wp_roles; if ( ! isset( $wp_roles ) ) { $wp_roles = new WP_Roles(); } $role = get_role( 'subscriber' ); foreach ($wp_roles->get_role('editor')->capabilities as $key => $value){ $role->add_cap( $key ); } } add_action( 'admin_init', 'add_custom_caps');

It will clone all capability of Editor role and add them to Subscriber role

  • You are kidding or? Why would you add ALL caps of an editor, the OP just want the subscriber to have an option to see a list with all the Postings in the back-end. (Because edit.php holds the listing with posts in the back-end) Please read here what you want the OP to add and understand that your way will have huge impact with possible negative impact. – Charles Dec 28 '18 at 17:29

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.