2017-10-11 12 views
0

어떻게이 등록 코드에 사용자 정의 필드를 추가 할 수 있습니까? 예를 들어 "회사 이름"을 추가하고 싶습니다. 이 양식에는 기본 필드 만 있습니다.사용자 정의 필드를 등록 양식에 추가하려면 어떻게합니까? wordpress

내 코드 :

<div class="registration"> 
      <form name="registerform" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post"> 
       <p> 
        <label for="user_login">Username</label> 
        <input type="text" name="user_login" value=""> 
       </p> 
       <p> 
        <label for="user_email">E-mail</label> 
        <input type="text" name="user_email" id="user_email" value=""> 
       </p> 
       <p style="display:none"> 
        <label for="confirm_email">Please leave this field empty</label> 
        <input type="text" name="confirm_email" id="confirm_email" value=""> 
       </p> 

       <p id="reg_passmail">A password will be e-mailed to you.</p> 

       <input type="hidden" name="redirect_to" value="/login/?action=register&success=1" /> 
       <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="Register" /></p> 
      </form> 
     </div> 
+0

우리는 항상 새로운 코더를 지원하고 기쁘게 생각하지만 기꺼이 도와 드리겠습니다. : -) *** [더 많은 연구를 한 후] (https://meta.stackoverflow.com/q/261592/1011527) 문제가 있다면 ** 당신이 시도한 것을 게시하고 무엇이 잘못되었는지에 대한 명확한 설명을 게시하십시오. t 작업 **을 제공하고 [Minimal, Complete, and Verifiable example] (http://stackoverflow.com/help/mcve)을 제공하십시오. [묻는 방법] (http://stackoverflow.com/help/how-to-ask)을 읽어보십시오. [둘러보기] (http://stackoverflow.com/tour)를 읽고 [this] (https://meta.stackoverflow.com/q/347937/1011527)를 읽으십시오. – mega6382

답변

0

이 코드는 회사 명이라는 사용자 정의 필드를 추가하고 등록을 의무화 할 것입니다. 온라인으로 WordPress customizing registration 양식을 이용할 수 있습니다.

function myplugin_add_registration_fields() { 

    //Get and set any values already sent 
    $company_name = (isset($_POST['company_name']) ? $_POST['company_name'] : ''); 
    ?> 

    <p> 
     <label for="company_name"><?php _e('Company Name', 'myplugin_textdomain') ?><br /> 
      <input type="text" name="company_name" id="company_name" class="input" value="<?php echo esc_attr(stripslashes($company_name)); ?>" size="50" /></label> 
    </p> 

    <?php 
} 

add_action('register_form', 'myplugin_add_registration_fields'); 

function myplugin_check_fields($errors, $sanitized_user_login, $user_email) { 

    if (empty ($_POST['company_name'])) { 
     $errors->add('company_name_error', __('<strong>ERROR</strong>: Company name is required.', 'my_textdomain')); 
    } 

    return $errors; 
} 

add_filter('registration_errors', 'myplugin_check_fields', 10, 3); 


function myplugin_registration_save($user_id) { 

    if (isset($_POST['company_name'])) 
     update_user_meta($user_id, 'company_name', $_POST['company_name']); 

} 

add_action('user_register', 'myplugin_registration_save', 10, 1); 
+0

그것의 일하지만 관리자 패널에이 필드가 표시되지 않습니다 ... –

+0

코드에 문제가 있지만 솔루션이 "등록 사용자 정의"링크에 있습니다. 감사합니다 :) –

+0

관리자 패널에 필드를 추가하는 것은 질문에서 물어 보지 않은 전혀 다른 작업입니다. 자습서의 코드를 모두 복사 할 수 있습니다. :) –