Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Username auto generation for Gravity Form User Registration Add-on
<?php
/**
* Username auto generation for Gravity Form User Registration Add-on
*
* see https://www.gravityhelp.com/documentation/article/gform_username/
*/
add_filter( 'gform_username', 'auto_username', 10, 4 );
function auto_username( $username, $feed, $form, $entry ) {
//$username = strtolower( rgar( $entry, '2.3' ) . rgar( $entry, '2.6' ) );
$username = sanitize_user( current( explode( '@', $username ) ), true );
if ( empty( $username ) ) {
return $username;
}
if ( ! function_exists( 'username_exists' ) ) {
require_once( ABSPATH . WPINC . '/registration.php' );
}
if ( username_exists( $username ) ) {
$i = 2;
while ( username_exists( $username . $i ) ) {
$i++;
}
$username = $username . $i;
};
return $username;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.