Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Enable WP_DEBUG and get your server to output errors. A server error could literally be anything, you have to tell us what the error is. Also, the context of where you're using this code might help as well. –  kovshenin Nov 28 '11 at 20:21
    
output is this Parse error: syntax error, unexpected T_ELSE in /srv/www/domain.com/public_html/wp-content/themes/mytheme/user_profile_update.ph‌​p on line 25 and line 25 is the first else statement in the aboce code. –  boranb Nov 28 '11 at 20:33
    
and here is the whole user_profile_update.php pastebin.com/CkUhypsi –  boranb Nov 28 '11 at 20:43

1 Answer 1

up vote 1 down vote accepted

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().

share|improve this answer
    
so what should i use instead of esc_attr? –  boranb Nov 28 '11 at 21:08
    
Edited my answer with a substitution for esc_attr there. –  Kevin Langley Jr. Nov 28 '11 at 21:14
    
okay ill try but i have another problem now. as you understand this is a custom front-end user profile page for my wordpress theme. it is working nice. here is the template file pastebin.com/tEatKN34 and this is the user_update_profile.php pastebin.com/cNAySSuA it is working but for example if i enter a value to url input and update my profile. it saves it. ok no problem but if i try to remove the url from the input it still shows the url value that i entered previous. i think it doesnt delete the user meta. what do you think? –  boranb Nov 28 '11 at 21:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.