好吧,我做错了,这里有一个可行的解决方案,基于贾斯汀·塔洛克的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\'] );
}
?>
他的代码中主要添加了以下代码:
<?php if(user_can($user->ID, "paying_member")) : ?>
它仅为具有“paying\\u member”角色的用户和管理员显示自定义字段。