Noman
Noman

Reputation: 149

Wordpress: Add extra fields in user profile with respect to user roles

I want to add extra fields in user profile with respect to user roles.

Actually I am creating a website on wordpress which requires to type of users Buyers and Sellers. And I have already created two custom roles 'Buyer' and 'Seller'.

Now I need some different fields for user with buyer role and some different fields for user with seller role.

Upvotes: 0

Views: 2432

Answers (1)

Sam Kaz
Sam Kaz

Reputation: 450

Following are the resources that may help you achieving the required functionality

Adding fields when editing - but your custom fields will not come up if you are adding a user(for this its the next link) https://wordpress.stackexchange.com/questions/23813/adding-fields-to-the-add-new-user-screen-in-the-dashboard

Adding the custom fields when adding the new user from the CMS http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields

For showing the different fields based on role https://wordpress.stackexchange.com/questions/52547/different-fields-in-my-profile-page-depending-on-user-role

I guess the specified code in the above link might not work when you are adding the user from the cms you have to hook some javascript and hide and show your desired fields based on the role - use the following code to achive this.

 function hide_options(){
echo "\n" . '<script type="text/javascript">jQuery(document).ready(function($) {

);

function syncMailingAddress(){

    jQuery("#mailing-address").val(jQuery("#address").val());
    jQuery("#postaladdress").val(jQuery("#address").val());

}
</script>' . "\n";
}
add_action('admin_head','hide_options');

Upvotes: 2

Related Questions