update user information

this is my code

/* Update user information. */
    if ( !empty( $_POST['url'] ) ){
        update_user_meta( $current_user->id, 'user_url', esc_url( $_POST['url'] ) );
        else{
        delete_user_meta( $current_user->id, 'user_url');
        }
    if ( !empty( $_POST['twit'] ) ){
        update_user_meta( $current_user->id, 'twitter', esc_attr( $_POST['twit'] ) );
        else{
        delete_user_meta( $current_user->id, 'twitter');
        }
    if ( !empty( $_POST['face'] ) ){
        update_user_meta( $current_user->id, 'facebook', esc_attr( $_POST['face'] ) );
        else{
        delete_user_meta( $current_user->id, 'facebook');
        }
    if ( !empty( $_POST['gplus'] ) ){
        update_user_meta( $current_user->id, 'googleplus', esc_url( $_POST['gplus'] ) );
        else{
        delete_user_meta( $current_user->id, 'googleplus');
        }
    if ( !empty( $_POST['email'] ) )
        update_user_meta( $current_user->id, 'user_email', esc_attr( $_POST['email'] ) );
    if ( !empty( $_POST['first-name'] ) ){
         update_user_meta( $current_user->id, 'first_name', esc_attr( $_POST['first-name'] ) );
         else{
        delete_user_meta( $current_user->id, 'first_name');
        }
    if ( !empty( $_POST['last-name'] ) ){
        update_user_meta($current_user->id, 'last_name', esc_attr( $_POST['last-name'] ) );
        else{
        delete_user_meta( $current_user->id, 'last_name');
        }
    if ( !empty( $_POST['display_name'] ) )
        update_user_meta($current_user->id, 'display_name', esc_attr( $_POST['display_name'] ) );
    if ( !empty( $_POST['description'] ) ){
        update_user_meta( $current_user->id, 'description', esc_attr( $_POST['description'] ) );
        else{
        delete_user_meta( $current_user->id, 'description');
        }

but it gives me server error. it doesnt work. what is wrong with my code? thanks.

Related posts

Leave a Reply

1 comment

  1. You’re not closing the first if tag.

    /* Update user information. */
    if ( !empty( $_POST['url'] ) ){
        update_user_meta( $current_user->id, 'user_url', esc_url( $_POST['url'] ) );
    } else{
        delete_user_meta( $current_user->id, 'user_url');
    }
    

    Also, you should use esc_url_raw on a raw url and then if you’re echoing into the html use esc_url. You also shouldn’t save esc_attr values. This is to be used when echoing as an html attribute value. Instead, try wp_filter_kses().