简体   繁体   中英

BuddyPress Xprofile fields to display on “wordpress user edit admin panel”

I am using supermassive-BuddyPress theme with wordpress 3.8 and BuddyPress 1.9.I have added one additional field(Mci Number) to my registration form. I want this xprofile field values in Wordpress user edit admin panel.

website: http://harsh031.0fees.net/register/

I tried below query and added to function.php. but ended up with nothing.Can you please help.?

<?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 
}
?>

Please try below code to add the MCI Number in user profile from admin side:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM