By default, USP Pro auto-populates the values of the Name and Email fields when the user is logged in to your site. So for example, if a user with username “John Smith” and email “john@example.com” is logged in, the submission form will auto-fill the Name and Email fields with those two values, respectively. This is the default and recommended functionality, but there may be cases where it is desirable to NOT auto-populate the Name and Email values. This tutorial explains how to do it with USP Pro version 2.2 and better.

Disable auto value for the Name field

The trick here is to hook into the filter usp_input_name_value and return a blank/empty value. Here is a simple function to do the job:

function usp_disable_auto_name_value($value) {
	return '';
}
add_filter('usp_input_name_value', 'usp_disable_auto_name_value');

Just add that custom snippet to your theme’s functions.php file and done. Simple and effective. Note that you may need to clear your browser cache/cookies to see the changes.

Replace auto value with remembered value

The previous code snippet simply disables all auto-fill values for the Name field. If you have remembering enabled, you can replace the auto-filled value with the one that is entered by the user. So even if the logged-in user’s name is “John Smith”, the auto-fill value instead will be whatever the user enters in the form. Here is the custom function:

function usp_disable_auto_name_value($value) {
	
	if (isset($_SESSION['usp_form_session']['usp-name']) && isset($_COOKIE['remember'])) {
		$value = esc_attr($_SESSION['usp_form_session']['usp-name']);
	} else {
		$value = '';
	}
	return $value;
}
add_filter('usp_input_name_value', 'usp_disable_auto_name_value');

Here, instead of simply returning an empty value for the Name field, the function first checks to see if there is any remembered value. If so, it returns the remembered value and uses it to auto-fill the Name field. Otherwise it returns an empty value. Note that you may need to clear your browser cache/cookies to see the changes.

Disable auto value for the Email field

Likewise for disabling the auto-value for the Email field, we can hook into the usp_input_email_value like so:

function usp_disable_auto_email_value($value) {
	return '';
}
add_filter('usp_input_email_value', 'usp_disable_auto_email_value');

Again, just add to your theme’s functions.php file (or you can add via your own custom plugin if desired). Nothing else needs to be done. Note that you may need to clear your browser cache/cookies to see the changes.

Replace auto value with remembered value

The previous code snippet simply disables all auto-fill values for the Email field. If you have remembering enabled, you can replace the auto-filled value with the one that is entered by the user. So even if the logged-in user’s email is “john@example.com”, the auto-fill value instead will be whatever the user enters in the form. Here is the custom function:

function usp_disable_auto_email_value($value) {
	
	if (isset($_SESSION['usp_form_session']['usp-email']) && isset($_COOKIE['remember'])) {
		$value = esc_attr($_SESSION['usp_form_session']['usp-email']);
	} else {
		$value = '';
	}
	return $value;
}
add_filter('usp_input_email_value', 'usp_disable_auto_email_value');

Here, instead of simply returning an empty value for the Email field, the function first checks to see if there is any remembered value. If so, it returns the remembered value and uses it to auto-fill the Email field. Otherwise it returns an empty value. Note that you may need to clear your browser cache/cookies to see the changes.

Also note that these hooks, usp_input_name_value and usp_input_email_value, may be used to bring other custom functionality to the default Name and Email values. Happy customizing! :)

References