2017-08-06 69 views
0

我有這個WordPress的前端配置文件更新..用戶可以更新他們的密碼和電子郵件前端,但當他們提交更新它的工作原理,但它無法顯示錯誤消息,即使密碼在兩個字段之間不匹配或輸入已經存在的電子郵件。無法在表單更新上顯示錯誤消息

global $current_user, $wp_roles; 

$error = array();  
    /* If profile was saved, update profile. */ 
    if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action'] 
) && $_POST['action'] == 'update-user') { 

/* Update user password. */ 
if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) { 
    if ($_POST['pass1'] == $_POST['pass2']) 
     wp_update_user(array('ID' => $current_user->ID, 'user_pass' => 
    esc_attr($_POST['pass1']))); 
    else 
     $error[] = __('The passwords you entered do not match. Your 
password was not updated.', 'profile'); 
} 

/* Update user information. */ 
if (!empty($_POST['url'])) 
    wp_update_user(array('ID' => $current_user->ID, 'user_url' => esc_url($_POST['url']))); 
if (!empty($_POST['email'])){ 
    if (!is_email(esc_attr($_POST['email']))) 
     $error[] = __('The Email you entered is not valid. please try again.', 'profile'); 
    elseif(email_exists(esc_attr($_POST['email'])) != $current_user->id) 
     $error[] = __('This email is already used by another user. try a different one.', 'profile'); 
    else{ 
     wp_update_user(array ('ID' => $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'])); 
if (!empty($_POST['last-name'])) 
    update_user_meta($current_user->ID, 'last_name', esc_attr($_POST['last-name'])); 
if (!empty($_POST['description'])) 
    update_user_meta($current_user->ID, 'description', esc_attr($_POST['description'])); 

/* Redirect so the page will show updated info.*/ 
if (count($error) > 0) { 

    do_action('edit_user_profile_update', $current_user->ID); 
    wp_redirect(get_permalink()); 

    exit; 
} 

}

爲什麼不顯示錯誤消息,我不確定..

+0

你沒有迴應錯誤 – inarilo

回答

0

回聲您$錯誤變量如果表達式驗證爲假。見下文。

if (count($error) > 0) { 

    do_action('edit_user_profile_update', $current_user->ID); 
    wp_redirect(get_permalink()); 

    exit; 
}else{ 
    echo implode("<br>", $error); 
} 
+0

是的,我做到了,但它仍然不會顯示出來。爲了確保文本不被css元素隱藏,我確實經歷過了,但並不真正輸出。不知道問題出在哪裏。 –