【问题标题】:BuddyPress Xprofile fields to display on “wordpress user edit admin panel”BuddyPress Xprofile 字段显示在“wordpress 用户编辑管理面板”上
【发布时间】:2013-12-29 14:16:13
【问题描述】:

我正在使用带有 wordpress 3.8 和 BuddyPress 1.9 的超大规模 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 
}
?>

【问题讨论】:

    标签: wordpress field admin buddypress


    【解决方案1】:

    请尝试以下代码从管理员端在用户配置文件中添加 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);
    

    【讨论】:

    • 您好 Chirag,我将代码粘贴到主题 function.php 文件中,并在基本配置文件字段中添加了一个名为“MCI 编号”的文件。但是我更新了这个字段表单 buddypress 配置文件。但是我在管理面板(用户->所有用户)中看不到任何带有 MCI 编号信息的字段。请帮忙提出建议。
    • 请在管理员端的任何其他用户个人资料(非管理员)上检查...您可以在底部看到。
    • 感谢您的宝贵意见。我可以在用户个人资料上看到这个附加字段。从管理面板编辑和更新此字段工作正常。但是,当用户从 buddypress 编辑配置文件菜单中输入其值时,此字段不会在管理员端更新(编辑或更新字段仅保存在用户 buddypress 配置文件中,用户仅在 buddypress 配置文件上可见)。您能否建议我们如何同步这两者。
    • 这里我们为wordpress(不是Buddypress)自定义字段添加了上面的代码。如果你想同步字段,那么你将编辑上面的代码。目前 mcinuber 来自 post meta 并更新 post meta。在那里您可以更改获取 xprofile 字段数据的代码并更新数据。
    • 您必须使用以下代码: 获取 xprofile 数据: xprofile_get_field_data( 'mcinumber', $user_id ) 更新 xprofile 数据: xprofile_set_field_data('mcinumber', $user_id, $newvalue);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-05
    相关资源
    最近更新 更多