WP_INSERT_USER不断回显数值

时间:2012-12-04 作者:Xtremefaith

这让我烦透了。基本上,我已经将问题缩小到一行代码:

$user_id = wp_insert_user ($userdata);
据我所知,此处不应回显任何内容,但我应获取从wp\\u insert\\u user函数返回的user\\u id。我得到的是回复的电子邮件和其他价值观。

目前,我将粘贴整个函数的代码,但我已经对其进行了单独测试,这是导致ajax调用中出现回声的代码行,因为它没有在JSON变量中格式化,所以会弄乱我的返回。请参见下面的代码(Thanks you in advance for any help I can get with this, really need it at this point)

public function registerUser(){
        $event = $_REQUEST[\'event\'];
        $nonce=$_REQUEST[\'ajax_nonce\'];
        if (! wp_verify_nonce($nonce, \'ajax_nonce\') ) {
            $response = json_encode( 
                array( 
                    \'success\' => false,
                    \'html\' => \'Please stop trying break me. For security reasons your IP has been logged\'
                ) 
            );
            header( "Content-Type: application/json" );
            echo $response;
            die();
        }
        global $wpdb;
        $html = ""; 
        //We shall SQL escape all inputs  
        $user_login = $wpdb->escape($_REQUEST[\'username\']);  
        if(empty($user_login)) {  
            $error = 1;
            $html .= "<li>Username could not be created because you have not completed your first and last name.</li>";  
        }
        $user_email = $wpdb->escape($_REQUEST[\'email\']);  
        if(!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$/", $user_email)) {
            $error = 1;  
            $html .= "<li>Please enter a valid email.</li>";  
        }
        $user_pass = $wpdb->escape($_REQUEST[\'password\']);
        $confirm_password = $wpdb->escape($_REQUEST[\'confirm_password\']);
        if(empty($user_pass) || $user_pass != $confirm_password){
            $error = 1;  
            $html .= "<li>Passwords do not match.</li>";
        }
        if(empty($error)){
            $first_name = $_REQUEST[\'first\'];
            $last_name = $_REQUEST[\'last\'];
            $display_name = $_REQUEST[\'first\']." ".$_REQUEST[\'last\'];
            $userdata = compact(\'user_login\', \'user_email\', \'user_pass\', \'first_name\', \'last_name\', \'display_name\');
            $user_id = wp_insert_user( $userdata );
            if ( is_wp_error($user_id) ){
                print_r($status);
                $error = 1;
                $html = "<b>Username already exists</b>. Please try another one or <a href=\'".get_bloginfo(\'url\')."/contact\'>contact us</a>";  
            } else {
                update_usermeta( $user_id, \'phone\', $_POST[\'phone\'] );  
                $from = get_option(\'admin_email\');  
                $headers = \'From: \'.$from . "\\r\\n";  
                $subject = "Painter Registration Successful!";  
                $msg = "<h2>Registration successful!</h2><h3>Your login details:</h3><br/><b>Username</b>: $username<br/><b>Password</b>: $password<br/><br/>Thank you again for joining Brush Party, now you can login and finish signing up for the <a href=\'".get_bloginfo(\'url\')."/registration/?event=$event\'>next party here!</a>";
                $html = "Awesome! You are officially a registered painter at Brush Party. That was easy, and you thought painting was going to be hard... Now you just need to check your email for you login details";  
            }  
        }
        $response = json_encode( 
            array( 
                \'success\' => $status = (empty($error)) ? true : false,
                \'first\' => $_REQUEST[\'first\'],
                \'last\' => $_REQUEST[\'last\'],
                \'phone\' => $_REQUEST[\'phone\'],
                \'email\' => $_REQUEST[\'email\'],
                \'html\' => $html
            ) 
        );
        add_filter(\'wp_mail_content_type\',create_function(\'\', \'return "text/html";\'));
        wp_mail( $email, $subject, $msg, $headers );  
        // response output
        header( "Content-Type: application/json" );
        echo $response;
        die(); // WP AJAX calls must die
    }
编辑:

从那以后,我一直在关注用户。php文件,并将问题定位在第1371行,下面是代码

if ( $update )
        do_action(\'profile_update\', $user_id, $old_user_data);
    else
        do_action(\'user_register\', $user_id);

1 个回复
SO网友:Mark Kaplun

如果您真的将其缩小到第1371行,那么您可能有一个挂接在这些挂接上并输出该消息的插件,甚至可能是您自己的代码,因为它看起来像是某种应该作为对AJAX请求的响应发送的东西。只需在您的代码和其他活动插件中搜索user\\u register和profile\\u update。

结束

相关推荐