Try using these codes:
function themename_check_user_role( $role, $user_id = null ) {
if ( is_numeric( $user_id ) )
$user = get_userdata( $user_id );
else
$user = wp_get_current_user();
if ( empty( $user ) )
return false;
return in_array( $role, (array) $user->roles );
}
// example use for the current user
if ( themename_check_user_role( 'customer' )
_e( "You've got access!", 'themename' );
else
_e( "Sorry, you don't have access!", 'themename' );
Here, you are checking whether a particular user has a role or not. If a match is found, true will be returned.
Related Posts:
- How can I hide a category from Contributors in the edit/add new post screen?
- Assigning a category to a user role
- How can I prevent users from creating new categories?
- Allow contributors to add categories, but not delete
- WordPress/Woocommerce only show category in shop to a single role
- Admin comments and user restrictions
- Display posts of certain categories to specific user roles
- How to restrict category creation to admins only while allowing editors to still pick category
- Allow Custom Role to edit a custom post type category
- Display the articles of a category by role
- how to Specifies an author / editor to edit one category only?
- Assign a category by user and customize the edit-tags.php?taxonomy=category page
- Hide categories from authors
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- Different template for subcategories
- How to get this only in small letters (lowercase)? [closed]
- How to totally get rid of Category in my blog?
- Is there a function to cause empty categories not to show in menus?
- Disable pagination only for specific category
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Category Specific Archive
- How to add categories to products in woocommerce programatically? [closed]
- Is there a plugin that will completely remove the category system?
- How to get the number of child categories a specific parent category has?
- Removing category base form links messes up the parent-child behavior
- How to get only the last child of category slug?
- Multisite – create a category in specific site
- How to list only child categories?
- How do you remove display of WooCommerce product category on single product page?
- Show recent posts in menu?
- Cannot add / edit categories to a post anymore
- Convert the default sub-category dashes to bullets or any other characters
- How to check category of of custom post type or not
- Set a them for all subset of category
- How to query post like normal search would do. within search.php page
- Modify WordPress SQL Query to pull from within a category
- How can i insert term in a specific language of Polylang?
- How to retrieve more posts from a custom post type that are in the same category as the current post
- WordPress Get Posts from each category equally
- Unwanted Duplicate Product Categories in WooCommerce
- Same base for category and post
- Custom taxonomy/category order
- Add tag parameter to category.php
- Why custom taxomony not showing when create a post?
- Single.php Category Post Count
- wp_list_categories with show_count, except for specific categories
- Show the amount of posts in a tag in a specific category has
- Adding a H1 Tag to Post Tags automatically, but hide the tag? (Same for Category)
- How do I add a category to my post_type
- WordPress showing wrong category name
- Add posts of a certain category to a page
- Show 10 Sub Categories Per Parent Category Page?
- Conditional category & tag statement
- How can I filter posts by tag on the fly
- Post Loop Category first show parent then child
- How to display posts from specific category using get_option function?
- wp_nav_menu not appearing correctly on category page
- Post not found when filtered by category ID
- How to detect /category and /tag base pages?
- How to Show or Hidden Categories on page in WordPress?
- Display all posts from selected category
- Is there any better/faster code than this ? It shows the categories that an author had ever posted in
- category description not showing in my woocommerce
- How to get immediate children of a ‘term’ parent id through ‘get_terms’?
- Hide Some Categories in Post Editor
- in post content shortcode works, but hardcoded in same page template doesn’t?
- Only 10 of 233 categories selectable when adding a new post
- When creating category, it creates automatically tag, or, when creating tag, it creates automatically category in same name
- Multiple if statements with else for get_the_category [closed]
- Balance Tags to the_content Words Length
- How to create template for children category?
- Using a template page parent breaks page
- Categories and Tags Conflict after Woocommerce Installation
- Setting category for post as default
- the_content() not showing full posts in category template
- Query post only from categories that have subcategories
- How to get the link of all categories
- Show parent category if there is no subcategory
- Add category links?
- foreach,having wp_query inside, breaks after showing one result
- Display a category name automatically using code in the functions.php file
- Removing categories, Comments etc from posts?
- Add html word before category
- Include Category Description in search result
- Problem importing categories and sub-categories
- how to ask if in two categorys inside if
- All post of child category not in top category
- How to add a tag above a category post that displays the category name in WordPress
- Woocommerce – Display product category of product in Orders page
- How to show video from wp option value?
- Changing Woocommerce categories programatically
- Add an Exclusive or featured tag line to article titles
- How to list out post category name and description in page
- Print child category slug nicename
- How to link ACF relationship field to the new Query block in Full Site Editing
- Order Categories by Character Count
- Function to reference post meta in place of category Woocommerce
- hide_empty property not working when using get_terms
- Category Redirection Problem
- Hierarchical outline of posts