Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As far I know, the widgets in the dashboard can be removed, but I want to ask if its possible to remove the access to dashboard completely and allow access to only post-new.php page? Thanks.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Removing the dashboard:

/* Remove the "Dashboard" from the admin menu for non-admin users */
function wpse54085_remove_dashboard () {
    global $current_user, $menu, $submenu;
    get_currentuserinfo();

    if( ! in_array( 'administrator', $current_user->roles ) ) {
        reset( $menu );
        $page = key( $menu );
        while( ( __( 'Dashboard' ) != $menu[$page][0] ) && next( $menu ) ) {
            $page = key( $menu );
        }
        if( __( 'Dashboard' ) == $menu[$page][0] ) {
            unset( $menu[$page] );
        }
        reset($menu);
        $page = key($menu);
        while ( ! $current_user->has_cap( $menu[$page][1] ) && next( $menu ) ) {
            $page = key( $menu );
        }
        if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI'] ) && ( 'index.php' != $menu[$page][2] ) ) {
            wp_redirect( get_option( 'siteurl' ) . '/wp-admin/post-new.php');
        }
    }
}
add_action( 'admin_menu', 'wpse54085_remove_dashboard' );

Removing further parts of the admin menu:

Here you can use the remove_menu_page() function.

function wpse54085_admin_menu_fixes() {
    global $current_user;

    if( ! in_array( 'administrator', $current_user->roles ) ) {
        remove_menu_page('link-manager.php');
        /* add more menu pages, depending on what you want to remove */
    }
}
add_action( 'admin_menu', 'wpse54085_admin_menu_fixes' );

Obviously either function can be extended to differentiate between further user roles. Both should be added to your theme's functions.php file.

share|improve this answer
    
Thanks for noticing, @brasofilo –  Johannes Pille Jun 3 '12 at 19:57
    
u're welcome, Johannes :) –  brasofilo Jun 3 '12 at 20:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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