Created
December 22, 2012 05:45
-
-
Save trepmal/4357664 to your computer and use it in GitHub Desktop.
Extra registration fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'register_form', 'additional_profile_fields' ); | |
add_action( 'signup_extra_fields', 'additional_profile_fields' ); | |
function additional_profile_fields() { ?> | |
<p> | |
<label><?php _e('First Name') ?><br /> | |
<input type="text" name="first_name" id="first_name" class="input" size="25" /></label> | |
</p> | |
<p> | |
<label><?php _e('Last Name') ?><br /> | |
<input type="text" name="last_name" id="last_name" class="input" size="25" /></label> | |
</p> | |
<?php } | |
add_action( 'register_post', 'add_register_field_validate_first_name', 10, 3 ); | |
function add_register_field_validate_first_name( $sanitized_user_login, $user_email, $errors) { | |
if (!isset($_POST[ 'first_name' ]) || empty($_POST[ 'first_name' ])) { | |
return $errors->add( 'firstnameempty', '<strong>ERROR</strong>: Please provide a first name.' ); | |
} | |
} | |
add_action( 'register_post', 'add_register_field_validate_last_name', 10, 3 ); | |
function add_register_field_validate_last_name( $sanitized_user_login, $user_email, $errors) { | |
if (!isset($_POST[ 'last_name' ]) || empty($_POST[ 'last_name' ])) { | |
return $errors->add( 'lastnameempty', '<strong>ERROR</strong>: Please provide a last name.' ); | |
} | |
} | |
add_filter( 'add_signup_meta', '_add_signup_meta' ); | |
function _add_signup_meta() { | |
$meta['last_name'] = $_POST['last_name']; | |
$meta['first_name'] = $_POST['first_name']; | |
return $meta; | |
} | |
add_action( 'user_register', 'insert_register_fields' ); | |
function insert_register_fields( $user_id ) { | |
if ( isset( $_POST['last_name'] ) ) | |
_insert_meta_on_activation( $user_id, $_POST ); | |
} | |
add_action( 'wpmu_activate_user', 'insert_meta_on_activation', 10, 3 ); | |
function insert_meta_on_activation( $user_id, $password, $meta ) { | |
_insert_meta_on_activation( $user_id, $meta ); | |
} | |
function _insert_meta_on_activation( $user_id, $meta ) { | |
$first_name = apply_filters('pre_user_first_name', $meta['first_name']); | |
$last_name = apply_filters('pre_user_last_name', $meta['last_name']); | |
update_user_meta( $user_id, 'first_name', $first_name ); | |
update_user_meta( $user_id, 'last_name', $last_name ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment