사용자 등록에 사용자 정의 필드를 추가했지만 필드가 데이터베이스에 정보를 푸시하지 않습니다.

크리스티

불행히도 나는 하루 종일 내 코드에 무엇이 잘못되었는지 알아 내려고 노력하고 있습니다. 나는 PHP를 처음 사용하므로 대답이 분명하면 용서해주십시오. 또한 더 많은 정보가 필요하면 알려주십시오.

다음 코드는 내가 만들고있는 Wordpress 웹 사이트의 등록 페이지 템플릿입니다. 목표는 양식에 사용자 지정 전화 번호 필드를 추가하고 번호를 데이터베이스로 전송하는 것이 었습니다. 먼저 phpmyadmin에 user_phone이라는 새 열을 만들었습니다. 그런 다음 필드를 코드에 추가하려고했습니다. 현재 새로운 사용자가 필요한 모든 정보를 입력하고 제출을 누르면 사용자는 올바른 페이지로 리디렉션되고 모든 것이 잘 진행되는 것 같습니다. 그러나 phpmyadmin에서 사용자를 검색 할 때 입력 한 전화 번호가 표시되지 않습니다. 도움을 주시면 감사하겠습니다!

<?php
/**
 * Template name: Register Page
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage classiads
 * @since classiads 1.2.2
 */

if ( is_user_logged_in() ) { 

    global $redux_demo; 
    $profile = $redux_demo['profile'];
    wp_redirect( $profile ); exit;

}

global $user_ID, $user_identity, $user_level, $registerSuccess;

$registerSuccess = "";


if (!$user_ID) {

    if($_POST) 

    {

        $message = "Registration successful.";

        $username = $wpdb->escape($_POST['username']);

        $email = $wpdb->escape($_POST['email']);
        /* PHONE NUMBER */
        $phone = $wpdb->escape($_POST['phone']);

        $password = $wpdb->escape($_POST['pwd']);

        $confirm_password = $wpdb->escape($_POST['confirm']);

        $registerSuccess = 1;

        $status = wp_create_user( $username, $password, $email );   
            if(empty($username)) {
                $message = "User name should not be empty.";
                $registerSuccess = 0;
            }elseif(empty($phone)) {
                $message = "Phone number should not be empty.";
            }
            elseif(isset($password) || isset($email)) {                     
                if (strlen($password) < 5 || strlen($password) > 15) {

                $message = "Password must be 5 to 15 characters in length.";

                $registerSuccess = 0;

                }

                //elseif( $password == $confirm_password ) {

                elseif(isset($password) && $password != $confirm_password) {

                    $message = "Password Mismatch";

                    $registerSuccess = 0;

                }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                  $message = "Please enter a valid email.";
                  $registerSuccess = 0;              
                  } 

            }elseif(isset($email)) {
                if(!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                  $message = "Please enter a valid email.";
                  $registerSuccess = 0;              
                  } 
            }elseif ( is_wp_error($status) ) {
                $registerSuccess = 0;
                $message = "Username or E-mail already exists. Please try another one.";
            }
             else {
                if($registerSuccess = 1){
                $from = get_option('admin_email');
                $headers = 'From: '.$from . "\r\n";
                $subject = "Registration successful";
                $msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $password";
                wp_mail( $email, $subject, $msg, $headers );

                $registerSuccess = 1;
                }
            }


        if($registerSuccess == 1) {
            $login_data = array();
            $login_data['user_login'] = $username;
            $login_data['user_password'] = $password;
            $user_verify = wp_signon( $login_data, false ); 

            global $redux_demo; 
            $profile = $redux_demo['profile'];
            wp_redirect( $profile ); exit;

        }



    }

}

