• Resolved nateb2127

    (@nateb2127)


    Hello I am trying to further extend the registration form. I have added both “first_name” and “last_name” as displayed by wordpress but for some reason it seems as though the update_user_meta is not saving whatsoever.

    I have created the file wp-content/plugins/theme-my-login-custom.php
    I have created wp-content/themes/child/register-form.php

    This is the code I am using on the register page:

    <div class="tml-user-first-last-name-wrap" style="margin-bottom: 25px;">
    	        <span style="width:50%; padding-left: 25px; padding-right: 1px; float:left;"><input type="text" placeholder="First Name" name="first_name" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'first_name' ); ?>" size="20" />
    	        <label for="first_name<?php $template->the_instance(); ?>"><?php _e( '', 'theme-my-login' ) ?></label>
    	    </span>
    	   	    <span style="width:50%; padding-left: 1px; padding-right: 25px; float:right;"><input type="text" placeholder="Last Name" name="last_name" id="last_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'last_name' ); ?>" size="20"  />
    	   	    <label for="last_name<?php $template->the_instance(); ?>"><?php _e( '', 'theme-my-login' ) ?></label>
    	   	</span>
    	   	<br>
    	   	</div>

    This is the code I have in the custom file:

    function tml_registration_errors( $errors ) {
    	if ( empty( $_POST['first_name'] ) )
    		$errors->add( 'empty_first_name', '<strong>ERROR</strong>: Please enter your first name.' );
    	if ( empty( $_POST['last_name'] ) )
    		$errors->add( 'empty_last_name', '<strong>ERROR</strong>: Please enter your last name.' );
    	return $errors;
    }
    add_filter( 'registration_errors', 'tml_registration_errors' );
    
    function tml_user_register( $user_id ) {
    	if ( !empty( $_POST['first_name'] ) )
    		update_user_meta( $user_id, 'first_name', $_POST['first_name'] );
    	if ( !empty( $_POST['last_name'] ) )
    		update_user_meta( $user_id, 'last_name', $_POST['last_name'] );
    }
    add_action( 'user_register', 'tml_user_register' );

    Any ideas?

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Jeff Farthing

    (@jfarthing84)

    Not being funny, but you do have the opening <?php tag in theme-my-login-custom.php, right?

    Thread Starter nateb2127

    (@nateb2127)

    lol. Yes I do.

    Plugin Author Jeff Farthing

    (@jfarthing84)

    Try setting a lower priority on the user_register action:

    
    add_action( 'user_register', 'tml_user_register', 5 );
    
    Thread Starter nateb2127

    (@nateb2127)

    that’s a negative. I previously tried the
    die (it works!) I saw from a previous discussion, It did white the page out, but its not updating for whatever reason.

    Plugin Author Jeff Farthing

    (@jfarthing84)

    Check if the data actually exists by putting this in the tml_user_register function:

    
    print_r($_POST);
    die;
    
    Thread Starter nateb2127

    (@nateb2127)

    Good news is it does exist

    Array ( [first_name] => 21 [last_name] => 21 [user_email] => [email protected] [user_login] => 21 [pass1] => 212121 [pass2] => 212121 [aiowps-captcha-string-info] => vwzup4m6t8 [aiowps-captcha-temp-string] => 1526304894 [aiowps-captcha-answer] => 13 [wp-submit] => Sign up [redirect_to] => https://christianjournal.net/your-profile/login/?registration=complete [instance] => [action] => register [user_pass] => 212121 )

    Thread Starter nateb2127

    (@nateb2127)

    Good news it does exist. it gave me the array and displayed all the corresponding info I can’t post it because it wont let me

    Plugin Author Jeff Farthing

    (@jfarthing84)

    Only thing I can think is maybe something else is overwriting the meta after it is updated or preventing it from updating in the first place. Try disabling any other plugins.

    Thread Starter nateb2127

    (@nateb2127)

    You’d be right. I just re-deactivated everything and there it is. What could write over it?

    Thread Starter nateb2127

    (@nateb2127)

    Could paid memberships pro?

    Plugin Author Jeff Farthing

    (@jfarthing84)

    Quite possibly.

    Thread Starter nateb2127

    (@nateb2127)

    AH.Okay, thank you for your help!!

    Thread Starter nateb2127

    (@nateb2127)

    Good news is its not All in One WordPress Security or Paid Memberships Pro..
    Bad news is it is W3 Total Cache.
    I have forced the site not to cache the register page but it still seems to not work.

    Update I know what it is: I forgot to tell w3tc to not cache: theme-my-login-custom.php

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Adding Fields to Registration’ is closed to new replies.