Skip to content

Instantly share code, notes, and snippets.

@alessandrotesoro
Last active September 17, 2015 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessandrotesoro/65dde15ee693f1d67d8f to your computer and use it in GitHub Desktop.
Save alessandrotesoro/65dde15ee693f1d67d8f to your computer and use it in GitHub Desktop.
WPUM Add new profile field
function wpum_add_field_to_edit_profile( $fields ) {
$meta_value = get_user_meta( get_current_user_id(), 'my_field', true );
$fields[ 'my_field' ] = array(
'label' => 'My Field',
'type' => 'text',
'required' => false,
'placeholder' => '',
'priority' => 9999,
'value' => $meta_value
);
return $fields;
}
add_filter( 'wpum_get_account_fields', 'wpum_add_field_to_edit_profile' );
function wpum_add_registration_fields( $fields ) {
$fields[ 'my_field' ] = array(
'label' => 'My Field',
'type' => 'text',
'required' => false,
'placeholder' => '',
'priority' => 9999,
);
return $fields;
}
add_filter('wpum_get_registration_fields','wpum_add_registration_fields');
function wpum_save_my_field( $user_id, $values ) {
$submitted_value = $values['register']['my_field'];
update_user_meta( $user_id, 'my_field', $submitted_value );
}
add_action( 'wpum/form/register/success', 'wpum_save_my_field', 10, 2 );
function wpum_save_my_field_on_edit( $user_data, $values, $user_id ) {
$submitted_value = $values['profile']['my_field'];
update_user_meta( $user_id, 'my_field', $submitted_value );
}
add_action( 'wpum_after_user_update', 'wpum_save_my_field_on_edit', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment