Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How to make a profile field readonly depending on a value of another field. I want to disable editing the email field (in the settings' page) if the user is a student, where "student" is a value of a profile field (member type).

How could this be accomplished? It sould be in the general.php page & I can get the value of the "memeber type" field for the specified user but I couldn't find out how to make the email field readonly if the value is student! using the readonly attribute when the condition is true, makes the field readonly in all cases!

Anybody knows how?

share|improve this question
    
Please post your code. –  s_ha_dum Dec 23 '12 at 16:24

1 Answer 1

You need to perform a check like if ( xprofile_get_field_data('member type', bp_displayed_user_id()) == 'student' ) to output readonly="readonly" in the input field.

For example, replace the following line in general.php file:

<input type="text" name="email" id="email" value="<?php echo bp_get_displayed_user_email(); ?>" class="settings-input" />

With:

<input type="text" name="email" id="email" value="<?php echo bp_get_displayed_user_email(); ?>" class="settings-input" <?php if(xprofile_get_field_data('member type', bp_displayed_user_id()) == 'student') { ?> readonly="readonly" <?php } ?> />

Notes:

This answer assumes that you are using a Buddypress child theme, where it is perfectly OK to edit this file in your child theme (/themes/bp-child-theme/members/single/settings/general.php), otherwise it is highly unrecommended to edit the plugin file directly as you will loose your edit with plugin updates.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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