I think the function you are looking for is bp_displayed_user_id()
. That will get the ID of the user whose profile is currently being displayed.
Then, you can check their role like this:
$user = get_userdata( bp_displayed_user_id() );
if ( ! in_array( 'subscriber', (array) $user->roles ) ) {
return;
}
You could also use user_can()
, but it is best to avoid using role names with user_can()
and current_user_can()
, as they are really designed for capabilities and not roles. In fact, you ideally would not check user roles in a case like this at all. It would be better to add a custom capability to certain roles, like 'extended_bp_profile'
, and then check for that instead.
Related Posts:
- How can I add an image field to BuddyPress Extended Profile Fields? [closed]
- Get a list of all available fields in the User Profile
- How to add first name & last name to default registration form?
- How to display random users with avatars
- How to update BuddyPress xprofile fields programmatically? [closed]
- How to add custom fields to my custom registration form
- How to hide unused profile fields?
- How to limit character length in BuddyPress function output [closed]
- How to force field validation first, then its values saved durning edit profile?
- How to set the default avatar of buddypress avatar [closed]
- Dequeue script to prevent javascript event conflict on wordpress child theme
- Add Link to Users List (Backend) to open each users front-end profile
- Showing user profile data on front-end
- How do I pull avatar from post using BuddyPress? [closed]
- Changing author links on homepage to buddypress profiles – without affecting ability to link to author archive throughout the site
- Unhook the comment form in Buddypress
- How can i hide content if not friend in Buddypress? [closed]
- Sessions in word press [duplicate]
- What’s the difference between WordPress random_int() and PHP built-in function random_int()?
- Is it ok to use a function to output the text domain name in a wordpress theme
- Issue with wp_get_attachment_image() and SVG file type
- deregister scripts on certain page
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- Using get_terms for custom taxonomy in functions.php
- How to remove the embed_footer?
- Hide some items from Screen options in dashboard for products
- Editing or filtering the output of the Genesis navigation
- Using the child theme functions.php to change the customizer.php on parent theme
- Can’t Update function.php after writing short code
- How to get last updated row or ID in wordpress
- 2 Loops, Only Displaying 1 Loop in Both Loops
- edit role display name and label name without plugins
- is_plugin_active() not properly returning true
- Display gallery on top before content
- List of Body Classes Generated by body_class()
- wp_dropdown_categories and custom attribute
- Converting html to wordpress images not showing
- Redirect specific page in WordPress for first time visit
- How can I add text to all posts/pages/categories/homepage etc
- Pulling Twitter RSS feed not working as expected (fatal error)
- Related post using post title
- Move Post to different category if post_meta field is 0 or is 2 days old?
- Find a Javascript ID when trying to deregister?
- Functions For Calling Specific Elements
- Excerpts are not displayed by a shortcode on category pages
- Getting comment count per post not working
- Functions.php Problem
- It does not work concatenation in function.php
- Is There Any Built In WP Functionality For Combining Form Fields To Return Specific Data
- How would I go about replacing this function in my child theme located in inc/template-tags.php
- Condition OR for current user ID
- Retrieve a value from Yoast SEO to use to set a default twitter card image honoring overrides
- wp_create_category deprecated?
- If user is logged-in display/hide something
- Visual Composer creating own shortcodes with vc_map() to return simple Image
- Adding javascript to functions.php causes problems with my template
- Where do I store custom functions that call custom page template files?
- Excerpt for pages not showing
- Sortable column (by numbers) in admin users
- How can I add a class to a nav li depending on URL?
- Access category within rss2_head hook?
- How to Extend login session times to a Month
- Modifying the_posts_pagination from within functions.php instead of template files
- Woocommerce image sizes missing from Appearance › Customize but not declared by theme
- Prevent WordPress Automatic Logout
- display a div on ervery site but not frontpage?
- How can I change the size of the text in Word Press
- Using depth=n in wp_list_pages
- shorthand syntax for custom fields
- Replace header image on all other pages but home – URL issue
- Child theme functions.php
- Get users with different roles and call function on each of them (user_meta)
- Getting images from media library and get_the_date() not working
- WordPress show bad the php hour and date
- Show errormessages on wrong username/password on custom loginform?
- Using add_image_size in functions.php to get original uploaded file
- User profile Pick a premade Design/theme
- show all the posts thumbnails
- How do I change where “You must be logged in to comment” directs users?
- Login cookies blocked after customizing hashing method
- Class parameter in get_avatar args doesn’t get added to output
- Enable CORS Request for hostname using IP address
- locking content with overlay/pop up ads
- How to use `foreach()` in ajax call
- Change default color scheme in twentyfifteen child theme?
- Restrict access if logged out except for homepage
- Add meta data in head from theme
- DISABLE wordpress upgrade page
- How to list out all values from the get_body_class array
- Moving CDN jQuery to footer does not work?
- Function not recognizing page id?
- Register a widget area when a theme option has been saved?
- Blank child theme – functions.php problem
- Conditionally write open graph meta property in header
- Pull random comment from specific post, display on homepage with shortcode
- Adding custom HTML to each profile group tab [closed]
- Give a function a unique ID
- Hiding Google Analytics code based on theme options
- How do I make my child theme’s CSS update when I save it?
- WPDB query suddenly not working