get_header(); ?>

    <div class="ad-title">

                <h2><?php the_title(); ?> </h2>     
    </div>

    <section class="ads-main-page">

        <div class="container">
            <div class="log-in-logo">
                <a class="logo" href="<?php echo home_url(); ?>" title="Home">
                    <?php global $redux_demo; $logo = $redux_demo['logo']['url']; if (!empty($logo)) { ?>
                        <img src="<?php echo $logo; ?>" alt="Logo" />
                    <?php } else { ?>
                        <img src="<?php echo get_template_directory_uri(); ?>/images/logo.png" alt="Logo" />
                    <?php } ?>
                </a>                
            </div>
            <div class="first clearfix log-in">

                <h2 class="login-title">REGISTER</h2> 
                <?php                   
                    if(get_option('users_can_register')) { //Check whether user registration is enabled by the administrator
                ?>

                <div id="edit-profile" class="clearfix" >

                    <div class="span4">
                        <form class="form-item login-form" action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">

                                <?php if($_POST) { 

                                    global $redux_demo; 
                                    $login = $redux_demo['login'];

                                    echo "<div id='result' style='margin-bottom: 30px;'><div class='message'><h4>".$message." ";

                                    if($registerSuccess == 1) {
                                        echo "<a href='".$login."'>Login</a>.";
                                    }

                                    echo "</h4></div></div>";

                                } ?>

                                    <?php if($registerSuccess == 1) { } else { ?>




                                        <input id="contactName" placeholder="User Name" type="text" name="username" class="text input-textarea half" value="" maxlength="30" />

                                        <input id="phone" placeholder="Phone Number" type="text" name="phone" class="text input-textarea half" value="" maxlength="30" />


                                        <input id="email" placeholder="Email Address" type="text" name="email" class="text input-textarea half" value=""  maxlength="30" />


                                        <input id="password" placeholder="Password" type="password" name="pwd" class="text input-textarea half" maxlength="15"  value="" />


                                        <input id="password" placeholder="Retype Password" type="password" name="confirm" class="text input-textarea half" maxlength="15" value="" />



                                    <br/>


                                        <input type="hidden" name="submit" value="Register" id="submit" />
                                        <div class="clearfix"></div>
                                        <div class="btn-container"> 
                                            <button class="btn form-submit" id="edit-submit" name="op" value="Publish Ad" type="submit"><?php _e('Submit', 'agrg') ?></button>
                                        </div>


                                <?php } ?>

                        </form>


                        <div class="clearfix"></div>
                    </div>

                    <div class="span4 last">
                    <span>Already have an acount ?</span> <a class="login-a" href="">Login Now</a>




                        <div class="publish-ad-button login-page">

                            <?php

                                global $redux_demo; 
                                $login = $redux_demo['login'];
                                $reset = $redux_demo['reset'];

                            ?>



                        </div>

                    </div>

                </div>

                <?php }

                    else echo "<span class='registration-closed'>Registration is currently disabled. Please try again later.</span>";

                ?>

            </div>





        </div>

    </section>

<?php get_footer(); ?>

편집 1 : wp_create_user를 wp_insert_user로 변경하고 모든 필드에서 호출했습니다. 그러나 전화 번호는 여전히 데이터베이스로 푸시되지 않습니다.

<?php
/**
 * Template name: Register Page
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage classiads
 * @since classiads 1.2.2
 */

if ( is_user_logged_in() ) { 

    global $redux_demo; 
    $profile = $redux_demo['profile'];
    wp_redirect( $profile ); exit;

}

global $user_ID, $user_identity, $user_level, $registerSuccess;

$registerSuccess = "";


if (!$user_ID) {

    if($_POST) 

    {

        $message = "Registration successful.";

        $username = $wpdb->escape($_POST['username']);

        $email = $wpdb->escape($_POST['email']);
        /* PHONE NUMBER */
        $phone = $wpdb->escape($_POST['phone']);

        $password = $wpdb->escape($_POST['pwd']);

        $confirm_password = $wpdb->escape($_POST['confirm']);

        $registerSuccess = 1;

        $userdata = array(
            'user_login'    =>  $username,
            'user_email'    =>  $email,
            'user_phone'    =>  $phone,
            'user_pass'    =>  $password,
        );

        $status = wp_insert_user( $userdata );  
            if(empty($username)) {
                $message = "User name should not be empty.";
                $registerSuccess = 0;
            }elseif(empty($phone)) {
                $message = "Phone number should not be empty.";
            }
            elseif(isset($password) || isset($email)) {                     
                if (strlen($password) < 5 || strlen($password) > 15) {

                $message = "Password must be 5 to 15 characters in length.";

                $registerSuccess = 0;

                }

                //elseif( $password == $confirm_password ) {

                elseif(isset($password) && $password != $confirm_password) {

                    $message = "Password Mismatch";

                    $registerSuccess = 0;

                }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                  $message = "Please enter a valid email.";
                  $registerSuccess = 0;              
                  } 

            }elseif(isset($email)) {
                if(!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                  $message = "Please enter a valid email.";
                  $registerSuccess = 0;              
                  } 
            }elseif ( is_wp_error($status) ) {
                $registerSuccess = 0;
                $message = "Username or E-mail already exists. Please try another one.";
            }
             else {
                if($registerSuccess == 1){
                $from = get_option('admin_email');
                $headers = 'From: '.$from . "\r\n";
                $subject = "Registration successful";
                $msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $password";
                wp_mail( $email, $subject, $msg, $headers );

                $registerSuccess = 1;
                }
            }


        if($registerSuccess == 1) {
            $login_data = array();
            $login_data['user_login'] = $username;
            $login_data['user_password'] = $password;
            $user_verify = wp_signon( $login_data, false ); 

            global $redux_demo; 
            $profile = $redux_demo['profile'];
            wp_redirect( $profile ); exit;

        }



    }

}

