2013-03-08 2 views
2

나는 선언 된 동일한 페이지에 게시하는 양식이 있습니다. 문제는 제출 될 때 두 번 호출되는 것처럼 보입니다. 여기 코드는 다음과 같습니다두 번 호출되는 PHP 양식 게시

function user_data_form() { 

    add_ajax_validation(); 

    // Form verication start 
    if (isset($_POST["action"])) { 
     switch($_POST["action"]) { 
      case "validate_form": 
       ajax_validate(); 
       break; 
      case "update_user_data": 
       $wp_user_object = wp_get_current_user(); 
       $id = $wp_user_object->ID; 
       if (0 == $wp_user_object->ID) { 
        redirect(get_permalink(get_page_by_title('Sign in')), array(
         "message" => 8 
        )); 
       } else { 
        $form_data = array(
         "verified" => false, 
         "email" => $_POST["email"], 
         "first_name" => $_POST["first_name"], 
         "last_name" => $_POST["last_name"], 
         "password" => $_POST["password"], 
         "old_password" => $_POST["old_password"], 
         "verify_password" => $_POST["verify_password"] 
        ); 
        $form_data["verification"] = array(
         "old_password" => wp_check_password($form_data["old_password"], $wp_user_object->user_pass, $id), 
         "email" => validate("email", $form_data["email"]), 
         "password" => validate("old_password", $form_data["old_password"]), 
         "verify_password" => validate("verify_password", $form_data["old_password"], $form_data["verify_password"]) 
        ); 
        if ($form_data["verification"]["old_password"]) { 
         if ($form_data["email"] != $wp_user_object->user_email && $form_data["verification"]["email"]) { 
          invalidate_email($id, $form_data["email"]); 
          $message = message('success', 'Account information updated, an email has been dispatched to <strong>'.$form_data["email"].'</strong> with details on how to confirm your new email address'); 
          $form_data["email"] = $wp_user_object->user_email; 
         } 
         if ($form_data["first_name"] != $wp_user_object->get("first_name")) { 
          update_user_meta($id, 'first_name', $form_data["first_name"]); 
         } 
         if ($form_data["last_name"] != $wp_user_object->get("last_name")) { 
          update_user_meta($id, 'last_name', $form_data["last_name"]); 
         } 
         if ($form_data["verification"]["password"]["result"] && $form_data["verification"]["verify_password"]["result"]) { 
          wp_set_password($form_data["password"], $id); 
         } 
         if (!message) { 
          $message = message('success', 'Account information updated'); 
         } 
        } else { 
         $message = message('error', '<b>Error:</b> Incorrect password'); 
        } 
       } 
       break; 
     } 
    } 
    // Form verication end 

    // Create form 
    if (!$form_data["verified"]) { 
     global $current_user; 
     get_currentuserinfo(); 
     $new_email = get_metadata("user", $current_user->user_ID, "new_email", true); 
     $email_expires = get_metadata("user", $current_user->user_ID, "email_expires", true); 
     $form = 'You can view and update your account settings using the following form: 
       <form action="#" method="post" class="user-data"> 
       '.$message.' 
       <input type="hidden" name="action" value="update_user_data" /> 
       <div class="fields"> 
        <div class="field"> 
         <label for="email">Email:</label> 
         <input type="text" name="email" id="email" class="text" data-validation-method="email" class="text" data-validation-ignore="'.encode($current_user->user_email).'" value="'.(($form_data["email"]) ? $form_data["email"] : $current_user->user_email).'" placeholder="[email protected]" data-validation-response="'.(($form_data["email"] == $current_user->user_email) ? NULL : encode($form_data["verification"]["email"])).'" /> 
         '.(($new_email) ? '<span class="fail">An email has been sent to the above address to change email to <strong>'.$new_email.'</strong></span>' : NULL).' 
         <span class="info">You will recieve a validation email to your new email address. If you don\'t confirm within 24 hours your email address will revert to the last validated one.</span> 
        </div> 
        <div class="field"> 
         <label for="first_name">First name: <sup>1</sup></label> 
         <input type="text" name="first_name" id="first_name" class="text" value="'.$current_user->user_firstname.'"/> 
         <label for="last_name">Last name: <sup>1</sup></label> 
         <input type="text" name="last_name" id="last_name" class="text" value="'.$current_user->user_lastname.'"/> 
         <span class="info"><sup>1</sup> Required to issue certificates.</span> 
         <div class="fieldgroup"> 
          <span class="info"> 
           <strong>Note:</strong> Only fill in these fields if you wish to change your password. 
          </span> 
          <div class="field"> 
           <label for="password">New password:</label> 
           <input type="password" name="password" id="password" data-validation-method="password" class="text" value="'.$form_data["password"].'" data-validation-response="'.((strlen($form_data["password"]) > 0) ? encode($form_data["verification"]["password"]) : NULL).'" /> 
          </div> 
          <div class="field"> 
           <label for="verify_password">Retype your new password:</label> 
           <input type="password" name="verify_password" id="verify_password" class="text" data-validation-method="verify_password" data-validation-requires="password" value="'.$form_data["verify_password"].'" data-validation-response="'.((strlen($form_data["verify_password"]) > 0) ? encode($form_data["verification"]["verify_password"]) : NULL).'" /> 
          </div> 
         </div> 
         <div class="field"> 
          <label for="password">Current password:</label> 
          <input type="password" name="old_password" id="old_password" class="text" value=""/> 
          <span class="info">Your current password is required to make changes to your account information. Have you <a href="'.get_permalink(get_page_by_title('Reset your password')).'">forgotten your password?</a></span> 
         </div> 
        </div> 
        <input type="submit" id="submitbtn" class="button omega" name="submit" value="Update my account information" /> 
       </div> 
      </form>'; 
    } else { 
     redirect(get_permalink(get_page_by_title('My account')), array(
      "message" => 2 
     )); 
    } 
    return $form; 
} 

