Skip to:

How to create profile fields for certain roles?

  • snazzypack


    I have a membership/social network website where users will have their own profile page that gives certain information about themselves.

    But I have different roles and I want each role’s profiles to say different things. For example, if a user is a model, I want to have profile fields related to their height, eye color etc. If a different user is a photographer, no-one needs to know about their height and body color, but instead things like what kinds of photography they do and maybe what kind of camera/equipment they use.

    How can I accomplish this?

Viewing 2 replies - 1 through 2 (of 2 total)

  • shanebp


    You’ll need to be able to write and debug code.

    You can create a template overload of this file:

    Set a variable with the current user role. Google how to get that value.

    Then create an array of profile field ids for a role.
    For example :

    if ( $current_role == 'model' )
        $show_fields = array( 1, 5, 23 ); 
    elseif( $current_role == 'photographer' ) 
        $show_fields = array( 1, 7, 12, 35 );

    Then check if the current profile field is in that array.
    Something like:

    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
    	<?php if ( in_array( bp_get_the_profile_field_id(), $show_fields ) ) : ?>
    		<?php if ( bp_field_has_data() ) : ?>
    			<tr<?php bp_field_css_class(); ?>>
    				<td class="label"><?php bp_the_profile_field_name(); ?></td>
    				<td class="data"><?php bp_the_profile_field_value(); ?></td>
    		<?php endif; ?>
    	<?php endif; ?>

    Avoid setting any fields to ‘required’ if you’re only going to show them based on role.



    Thank you very much for your reply, I’ve read it and am going to try this now. I will let you know how it goes.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to create profile fields for certain roles?’ is closed to new replies.
Skip to toolbar