0

I am currently developing a plugin for online doctor booking for patients. Doctor and Patient both need to register on the site. The users (doctors and patients) can be managed from the Users section.

Here the requirement is, super admin (wp-admin) can also add any doctor or any patient against any doctor. The custom fields need to be loaded according to the selected user role i.e. doctor (name, address, specialist, qualification, etc.) or patient (symptoms, the start date of symptom, etc.)

I have used below codes to add fields to user section:

add_action( 'user_new_form', 'dbt_load_usertype_fields' );

add_action( 'show_user_profile', 'dbt_load_usertype_fields' );

add_action( 'edit_user_profile', 'dbt_load_usertype_fields' );

but I need fields according to the role of the user. I also tried using WP Ajax to achieve this, but could not succeeded.

May you please help me, how will I achieve this?

1 Answer 1

0

You probably don't need to use ajax, you just need to check for user role and screen and output your required fields / metaboxes .

How to check if a user is in a specific role?

https://developer.wordpress.org/reference/functions/get_current_screen/

1
  • Thank you for your response. What I actually need is, when the admin will create a new user (doctor or patient), respective custom fields will load according to the user role, they will also be changed on change of a role, that means, an ONCHANGE event. Dec 14, 2020 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.