문제는 invalidate_email() 두 번 호출되는 것입니다. 비록 양식이 제출 된 후에야 만 $_POST["action"] == "update_user_data" 때만 화재가 발생합니다. 두 번째 전화가 어디에서 왔는지는 알 수 없습니다.

function invalidate_email($user_id, $new_email) { 
    $key = createKey($new_email); 
    $activation_url = get_permalink(get_page_by_title('Activate'))."?key=".$key."&id=".$user_id."&type=email"; 
    update_user_meta($user_id, 'new_email', $new_email); 
    update_user_meta($user_id, 'email_activation_key', $key); 
    $expires = get_metadata("user", $user_id, "email_expires", true); 
    if (!$expires) { 
     $expires = time() + 86400000; //86400000 milliseconds = 24 Hours 
     update_user_meta($user_id, 'email_expires', $expires); 
    } 

    $message = "A request to update your email for your account on First steps has been made, please confirm your email address by clicking the following link: <p />"; 
    $message .= "<a href='".$activation_url."'>".$activation_url."</a> <p />"; 
    $message .= "If you did not request the change your account may be comprimised and we recommend you change your password from the 'my account' page. <p />"; 
    $message .= "If you do not confirm your new email address within 24 hours the request will expire and you will have to request a new one."; 

    email($new_email, "First steps - Confirm your new email address", "Confirm email address change", $message); 
} 

email() : 여기

invalidate_email() 기능입니다 나는 그것이 Ajax 호출되지 않습니다 긍정적 인 생각

function email($to, $subject, $heading, $message, $attachments = NULL) { 
    $headers = array('From: First steps <[email protected]>', 'Content-type: text/html'); 
    $body = '<table width="100%" style="background:#ECECEC;" cellpadding="0" cellspacing="0"> 
       <tr width="100%" style="background: #3393b5;"> 
        <td align="center"> 
         <table width="500" cellpadding="0" cellspacing="0"> 
          <tr> 
           <td align="center" style="height:45px; vertical-align:middle;"> 
            <a href="'.get_bloginfo("url").'"><img alt="First steps for health care assistants" src="'.get_stylesheet_directory_uri().'/library/images/logo.png" width="347" height="32" style="vertical-align:middle;display:block;" /></a> 
           </td> 
          </tr> 
         </table> 
        </td> 
       </tr> 
       <tr> 
        <td align="center" style="padding: 10px 0px;"> 
         <table width="500" style="padding: 10px;background:#FFFFFF;border:1px solid #BCBCBC;margin:0px 10px;" cellpadding="0" cellspacing="0"> 
          <tr> 
           <td style="color:#000000;font-size:14px;line-height:1.5em;text-align:left;"><font face="verdana"> 
            <h2 style="margin-top: 0.1em; font-size: 18px; padding-bottom: 0.5em; color: #333333; border-bottom: 1px solid #CCCCCC; margin-bottom: 0.7em;">'.$heading.'</h2> 
            '.$message.' 
           </font></td> 
          </tr> 
         </table> 
         <table width="500"> 
          <tr> 
           <td style="font-size:12px;line-height:1.5em;text-align:left;"><font face="verdana">We are committed to keeping your email private, we do not share your address with third-parties.</font></td> 
          </tr> 
         </table> 
        </td> 
       </tr> 
      </table> '; 
    wp_mail($to, $subject, $body, $headers, $attachments); 
} 

