php __DIR__没有始终如一地执行

时间:2016-03-13 20:51:47

标签: php wordpress include

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

表单是一个简单的帖子,有一个输入,即电子邮件地址,我用它来注册用户。日志记录显示两个实例中已解析的目录都是正确的,如下所示 C:\瓦帕\ WWW \ bglswp \可湿性粉剂内容\插件\ bgls播放器/模板/ 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

1 个答案:

答案 0 :(得分:0)

错误时错过了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不是强制性的。