Created
November 26, 2012 06:59
-
-
Save tobedoit/4146942 to your computer and use it in GitHub Desktop.
Wordpress: remove the "Dashboard" and redirect for non-admin user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Remove the "Dashboard" from the admin menu for non-admin users ********************************** | |
** http://wordpress.stackexchange.com/questions/52752/hide-dashboard-from-non-admin-users ******* */ | |
/* !관리자 아닌 회원 알림판 제거 & 리다이렉트 *********************************************************** */ | |
function custom_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] ) ) { | |
if (!current_user_can('subscriber')) { | |
wp_redirect( get_option( 'siteurl' ) . '/wp-admin/edit.php'); | |
} else { | |
wp_redirect( get_option( 'siteurl' ) . '/wp-admin/profile.php'); | |
} | |
} | |
} | |
} | |
add_action('admin_menu', 'custom_remove_dashboard'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment