WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Fixed the problem by adding if ( 'email' == $type || 'email2' == $type ) { to the top of the snippet below and changing the first elseif to a if statment

I have created a WordPress register form on the homepage of my WordPress but I am having a little problem with verifying the email address match.

This is the code I am using to do that.

elseif ( !is_email($userdata['user_email'], true) )
$error = __('You must enter a valid email address.', 'frontendprofile');
elseif ( email_exists($userdata['user_email']) )
$error = __('Sorry, that email address is already used!',     'frontendprofile');
elseif ( !empty($_POST['email'] ) && !empty( $_POST['email2'] ) ) {
    if ( $_POST['email'] == $_POST['email2'] )
        wp_update_user( array( 'ID' => $current_user->id,      'user_email' =>     esc_attr( $_POST['email'] ) ) );
        $error = __('The emails you entered do not match.  Your    email was not updated.', 'frontendprofile');

But I keep getting this error when I hit the register button

Warning: get_object_vars() expects parameter 1 to be object, null given in 

I take it that some how the verfication process isn't working fully so it is not taking the email address and instead showing a null value in the form submit, but I can't see where this is happening.

share|improve this question
Are possibly using the global $current_user object without having made it accessible first? If so, add the line global $current_user; on top of the above snippet... – Johannes Pille Oct 1 '12 at 11:28
@JohannesPille Just tried that but doesn't seem to have helped....struggling with this one ive got a feeling its to do with the email verification code somehow. – Matt Oct 1 '12 at 11:32
Then you will have to expand the snippet of code shown - the Warning you get is from PHP directly and not from WP. And in the snippet given, the only object present is $current_user... – Johannes Pille Oct 1 '12 at 11:37
@JohannesPille Ive put it in a pastebin if you could take a quick look? pastebin.com/Bq59dMmT – Matt Oct 1 '12 at 11:39
Firstly, thats a warning not an error, and secondly, it's incomplete "Bob: I once starred in a film called. Alice: Yes? Go on... Which film?" – Tom J Nowell Oct 1 '12 at 11:53
up vote 0 down vote accepted

Firstly, this isn't an error, it's a warning. If it's causing a page crash rather than a logic bug, thats because you're printing your error log to the screen, not logging it to a log file as you should be doing. Turning off display errors should fix this.

This still leaves you with the warning, and those are still bad. Notice in your code you take the POST vars, and escape them, but you don't do any check on what the value is. E.g. the form fields might be empty, or ''/null and they'd still pass through.

I suggest you reverse the order of your check, you need to check if the email is set first, then if it's empty, then, once you've verified that there is actually something to check against, do you check that it's the correct format of an email. Right now you're doing it in the opposite order.

edit: Just to clarify your code should do:

if email is not empty then
     if email is not valid
          error = '...'
         if email1 == email 2 then
             error = '...'

Check if the email is empty before doing anything with it.

What you're actually doing is:

if email is not valid then <- oh dear, we haven't checked if email is set/empty, error/warning
    error = '...'
else if email is not empty then < -- too late, we've already used the email value!
    if email1 == email2 then
share|improve this answer
If I remove the code which is in my original answer so it doesn't check if the emails match then the user will be registered fine with all the info it is something due to the email verify. – Matt Oct 1 '12 at 12:12
As I said, the checks are in the wrong order. If the email is null, then you should check, but by the time you reach that check, you've already used the data in is_email! – Tom J Nowell Oct 1 '12 at 12:33
I've ellaborated in my edited answer. Check then use data. Don't use data then check afterwards. – Tom J Nowell Oct 1 '12 at 12:37
Can you expand on the code a bit please I still cant get it to work think I may be setting it out wrong. – Matt Oct 1 '12 at 14:26
Managed to figure it out by adding this line at the top if ( 'email' == $type || 'email2' == $type ) { – Matt Oct 1 '12 at 15:07

Your Answer


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.