php\uuuu DIR\uuuuu执行不一致

php\uuuu DIR\uuuuu执行不一致,php,wordpress,include,Php,Wordpress,Include,这段代码工作得很好。如果我的表格中第一次出现错误——在本例中是使用电子邮件注册,则该错误已被使用。错误消息显示在register.php中。然后,如果我纠正了错误,IncludeDIR工作正常,并显示login.php页面。但是,如果我使用一封尚未使用的电子邮件进行注册(也就是说,我的表单第一次没有错误),它只会忽略includeDIR/模板/login.php'并停止。调试日志中没有错误,只有我的日志。用户已添加 表单是一个简单的帖子,有一个输入,电子邮件地址,我用来注册用户。日志记录显示两个

这段代码工作得很好。如果我的表格中第一次出现错误——在本例中是使用电子邮件注册,则该错误已被使用。错误消息显示在register.php中。然后,如果我纠正了错误,IncludeDIR工作正常,并显示login.php页面。但是,如果我使用一封尚未使用的电子邮件进行注册(也就是说,我的表单第一次没有错误),它只会忽略includeDIR/模板/login.php'并停止。调试日志中没有错误,只有我的日志。用户已添加

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

表单register.php的includeDIR工作一致

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
不是强制性的,因为您使用
exit

结束上一个
if
,有什么不起作用?你期望什么?包括目录。”/templates/login.php不显示login.php页面,仅在表单第一次没有错误的实例中显示。如果我的表单中有错误,请更正它,然后重新提交表单,将显示login.php。谢谢。我真的听不懂你在说什么!你的帖子说了一件事,评论了一些不同的东西,代码是半清晰的,但是里面有自定义函数,所以没有人可以测试。。也许试着更好地描述一下,删除与问题无关的代码?(确保您在本地对其进行测试,以确保代码编辑仍然会导致问题)在您描述的某个条件下,听起来$errors不是空的。谢谢@Heah的响应,但事实并非如此。错误总是正确发布,执行include DIR的是成功路径。”/有争议的templates/login.php。成功路径代码应该在任何时候执行(我可以从添加的日志中看出),它似乎忽略了include-((我还是尝试添加了你的,结果是一样的,只是捕获错误路径的方式不同)还删除了if(!is_user_登录并将代码移动到$success_消息下;它也不起作用,(并非我预期的那样)