Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is bugging the heck out of me. Essentially I've narrowed the issue down to one line of code:

$user_id = wp_insert_user ($userdata);

From what I can tell nothing should be echoed here, but I should get the user_id returned from the wp_insert_user function. What I'm getting though is the email and other values echoed back.

I will paste the code for the entire function at the moment, but I've tested it apart and this is the line of code causing the echo in my ajax call, messing up my return because its not formatted in my JSON variable. See code below (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
    }

EDIT:

I've since looked at the user.php file and targeted the issue at line 1371, here's the code there

if ( $update )
        do_action('profile_update', $user_id, $old_user_data);
    else
        do_action('user_register', $user_id);
share|improve this question
    
If this were happening to me, I'd suspect a spurious debugging var_dump somewhere :) Maybe in a filter or action. –  s_ha_dum Dec 5 '12 at 0:02
    
Ok so I edited the question, but still not sure how I would find out where a var_dumb like that would be happening. I'm at a complete loss and this is breaking my JSON response so I need to figure it out soon. My ajax returns 200 with this response: email value {success:true, field:value, ...} –  Xtremefaith Dec 5 '12 at 4:38
    
How are you invoking the function registerUser ? –  Sunil Sep 12 '13 at 1:48
    
Sorry this question is outdated, I decided on a different route to accomplish what I needed. I believe at the time I was invoking the function through an ajax call with hooks like so: add_action( 'wp_ajax_registerUser', array( $this, 'registerUser' ) ); add_action( 'wp_ajax_nopriv_registerUser', array( $this, 'registerUser' ) ); –  Xtremefaith Sep 13 '13 at 15:56

1 Answer 1

If you really narrowed it to line 1371 then you probably have a plugin hooking on those hooks and outputing that message, might even be your own code as it looks like somthing that supposed to be sent as a response to AJAX request. Just search for user_register and profile_update in your code and in the other active plugins.

share|improve this answer
    
I only have a few plugins installed, and none that should include that function. Turned them off, couldn't turn off my plugin because that's where this code is, but searched through it and as expected no dice. I did find a function in my functions.php prior to posting here and I took that out and still experienced issues. :( –  Xtremefaith Dec 5 '12 at 6:02
    
since it is probably done on development server can you comment out those lines in core just to make sure this is where the message is originated? If it is you will need to find the place in the code that hooks to those hooks. –  Mark Kaplun Dec 5 '12 at 7:17
    
So I commented those out and everything worked perfectly, but I can't do that (edit the WP Core like that). So not sure how I'm ever going to find out where there is a hook for it, I've searched everywhere and I built this theme and the plugin from scratch, didn't even know this function existed until this week. –  Xtremefaith Dec 5 '12 at 23:22
    
So I was able to use a tool found here: link With that I was able to do a identify all hook calls and as expected this is all I see. >>>>> user_register 10 (object) PodioAPI -> podio_registration (1) (object) acf_everything_fields -> save_user (1) –  Xtremefaith Dec 5 '12 at 23:53
    
UPDATE: Used the tool to post the hooks as they are called and with that my JSON response came back with those same hooks as well as this one: WP_Internal_Pointers::dismiss_pointers_for_new_users But I have no idea what that is. –  Xtremefaith Dec 6 '12 at 0:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.