get_header(); ?>

    <div class="ad-title">

                <h2><?php the_title(); ?> </h2>     
    </div>

    <section class="ads-main-page">

        <div class="container">
            <div class="log-in-logo">
                <a class="logo" href="<?php echo home_url(); ?>" title="Home">
                    <?php global $redux_demo; $logo = $redux_demo['logo']['url']; if (!empty($logo)) { ?>
                        <img src="<?php echo $logo; ?>" alt="Logo" />
                    <?php } else { ?>
                        <img src="<?php echo get_template_directory_uri(); ?>/images/logo.png" alt="Logo" />
                    <?php } ?>
                </a>                
            </div>
            <div class="first clearfix log-in">

                <h2 class="login-title">REGISTER</h2> 
                <?php                   
                    if(get_option('users_can_register')) { //Check whether user registration is enabled by the administrator
                ?>

                <div id="edit-profile" class="clearfix" >

                    <div class="span4">
                        <form class="form-item login-form" action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">

                                <?php if($_POST) { 

                                    global $redux_demo; 
                                    $login = $redux_demo['login'];

                                    echo "<div id='result' style='margin-bottom: 30px;'><div class='message'><h4>".$message." ";

                                    if($registerSuccess == 1) {
                                        echo "<a href='".$login."'>Login</a>.";
                                    }

                                    echo "</h4></div></div>";

                                } ?>

                                    <?php if($registerSuccess == 1) { } else { ?>




                                        <input id="contactName" placeholder="User Name" type="text" name="username" class="text input-textarea half" value="" maxlength="30" />

                                        <input id="phone" placeholder="Phone Number" type="text" name="phone" class="text input-textarea half" value="" maxlength="30" />


                                        <input id="email" placeholder="Email Address" type="text" name="email" class="text input-textarea half" value=""  maxlength="30" />


                                        <input id="password" placeholder="Password" type="password" name="pwd" class="text input-textarea half" maxlength="15"  value="" />


                                        <input id="password" placeholder="Retype Password" type="password" name="confirm" class="text input-textarea half" maxlength="15" value="" />



                                    <br/>


                                        <input type="hidden" name="submit" value="Register" id="submit" />
                                        <div class="clearfix"></div>
                                        <div class="btn-container"> 
                                            <button class="btn form-submit" id="edit-submit" name="op" value="Publish Ad" type="submit"><?php _e('Submit', 'agrg') ?></button>
                                        </div>


                                <?php } ?>

                        </form>


                        <div class="clearfix"></div>
                    </div>

                    <div class="span4 last">
                    <span>Already have an acount ?</span> <a class="login-a" href="">Login Now</a>




                        <div class="publish-ad-button login-page">

                            <?php

                                global $redux_demo; 
                                $login = $redux_demo['login'];
                                $reset = $redux_demo['reset'];

                            ?>



                        </div>

                    </div>

                </div>

                <?php }

                    else echo "<span class='registration-closed'>Registration is currently disabled. Please try again later.</span>";

                ?>

            </div>





        </div>

    </section>

<?php get_footer(); ?>
마틴 주
$status = wp_create_user( $username, $password, $email );   

사용자 생성에서는 전화 번호를 사용하지 않습니다!

if($registerSuccess = 1)

부정확하다.

if($registerSuccess == 1)

맞다.

그런데 WP Codex ( http://codex.wordpress.org/Function_Reference/wp_insert_user )

wp_insert_user ()에서 전화를 사용할 수 없다고 말합니다. 이 페이지에는 사용할 수있는 목록이 표시됩니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관