plugins - Want to add post to user dashboard

admin2025-06-05  2

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

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

Share Improve this question edited Dec 28, 2018 at 15:17 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Dec 28, 2018 at 11:53 FernaFerna 31 silver badge4 bronze badges 1
  • 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 Commented Dec 28, 2018 at 17:34
Add a comment  | 

2 Answers 2

Reset to default 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

}

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749062142a316028.html

最新回复(0)