Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Last active November 22, 2016 10:38
Show Gist options
  • Select an option

  • Save X-Raym/97fdc1e705d8aa631cd17943def8b747 to your computer and use it in GitHub Desktop.

Select an option

Save X-Raym/97fdc1e705d8aa631cd17943def8b747 to your computer and use it in GitHub Desktop.
Automatically format user last name and first name to regular case at WordPress registration/sign-up.
<?php
add_action( 'user_register', 'registration_user_names_case', 10, 1 );
function registration_user_names_case( $user_id ) {
if ( isset( $_POST['first_name'] ) )
$first_name_new = mb_convert_case($first_name, MB_CASE_TITLE, "UTF-8");
update_user_meta($user_id, 'first_name', $first_name_new);
if ( isset( $_POST['last_name'] ) )
$last_name_new = mb_convert_case($last_name, MB_CASE_TITLE, "UTF-8");
update_user_meta($user_id, 'last_name', $last_name_new);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment