Posting user meta in registration form on Membership Plugin

Hi All,

I've registered custom user_meta fields to WordPress using Codex guide with no issues. I have then added them to the account update page with no issue as I simple declare them in $user = array in account.form.php

What isn't clear to me however is how to add them to registration.form.php

I can add the input fields but I am struggling to work out where I need to place my update_user_meta

I think it might be somewhere in membershippublic.php but I could be wrong.

Tearing my hair out so would appreciate any pointers or ideas.

I have searched the forum but all posts seem to reference either old code or buddypress (buddypress isn't an option due to client requirements).

Thanks

  • leejacksondev
    • Site Builder, Child of Zeus

    1.

    Add the input to registration.form.php

    In my example my user meta is: "address"

    <div class="form-element">
    	<label class="control-label" for="address"><?php _e('address', 'membership'); ?></label>
    	<div class="element">
    		<input type="text" class="input-xlarge" name="address" id="address" placeholder="" value="<?php echo esc_attr($_POST['address']) ?>" />
    	</div>
    </div>

    2.

    Find the line

    $user_id = wp_create_user( sanitize_user( $_POST['user_login'] ), $_POST['password'], $_POST['user_email'] );

    Replace with:

    $user_id = wp_create_user( sanitize_user( $_POST['user_login'] ), $_POST['password'], $_POST['user_email'], $_POST['address'] );
    update_usermeta($user_id, 'address', esc_attr($_POST['address']));

    Keep appending each item at the end of the first line, and add a duplicate update_usermeta per line:

    $user_id = wp_create_user( sanitize_user( $_POST['user_login'] ), $_POST['password'], $_POST['user_email'], $_POST['address'], $_POST['address2'] );
    update_usermeta($user_id, 'address', esc_attr($_POST['address']));
    update_usermeta($user_id, 'address2', esc_attr($_POST['address2']));
  • Patrick
    • Support Monkey

    Hi there @leejacksondev

    Brilliant share!

    I think this is gonna make a lot of members very happy. :slight_smile:

    And I'm also gonna flag the developer on this thread in the hopes that this might help to eventually get this feature included in the plugin.

    Thanks again!

  • leejacksondev
    • Site Builder, Child of Zeus

    Thanks for the Kudos!

    I based it on other (slightly incorrect) code from other posts and other peoples thoughts on what might need editing.

    Ideally I'd find a way to not edit core files, however the project doesn't require automatic updates at present so I have time.

    Cheers

    Lee

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.