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]
- BuddyPress Edit activity function good practice
- Send An Email to Admin on User Profile Completion
- How to replace words in my posts and saved new words
- Language Switch Function
- Add array of category IDs to global variable?
- Why might wptexturize have become re-enabled?
- How to debug function file causing white screen
- Javascript and Stylesheet in child page
- What to do to have access to WordPress functions
- how to create php file and load it in wordpress post?
- How to prevent multiple custom terms from being created
- Post date on Custom field
- Fatal error: Call to undefined function add_action() – an untouched problem
- revision id is one number behind – publish_post
- How to add number to wordpress count function?
- How do I integrate my Child Theme into a Custom Template?
- Using wp_localize_script in template file – is it secure?
- Limit Number of Posts on Blog Category Page Throwing 404 Error on Paginated Pages
- Sending Messages Back to the Template After Processing?
- How can I return the result of my custom function?
- Shortcode to eliminate and replace with
- No compression occurs on my jpegs after adding jpeg_quality hook to my functions.php file
- Automatic add space if user enters number(any digit)
- Changing the register url is not working
- WordPress Jquery+scripts enqueue issue
- Newest comments first not working
- Pass arguments to function class with do_action()
- Trying to Add a LEFT Sidebar?
- How to a override parent theme page that has been included with require_once?
- previous_post_link inside of a function?
- Display most popular posts
- Remove Featured Images from Posts Older Than a Certain Date
- To make some div display for a longer time
- Search and Replace Script Loader in Head Only Works in Footer
- How to display content If function exist/condition true?
- Regex works in regexr, but not if I filter content [closed]
- Getting back a blank WordPress site following functions code edit
- Different body image backgrounds on different pages, posts and categories
- Insert menu into theme location depending on user logged in/out status
- How to list out all values from the get_body_class array
- Moving CDN jQuery to footer does not work?
- How to run a function when publish posts? [duplicate]
- get_comments not working properly after WordPress v4.4 update
- custom COOKIE on custom page
- Retrieve a custom form field modified by a filter
- Call custom field using php
- Custom taxonomy not refreshing page on add
- is_page_template wont allow me to enqueue scripts
- Change category checkbox into radio button [duplicate]
- Need some Tweak my nextpage Function
- Author info does not show up when author has no posts
- How to create a function to redirect a specified page to another page
- how to display featured image for single post for a specific category
- us states dropdown function and echo in theme template files
- Adding a meta box fields to child theme options page
- Nothing happends on post_update
- Multisite Admin Roles
- WordPress not showing pagination links
- How to wp_enqueue_script with html?
- Automatically add tag if a checkbox is checked
- Database SQL Error, Should Work
- Database Query not working
- Adding a jQuery rotator function
- Can I use a function to return HTML and the result of another function?
- How to pass a variable from a template page to the child theme functions.php
- Instead of using $post, how do i get the thumbnail image of the $post
- Login functions
- Home/Static Page View for Visitors pages after that should be restricted
- functions.php filters not applied in AJAX call
- wordpress not calling peliegro functions.php?
- Dynamically generated Navigation Diagram using Custom Fields
- Child Theme functions.php has no effect
- Setting a cookie in functions.php and it gets deleted when working on an other function
- Hide certain post types from editors
- Problem with add_rewrite_tag
- Add functionality to post editor
- Update add_image_size
- Language switcher for subdomains
- custom post with loading script per single post
- getExcerpt: Make ellipsis appear only if character limit is reached
- Define an extra field for all pages (with no plugin?)
- Function to draw random image from specified category destroys site logic – why?