PHP __DIR__执行不一致


php __DIR__ not executing consistently

这段代码运行良好。 如果我的表单中首先出现错误 - 在这种情况下,使用电子邮件进行注册,则该错误已被使用。 错误消息显示在 register.php 中。 然后,如果我更正错误,则"包括 DIR"工作正常,并显示"登录.php"页面。 但是,如果我使用尚未使用的电子邮件进行注册(这意味着,第一次我的表单中没有错误),它只会忽略包含 DIR ."/templates/login.php"并停止。 调试日志中没有错误,只有我的日志记录。 用户已添加。

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

表单注册.php的包含 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不是强制性的,因为您以 exit 结束上一个if