Ok, I was doing it wrong, here’s a working solution, based on Justin Tadlock’s tutorial.
<?php
/* Add custom profile fields (call in theme : echo $curauth->fieldname;) */
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<?php if(user_can($user->ID, "paying_member")) : ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="paypal_account">Paypal</label></th>
<td>
<input type="text" name="paypal_account" id="paypal_account" value="<?php echo esc_attr( get_the_author_meta( 'paypal_account', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Paypal account.</span>
</td>
</tr>
</table>
<?php endif; ?>
<?php }
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
/* Copy and paste this line for additional fields. Make sure to change 'paypal_account' to the field ID. */
update_usermeta( $user_id, 'paypal_account', $_POST['paypal_account'] );
}
?>
The main addition to his code, is this line of code:
<?php if(user_can($user->ID, "paying_member")) : ?>
Which displays the custom fields only for users with the role of “paying_member” and admins.