I wanted the logged in user to get one form from other application only if he/she is Administrator and here is how I checked it. You can check for any role (even new role made through custom user role).
<?
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php'); //to load from any folder
$current_user = wp_get_current_user();
$user_info = get_userdata($current_user->ID);
if (in_array("administrator", $user_info->roles)) {
//greet or any other function to call if you want
} else {
die("Login as Admin to continue");
}
// other code below if user passed your role requirement
// otherwise the content will not be shown to him/her.
?>
We have to use in_array for checking user roles because you can assign multiple roles to users.
I saved that code in “chkuser.php” and in the beginning of any other php page, I do <? include "chkuser.php"; ?>
and program will stop there if user was not an Administrator.