Wordpress is very good in providing different types functions to check where a property of anything exits or not. From the data provided by functions, we use some sort of PHP code to get things done. I found many types bit complicated to check roles of the user. So I found a solution, to accomplish get current user details and then from that array we can check whether the role of that user exits or not.
We first use WordPress function wp-_get_current_user(); to get the users details and the use the roles object to find out the weather is roles exits or not. So by default, administrator, author, contributor, subscribers and editor roles exits. we can use any of the roles to check whether the role exits or not
$user = wp_get_current_user(); if ( in_array( 'author', (array) $user->roles ) ) { // do your work }