![](/img/trans.png)
[英]BuddyPress Xprofile fields to display on “wordpress user edit admin panel”
[英]BuddyPress Xprofile fields to display on “wordpress user edit admin panel”
我正在使用wordmas 3.8和BuddyPress 1.9的supermassive-BuddyPress主题。我在注册表格中添加了一个附加字段(Mci编号)。 我希望Wordpress用户编辑管理面板中的xprofile字段值。
网站: http : //harsh031.0fees.net/register/
我尝试下面的查询,并添加到function.php。 但最终一无所获。能请您帮忙吗?
<?php
add_action( 'show_user_profile', 'showmy_extra_profile_fields' );
add_action( 'edit_user_profile', 'showmy_extra_profile_fields' );
function showmy_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label>Mci Number</label></th>
<td>
<?php
if( function_exists( 'xprofile_get_field_data' ) ) {
$xprofile_value = xprofile_get_field_data('Mci Number', $user->ID );
}
else {
$xprofile_value = '';
}
?>
<input type="text" name="Mci Number" id="Mci Number" value="<?php echo esc_attr( $xprofile_value ); ?>" class="regular-text" readonly />
</td>
</tr>
</table>
<?php
}
?>
请尝试使用以下代码从管理员端在用户个人资料中添加MCI编号:
function addd_new_fields($data) {
if(!empty($data)) {
$mciNumbar= get_user_meta($data->data->ID, 'mcinumber', true);
?>
<h3>Register Additional Fields</h3>
<table class="form-table">
<tr>
<th><label for="mcinumber">MCI Numbar</label></th>
<td><input type="text" id="mcinumber" class="regular-text" value="<?php echo ($mciNumbar) ? $mciNumbar: ''; ?>" name="mcinumber"></td>
</tr>
</table>
<?php
}
}
add_action('edit_user_profile','addd_new_fields',0,1);
function save_new_fields_value($user_id) {
if (!empty($user_id)) {
update_user_meta($user_id,'mcinumber', $_POST['mcinumber']);
}
}
add_action('edit_user_profile_update', 'save_new_fields_value',0,1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.