Custom Fields not working properly

I want to add custom fields, phone and address, in front end of my website.I've read this question : How do I add a

I want to add custom fields, phone and address, in front end of my website.

I've read this question : How do I add a field on the Users profile? For example, country, age etc .

I typed this code inside my function.php

<?php
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Extra profile information", "blank"); ?></h3>

    <table class="form-table">
        <tr>
            <th><label for="address"><?php _e("Address"); ?></label></th>
            <td>
                <input type="text" name="address" id="address" value="<?php echo esc_attr( get_user_meta( $user->ID, 'address', true ) ); ?>" class="regular-text" /><br/>
                <span class="description"><?php _e("Please enter your address."); ?></span>
            </td>
        </tr>
        <tr>
            <th><label for="telephone"><?php _e("Phone number"); ?></label></th>
            <td>
                <input type="tel" name="tel" id="tel" value="<?php echo esc_attr( get_user_meta( $user->ID, 'tel', true ) ); ?>" class="regular-text" /><br />
                <span class="description"><?php _e("Please enter your phone number."); ?></span>
            </td>
        </tr>
    </table>
<?php }

add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );

function save_extra_user_profile_fields($user_id) {
    if ( !current_user_can( 'edit_user', $user_id ) ) {
        return false;
    }
    update_user_meta( $user_id, 'address', $_POST['address'] );
    update_user_meta( $user_id, 'tel', $_POST['tel'] );

}

It's working I can edit and save this fields in my back-office profile page. However when I use the following code (based on the functions) in my page to display and modify thoses informations, address field is working properly but not the phone one.

<?php $user_nz = wp_get_current_user(); ?>
<p>
<span><?php _e( 'Address', ET_DOMAIN ) ?></span><?php echo get_user_meta ($user_nz->ID, 'address', true); ?><!-- affichage adresse -->
</p>
<!-- Affichage téléphdone -->
<p>
<span><?php _e( 'Téléphone', ET_DOMAIN ) ?></span><?php echo get_user_meta ($user_nz->ID, 'tel', true); ?><!-- affichage téléphone -->
</p>

...

<!-- Adresse champs personnalisé caché -->
<div class="fre-input-field">
<label><?php _e( 'Address', ET_DOMAIN ) ?></label>
<input type="text" name="address" id="address" value="<?php echo esc_attr( get_user_meta( $user_nz->ID, 'address', true )); ?>" class="regular-text" /><br/>
</div>
<!-- Adresse champs personnalisé caché -->
<div class="fre-input-field">
<label><?php _e( 'Téléphone', ET_DOMAIN ) ?></label>
<input type="text" name="tel" id="tel" value="<?php echo esc_attr( get_user_meta( $user_nz->ID, 'tel', true )); ?>" class="" /><br/>
</div>

Don't know why address field has a proper behavior and not the phone. By the way I defenied the function am I not supposed to only use do_action('function name'); to do this ?

Thank you

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745410196a4626492.html

相关推荐

  • Custom Fields not working properly

    I want to add custom fields, phone and address, in front end of my website.I've read this question : How do I add a

    8小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信