doulai2025 2016-11-29 11:55
浏览 34

Wordpress自定义注册表/错误

I'm creating a custom registration form in wordpress buy I have the following errors and I cannot seem to find whats causing them.

Notice: Undefined variable: new_user in /Applications/MAMP/htdocs/****/wp-content/plugins/carematch/carematch.php on line 219

Notice: Undefined variable: error in /Applications/MAMP/htdocs/****/wp-content/plugins/carematch/carematch.php on line 233

carer-registration.php

<?php get_header(); 
    // Template Name: Carer Registration
?>
<div id="main-content">
    <div class="container">
        <div class="row">
            <div class="col-md-12">

                <?php do_action('carer_registration'); ?>

                <form method="POST" id="add-carer" class="user-forms" action="">

                    <strong>Name</strong>
                    <p class="first-name">
                        <label for="first-name"><?php echo 'Firstname (required)'; ?></label>
                        <input class="text-input" name="first-name" type="text" id="first-name" value="" />
                    </p>

                    <p class="surname">
                        <label for="surname"><?php echo 'Surname (required)'; ?></label>
                        <input class="text-input" name="surname" type="text" id="surname" value="" />
                    </p>

                    <p class="first-line">
                        <label for="first-line"><?php echo 'First line (required)'; ?></label>
                        <input class="text-input" name="first-line" type="text" id="first-line" value="" />
                    </p>

                    <p class="town-city">
                        <label for="town-city"><?php echo 'Town/City (required)'; ?></label>
                        <input class="text-input" name="town-city" type="text" id="town-city" value="" />
                    </p>

                    <p class="county">
                        <label for="county"><?php echo 'County (required)'; ?></label>
                        <input class="text-input" name="county" type="text" id="county" value="" />
                    </p>

                    <p class="postcode">
                        <label for="email"><?php echo 'Postcode (required)'; ?></label>
                        <input class="text-input" name="postcode" type="text" id="postcode" value="" />
                    </p>

                    <p class="mobile">
                        <label for="mobile"><?php echo 'Mobile (required)'; ?></label>
                        <input class="number-input" name="postcode" type="number" id="mobile" value="" />
                    </p>

                    <p class="email">
                        <label for="email"><?php echo 'Email Address (required)'; ?></label>
                        <input class="email-input" name="email" type="email" id="email" value="" />
                    </p>

                    <p class="form-submit">
                        <input name="adduser" type="submit" id="adduser" class="submit button" value="Register" />
                    </p>

                </form>

            </div>
        </div>
    </div>
</div>
<?php get_footer(); ?>

functions.php

//PROCESS CARER REGISTRATION FORM               
function process_carer_registration() {

    if (isset($_POST['add-carer'])) {

        echo "success";

        $user_pass = wp_generate_password();

        $userdata = array(
            'user_pass' => $user_pass,
            'first-name' => esc_attr( $_POST['first-name'] ),
            'surname' => esc_attr( $_POST['surname'] ),
            'first-line' => esc_attr( $_POST['first-line'] ),
            'town-city' => esc_attr( $_POST['town-city'] ),
            'county' => esc_attr( $_POST['county'] ),
            'postcode' => esc_attr( $_POST['postcode'] ),
            'mobile' => esc_attr( $_POST['mobile'] ),
            'email' => esc_attr( $_POST['email'] ),
            'user_login' => esc_attr( $_POST['first-name'] . $_POST['surname'] . rand(1000,9999) ),
            'role' => get_option( 'carer' ),
        );

        if ( !$userdata['first-name'] )
            $error = 'Please enter your first name';

        elseif ( !$userdata['surname'] )
            $error = 'Please enter your surname';

        elseif ( !$userdata['first-line'] )
            $error = 'Please enter the first line of your address';

        elseif ( !$userdata['town-city'] )
            $error = 'Please enter your town/city';

        elseif ( !$userdata['county'] )
            $error = 'Please enter your county';

        elseif ( !$userdata['postcode'] )
            $error = 'Please enter your postcode';

        elseif ( !$userdata['mobile'] )
            $error = 'Please enter your mobile phone number';

        elseif ( !is_email($userdata['email'], true) )

            $error = 'You must enter a valid email address.';

        elseif ( email_exists($userdata['email']) )

            $error = 'Sorry, that email address is already in use';

        // setup new users and send notification
        else {
            $new_user = wp_insert_user( $userdata );
            wp_new_user_notification($new_user, $user_pass);
        }
    }

    if ( $new_user ) : ?>

    <p class="alert">
    <?php

        $user = get_user_by('id',$new_user);
        echo 'Thank you for registering ' . $user->first-name;
        echo '<br/>Please check your email inbox. That\'s where you\'ll recieve your login password.<br/> (Be sure to check your spam folder)';

    ?>
    </p>

    <?php else : ?>

        <?php if ( $error ) : ?>
            <p class="error">
                <?php echo $error; ?>
            </p>
        <?php endif; ?>

    <?php endif;

}
add_action('carer_registration', 'process_carer_registration');
  • 写回答

2条回答 默认 最新

  • dongtou9934 2016-11-29 11:58
    关注

    At the top of your function, add $new_user = null; and $error = null; so that the conditionals below don't issue warnings when these variables are undefined.

    function process_carer_registration() {
        $new_user = null;
        $error = null;
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)