Skip to content

Instantly share code, notes, and snippets.

@falahati
Forked from tobedoit/gist:4146942
Created June 18, 2018 22:52
Show Gist options
  • Save falahati/8974e0bf0ae40448f352bad24aa74635 to your computer and use it in GitHub Desktop.
Save falahati/8974e0bf0ae40448f352bad24aa74635 to your computer and use it in GitHub Desktop.
Wordpress: remove the "Dashboard" and redirect for non-admin user
/* 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