[英]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.