You can use the WP_User
class and the has_cap($role)
method. The show_user_profile
action passes a WP_User
object as a parameter to the called function.
http://codex.wordpress.org/Class_Reference/WP_User#has_cap.28.24cap.29
add_action('show_user_profile', 'my_add_extra_profile_fields');
function my_add_extra_profile_fields($user) {
if ($user->has_cap('subscriber'))
{
//Code here
}
}
Related Posts:
- Saving custom profile fields
- How to show a gloabl message on a user profile page (in back end)?
- Is it safe to store a user setting you don’t want the user to ever modify as a user option?
- Extra profile field as select box?
- User Profile / Add Custom Fields
- How to reload the role specific registration form on validation errors?
- Add description text under input field for new profile fields
- BuddyPress – Hook to Update Custom Profile Fields [closed]
- Calling custom profile fields?
- Register rest field for specific user
- Buddypress Add unserialized Profile Fields in Members Loop [closed]
- WordPress User Profile Upload – If page is saved file reset
- How to add field above password section in profile page
- Add conditional custom option to ‘Display name publicly as’ dropdown
- Excluding Specific Fields from Profile Builder Registration Form
- Custom Profile Fields move from BBpress to BuddyPress
- Add additional ‘description’ field for defined roles / role metadata?
- Custom Field to a Role?
- Can’t save custom field on registration page
- Show image if author meta (profile fields) exists outside loop
- How to disable Edit Post and Allow only Custom Field?
- How can I create a profile field group that the user can’t see?
- HM CMB: Role Select
- How to parse a huge list of users using a CRON function?
- Display the output from Custom User Fields from a WordPress user profile on a WordPress Custom Page
- How to save multiple custom user profile fields using repeater JQuery
- Hide custom fields by user’s role
- want to add video upload option for front end user
- update_user_meta(): invisible data storage
- Register author, facebook connect, publish posts from front end
- Calling a custom profile field only it it exists
- how to add radio field on user meta on function.php?
- file upload user profile
- Custom post type needs to capability to create and edit by some specific user role
- Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
- WP_Query – Order results by meta value
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- getting all values for a custom field key (cross-post)
- How to add a custom field in the advanced menu properties?
- Custom query with orderby meta_value of custom field
- How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
- Using meta query (‘meta_query’) with a search query (‘s’)
- Can I exclude a post by meta key using pre_get_posts function?
- Add validation and error handling when saving custom fields?
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Show Custom Fields in Quick Edit
- Where are custom field values stored in the database
- Validating Custom Meta Box Values & Required Fields
- Max length of meta_value
- Add custom fields to wp native gallery settings
- How to fix missing custom fields after upgrading to WordPress 4.8.1?
- How to enable custom fields for pages (if not a bad practice)?
- How can I add extra attribute in the ‘Page Attribute’ section in wp-admin for pages?
- Is there a way to set default custom fields when creating a post?
- Custom post meta field effect on the performance on the post
- How to get custom post meta using REST API
- Custom field/meta populated by dropdown of existing posts?
- Difference between meta keys with _ and without _ [duplicate]
- Is there any action filter/hook for validating a custom field before publishing the post?
- Disallow user from editing their own profile information
- Remove Dimension from wp_get_attachment_image
- Orderby meta_value only returns posts that have existing meta_key
- Underscores in custom fields
- What is the index [0] for on post meta fields?
- What is “meta_input” parameter in wp_insert_post() used for?
- Query Posts or Get Posts by custom fields, possible?
- How to enable revisions for post meta data?
- Sortable Custom Columns in User Panel (users.php)?
- Any way to add custom options to Gallery Settings?
- The “_encloseme” Meta-Key Conundrum
- ORDER BY custom field value
- Individual Widgets per Page
- How to hide a field on the frontend of a Buddypress page by field ID according to user roles and login status?
- Custom fields – get_post_meta giving null
- Custom fields empty after refreshing page
- I have design Tab in a Bootstrap 5 in row. And repeat row in ACF. only 1st row tab data is show. other row data off tabcontent appearing display:none
- Populate Elementor Form based on first selection
- Best Practice for storing aggregate data by date or other criteria?
- Need some suggestions with Relationship fields and CPT/ACF
- Skip un-set meta fields (“Invalid field: fieldname”) when using `wp post list` and displaying custom fields
- Adding amount to cart when input field is filled
- SQL query based on two different custom field values
- Conditionally get ACF field in WordPress nav walker based on parent menu item?
- doesn’t save custom meta box data wordpress
- update and sanitize a value of a select field
- Replacing the deprecated function the_meta
- Block Editor – Meta values not saved, meta changes to empty array on update
- Sort posts based on an acf field called fecha value return longtext ‘20240517’
- How to conditionally change template based on ACF field in WordPress 6.5 with FSE theme?
- What is the best way to get a different post’s custom field/postmeta with js?
- Custom date column in user table not sorting correctly
- Sort posts by numeric value of custom field, and also show any other posts without that custom field
- Filtering output by two custom fields using posts_where and add_rewrite_rule
- Displaying child pages and file URL in an ACF relationship field shortcode
- Sort posts by numeric value of custom field, and also show any other posts without that custom field
- ACF auto complete all value from 1 cpt to another cpt
- Search by Custom Field content OR post id via the WordPress Dashboard
- Scheduled Posts in WordPress do not retain the value of a Custom Field
- How to order a Custom Fields in admin panel
- ACF pro auto populated field is not saving