Some WordPress Tricks

Redirect some or users to a particular URL after logging in

function login_redirect( $redirect_to, $request, $user ) 
{ 
   return ( is_array( $user->roles ) && in_array( 'sln_staff', $user->roles ) ) ? "https://mydevfactory.com/~appfactory/salonBooking/wp-admin/admin.php?page=salon" : admin_url(); /* here sln_staff is the admin group for which a redirect will happen after logging in */
}

add_filter( 'login_redirect', 'login_redirect', 10, 3 );

 

Remove the Black Admin bar that appears on top of site when the user is logged in

function remove_admin_bar() 
{ 
   show_admin_bar(false);
}
add_action('after_setup_theme', 'remove_admin_bar');

Remove the WordPress update notice on top of the Dashboard

function hide_update_notice_to_all_but_admin_users() 
{ 
   if (!current_user_can('update_core')) { 
     remove_action( 'admin_notices', 'update_nag', 3 ); 
   } 
   $user = wp_get_current_user(); 
   /*echo ($user['roles'][0]); 
   if(in_array( 'sln_staff', $user->roles )) 
     echo "SLN_STAFF"; 
   else 
     echo "WHOEVER";*/
}

add_action( 'admin_head', 'hide_update_notice_to_all_but_admin_users', 1 );

 

Remove the Dashboard items using the Screen Options and then remove the Screen Options and Help tab

function remove_help_tabs($old_help, $screen_id, $screen)
{ 
   $screen->remove_help_tabs(); 
   return $old_help;
}

add_filter( 'contextual_help', 'remove_help_tabs', 999, 3 );
add_filter('screen_options_show_screen', '__return_false');

 

Leave a Reply