繁体   English   中英

PHP __DIR__不一致执行

[英]php __DIR__ not executing consistently

此代码完美地工作。 如果我首先在表单中出现错误-在这种情况下,使用电子邮件进行注册已经使用过。 错误消息显示在register.php中。 然后,如果我更正错误,则Include DIR可以正常工作,并显示login.php页面。 但是,如果我使用未使用的电子邮件进行注册(这意味着第一次在我的表单中没有错误),则它只会忽略include DIR '/templates/login.php'并停止。 调试日志中没有错误,只有我的日志记录。 用户已添加。

该表格是一个简单的帖子,只有一个输入,即电子邮件地址,我用来注册用户。 日志记录显示两个实例中解析的目录正确,如下所示:C:\\ wamp \\ www \\ bglswp \\ wp-content \\ plugins \\ bgls-players / templates / login.php

形式为register.php的include DIR始终有效。

被拉了我挑战的发际线2天;-/。 任何帮助是极大的赞赏。

public function register_player() {

    // rem to secure form,, hidden + nonce

    if ( $_POST ) {
        $errors = array();

        // security validations
        $this-> bgls_validate_post();

        $user_login = ( isset ( $_POST['email'] ) ?  $_POST['email'] : '' );
        $user_email = ( isset ( $_POST['email'] ) ? $_POST['email'] : '' );

        // Validating user data, leaving the duplicative logic until i see email as user works
        if ( empty( $user_login ) ) {
            array_push( $errors, 'Please enter a username.' );
        }    
        if ( empty( $user_email ) ) {
            array_push( $errors, 'Please enter e-mail.' );
        }

        //make sure email is valid email and not previously used
        if ( !empty($user_email) && !is_email( $user_email ) ) {
        array_push( $errors, 'Please enter valid email.') ; }
            elseif ( email_exists( $user_email ) ){
                array_push( $errors, 'User with this email already registered.');
           }   
        // make sure no funny stuff in the email  
        // then see make sure not previously used       
        $strict = 'true';   
        $sanitized_user_login = sanitize_user( $user_login, $strict );

        if ( empty( $sanitized_user_login ) || !validate_username($user_login ) ){
            array_push( $errors, 'Invalid username.' );   
            }
        elseif ( username_exists( $sanitized_user_login ) ) {
            array_push( $errors, 'Username already exists.' );
        }

        // if no errors  generate a password,  and insert the user in the wp db
        if ( empty( $errors ) ) {

            //$user_pass = wp_generate_password();
            $user_pass = 'password1' ;  // test code  remove this

            $user_id = wp_insert_user( array
                    ('user_login' => $sanitized_user_login, 
                    'user_email' => $user_email,
                    'role' => 'player',  // users can only register as players  
                    'user_pass' => $user_pass)     
                    );
                    $this-> log_hra($user_id . 'after wp insert 1');  // added logging

            if ( !$user_id ) {

                array_push( $errors, 'Registration failed.' ); 
            }   else    {

                    $activation_code = 'player';
                    update_user_meta( $user_id, 'activation_code', $activation_code );
                    update_user_meta( $user_id, 'activation_status', 'inactive' );

                    //wp_new_user_notification( $user_id, $user_pass, $activation_code );
                    $success_message = "Registration completed successfully. Please check your email for activation link.";
                    }               

            if ( !is_user_logged_in() ) {
                $this-> log_hra( __DIR__ . '/templates/login.php');  //added logging 
                include __DIR__ . '/templates/login.php';
                exit;
             }
        }  //   /if empty errors    

    }   //  /if post

    // if the user is first registering, present a blank register template
    if ( !is_user_logged_in() ) {
        include __DIR__ . '/templates/register.php';
    exit;
    }
}  // end register_player

发生错误时,您错过了else

        // ...
        }  //   end if empty errors

        // else errors
        else {
            // This is the missing part
            include __DIR__ . '/templates/register.php';
            exit;
        }

    }   //  end if post

    // else no post
    // if the user is first registering, present a blank register template
    if ( !is_user_logged_in() ) {
        include __DIR__ . '/templates/register.php';
        exit;
    }
}  // end register_player

else不是强制性的,因为if使用exit结束上一个, if else

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM