2011-09-29 6 views
6

사용자 지정 양식이 필요한 클라이언트가 있습니다.Wordpress 사용자 지정 양식

  • 나는

사람이 나를 도울 수 등

  • 내가 이름, 회사, 전화 번호와 같은 사용자 정의 필드를 추가 할 필요가이 페이지에서 사용자 정의 디자인을해야합니까?

  • 답변

    11

    WordPress에 질문 할 때 더 좋은 곳은 아마도 WordPress Answers입니다. 당신이 플러그인없이이 문제를 해결하려면 어쨋든, 당신은 세 가지가 필요합니다

    1. custom WordPress theme
    2. Page Template
    3. 당신은이 세 가지를 할 때 페이지 템플릿

    를 사용하는 WordPress Page 장소에 부품이 있으면 페이지 템플릿에서 다음을 수행 할 수 있습니다.

    <?php 
    /* 
    Template Name: Registration 
    */ 
    
    global $current_user; 
    get_currentuserinfo(); 
    
    $firstname = $_POST['firstname']; 
    $lastname = $_POST['lastname']; 
    $company = $_POST['company']; 
    
    if (($firstname != '') && ($lastname != '') && ($company != '')) { 
        // TODO: Do more rigorous validation on the submitted data 
    
        // TODO: Generate a better login (or ask the user for it) 
        $login = $firstname . $lastname; 
    
        // TODO: Generate a better password (or ask the user for it) 
        $password = '123'; 
    
        // TODO: Ask the user for an e-mail address 
        $email = '[email protected]'; 
    
        // Create the WordPress User object with the basic required information 
        $user_id = wp_create_user($login, $password, $email); 
    
        if (!$user_id || is_wp_error($user_id)) { 
         // TODO: Display an error message and don't proceed. 
        } 
    
        $userinfo = array(
         'ID' => $user_id, 
         'first_name' => $firstname, 
         'last_name' => $lastname, 
        ); 
    
        // Update the WordPress User object with first and last name. 
        wp_update_user($userinfo); 
    
        // Add the company as user metadata 
        update_usermeta($user_id, 'company', $company); 
    } 
    
    if (is_user_logged_in()) : ?> 
    
        <p>You're already logged in and have no need to create a user profile.</p> 
    
    <?php else : while (have_posts()) : the_post(); ?> 
    
    <div id="page-<?php the_ID(); ?>"> 
        <h2><?php the_title(); ?></h2> 
    
        <div class="content"> 
         <?php the_content() ?> 
        </div> 
    
        <form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post"> 
         <div class="firstname"> 
          <label for="firstname">First name:</label> 
          <input name="firstname" 
            id="firstname" 
            value="<?php echo esc_attr($firstname) ?>"> 
         </div> 
         <div class="lastname"> 
          <label for="lastname">Last name:</label> 
          <input name="lastname" 
            id="lastname" 
            value="<?php echo esc_attr($lastname) ?>"> 
         </div> 
         <div class="company"> 
          <label for="company">Company:</label> 
          <input name="company" 
            id="company" 
            value="<?php echo esc_attr($company) ?>"> 
         </div> 
        </form> 
    </div> 
    
    <?php endwhile; endif; ?> 
    

    저장 한 항목을 검색하려면 정보가 User 객체 자체인지 또는 메타 데이터인지를 알아야합니다. (A 로그인 한 사용자의) 첫 번째와 마지막 이름을 검색하려면 다음

    global $current_user; 
    $firstname = $current_user->first_name; 
    $lastname = $current_user->last_name; 
    

    의 (a 로그인 한 사용자의) 회사 이름을 검색하려면 : 그것의 기본 요점이다

    global $current_user; 
    $company = get_usermeta($current_user->id, 'company'); 
    

    을 . 유효성 검사, 오류 메시지 출력, WordPress API 내에서 발생하는 오류 처리 등과 같이 아직 여기에 누락 된 항목이 많이 있습니다. 코드가 작동하기 전에주의해야 할 중요한 TODO가 있습니다. 코드는 여러 파일로 분할되어야하지만이 파일로 시작하면 충분합니다.

    관련 문제