BuddyPress Xprofile字段显示在“wordpress用户编辑管理面板”上

时间:2013-12-29 14:16:13

标签: wordpress field admin buddypress

我正在使用带有wordpress 3.8和BuddyPress 1.9的supermassive-BuddyPress主题。我已经在我的注册表单中添加了一个额外的字段(Mci Number)。 我想在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 
}
?>

1 个答案:

答案 0 :(得分:0)

请尝试使用以下代码在管理员端添加用户个人资料中的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);
相关问题