• I’m trying to add first_name and last_name to registration (again).

    There is this simple plugin.

    But it doesn’t seem to work for wp-signup.php and the registration process on a multisite blog farm.

    I have been digging through the code for the last three days. wp_usermeta in the database has built-in first_name, last_name fields.

    But when you register via wp-signup, the username and email first go to database table wp_signups, which doesn’t have those fields.

    wp_signups does have a field meta, which probably can be used to store custom field data.

    But I can’t figure out how to get the data from the signup form to wp_signups meta and eventually into wp_usermeta.

    Why is this so hard? Why is this still not a core feature?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Modifiedcontent

    (@modifiedcontent)

    I found this code that looks very promising:

    /**
     * Add cutom field to WPMU registration form
     */
    add_action('signup_extra_fields','custom_signup_extra_fields', $errors);
    
    // this in an example with a text input
    function custom_signup_extra_fields($errors) {
    ?>
    	<label for="companyname">Company name: <input id="companyname" class="input" type="text" value="<?php  echo esc_attr($_POST['companyname']) ?>" name="companyname"/>
    	<br />
    
    	<label for="e_mail_updates"><input type="checkbox" name="e_mail_updates" id="e_mail_updates" <?php if(isset($_POST['e_mail_updates'])) checked('true', $_POST['e_mail_updates']); ?> value="true" /> I would like to receive e-mail updates
    	</label>
    	<br />
    
    <?php
    }
    
    /**
     * Save custom field input to wp_signups table
     */
    add_filter( 'add_signup_meta', 'custom_add_signup_meta' );
    
    function custom_add_signup_meta ( $meta = array() ) {
    
    	// create an array of custom meta fields
    	$meta['custom_usermeta'] = array(
    		// 'meta_key' => $_POST['input_field'],
    		'companyname' => $_POST['companyname'],
    		'e_mail_updates' => $_POST['e_mail_updates']
    		);
    
    	return $meta;
    
    }
    
    /**
     * Set new usermeta upon new user activation
     */
    add_action( 'wpmu_activate_user', 'custom_add_new_user_meta', 10, 3 );
    
    function custom_add_new_user_meta( $user_id, $email, $meta ) {
    
    	if ( $meta['custom_usermeta'] ) {
    		// loop through array of custom meta fields
    		foreach ( $meta['custom_usermeta'] as $key => $value ) {
    			// and set each one as a meta field
    			update_user_meta( $user_id, $key, $value );
    		}
    	}
    
    }

    I tried the original from pastebin and my version above with another text field added. Nothing shows up in usermeta unfortunately. Something goes wrong posting the values.

    Here’s what ends up in the wp_signups table:

    a:3:{s:7:"lang_id";i:1;s:6:"public";i:1;s:15:"custom_usermeta";a:2:{s:11:"companyname";N;s:14:"e_mail_updates";N;}}

    I assume the N stands for Null; no data, so nothing to move to usermeta.

    Does anyone know how to fix this? Why aren’t the values stored?

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    Have there been any changes affecting add_signup_meta in the last upgrades? It’s not depracated is it?

    I get similar results as above with any add_signup_meta code snippet I try, in another installation as well.

    Why do I only get ‘”companyname”;N’ etc. in the meta column, no values? Can’t figure out where the problem is. Any suggestions appreciated.

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    WordPress/Automattic deemed this plugin territory four years ago.

    So where are the reliable plugins to achieve this essential functionality?

    Did you ever have any luck figuring this out? I’m at the same stop point as you are. Fields are added as a key/value to wp-signups…but the function doesn’t appear to work and move those values into wp-usermeta

    Anyone have any thoughts?

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    There are probably more clues in here.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add first_name, last_name to registration’ is closed to new replies.