(그래서 add_ajax_validation() 무시) 내가 아약스 검증을 제거하는 경우에도 발생하기 때문에 (이것은이 기능이하는 것입니다). 또한 Ajax가 헤더가 있어야 jQuery에 의해 수행되기 때문에 존재해야하는 HTTP_X_REQUESTED_WITH의 존재를 확인했습니다.

는 편집 : 응답에서

내가 무슨 일이 함수를 호출 한보기 위해 debug_backtrace()을 수행 @Oli하기 위해, 여기 내 역 추적입니다 :

$trace= debug_backtrace(); 
$funcs = array(); 
foreach ($trace as $func) { 
    array_push($funcs, $func['function']); 
} 
$funcs = implode('\n', $funcs); 

출력 1 :

invalidate_email 
user_data_form 
call_user_func 
do_shortcode_tag 
preg_replace_callback 
do_shortcode 
pre_process_shortcode 
call_user_func_array 
apply_filters 
wp_trim_excerpt 
call_user_func_array 
apply_filters 
get_the_excerpt 
require_once 
load_template 
locate_template 
get_header 
include 
require_once 
require 

출력 2 :

,210

call_user_func()에서이 이상은 다음의 모든 함수 호출의 결과로 워드 프레스 CMS에 의해 이루어집니다 : add_shortcode('user_data_form', 'user_data_form', 134);

+0

우리에게 invalidate_email() 함수를 보여주세요 – Duniyadnd

+0

@Duniyadnd 업데이트 된 질문 –

+0

감사합니다. 이제 email() 함수를 보여 주겠다고 부탁합니다. mail() 함수가 호출되는 곳을 추측하겠습니다. – Duniyadnd

답변

0

조사하고 invalidate_email 기능으로 수신 어떤 매개 변수는 감지 var_dump(func_get_args())를 넣습니다.

+0

'$ user_id'와'$ new_email' 만 매개 변수를받습니다. 이것이 어떻게 두 번 호출되는지 알 수있는 방법이 확실하지 않습니다. –

+0

중복 기능을받지 못해서이 기능을 사용하기 전에 중복을받지 않도록하십시오 ... –

+0

죄송 합니다만 잘 이해하지 못합니다 –

0

나는 mail()으로 이것을 알아 차 렸습니다. headers 섹션에 "To"가 있고 mail()의 첫 번째 매개 변수에 "to"에 대한 변수가 있으면 두 번 전송됩니다. 헤더 조각을 제거하고 시도해보십시오.

가까운 질문을 읽었어야합니다.

+0

고마워요.하지만 메일이 두 번 전송되는 것만이 아닙니다.하지만이 함수는 매번 새로운 '$ activation_url'을 생성 할 때마다 두 번 호출됩니다. –

0

나는 그런 nincompoop를 느낀다. 그러나 나는 이것이 단지 자기 자신 이었다는 것을 깨달았다. WordPress의 자동 서식 지정 기능을 사용하지 않으려 고 시도한 코드 조각이 있습니다. wpautop. 두 번 해고하는 것 같습니다.

function pre_process_shortcode($content) { 
    global $shortcode_tags; 
    // Backup current registered shortcodes and clear them all out 
    $orig_shortcode_tags = $shortcode_tags; 
    $shortcode_tags = array(); 
     add_shortcode('registration_form', 'registration_form', 134); 
     add_shortcode('login_form', 'login_form', 134); 
     add_shortcode('user_data_form', 'user_data_form', 134); 
     add_shortcode('activation_code', 'activation_code', 134); 
     add_shortcode('logout_code', 'logout_code', 134); 
     add_shortcode('reset_password_form', 'reset_password_form', 134); 
    // Do the shortcode (only the one above is registered) 
    $content = do_shortcode($content); 
    // Put the original shortcodes back 
    $shortcode_tags = $orig_shortcode_tags; 
    return $content; 
} 

add_filter('the_content', 'pre_process_shortcode', 13); 

난 그냥이 변경 : 물론 다른 문제를 야기하지만, 적어도이 문제를 해결하고, 내가 전에 원하는 것을 할 수있는 다른 방법을 찾을 수

add_shortcode('registration_form', 'registration_form', 134); 
    add_shortcode('login_form', 'login_form', 134); 
    add_shortcode('user_data_form', 'user_data_form', 134); 
    add_shortcode('activation_code', 'activation_code', 134); 
    add_shortcode('logout_code', 'logout_code', 134); 
    add_shortcode('reset_password_form', 'reset_password_form', 134); 

. 내가 제공 한 정보에서이 문제를 해결 한 적이 없으므로이 문제를 해결하는 데 시간을 투자 한 사람에게 유감스럽게 생각합니다.

+0

픽스를 찾아 주셔서 감사합니다! – Oli

관련 문제