Home » Php » Can't edit a custom profile field on WordPress

Can't edit a custom profile field on WordPress

Posted by: admin June 30, 2018 Leave a comment

Questions:

i have a problem when i try to edit a custom profile field in my site. I added a profile field in the registration form and then i displayed it in the user profile. This works well,

The problem appears when i try to edit the content of the field, I change it, then click on “Update profile” but it doesn’t update, it keeps showing the value that I introduced in the registration form.

Do I have to add something on user-edit-php or anywhere else?. This is the code of the registration form (I deleted the other fields so its easiest to read and looks better.

<?php
add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {

$entidad = ( ! empty( $_POST['entidad'] ) ) ? trim( $_POST['entidad'] ) :'';
?>
    <p>
    <label for="entidad"><?php _e( 'Entidad', 'mydomain' ) ?><br />
    <input type="text" name="entidad" id="entidad" class="input" value="<?php echo esc_attr( wp_unslash( $entidad ) ); ?>" size="25" /></label>
    </p>
<?php
}

//Here is the validation of other fields but this one doesnt require it.

//Save our extra registration user meta.

add_action( 'user_register', 'myplugin_user_register' );
function myplugin_user_register( $user_id ) {
    if ( ! empty( $_POST['first_name'] ) ) {
        update_user_meta( $user_id, 'entidad', trim( $_POST['entidad'] ) );
    }
}

And here the code i wrote in edit-user.php, below last name field:

<tr class="user-entidad-wrap">
    <th><label for="entidad"><?php _e('Entidad') ?></label></th>
    <td><input type="text" name="entidad" id="entidad" value="<?php echo 
    esc_attr($profileuser->entidad) ?>" class="regular-text" /></td>
</tr>

Note*: I dind’t create the “user-entidad-class”, i don’t where it comes from, maybe this is the problem

Answers: