Plugin Planet

Premium WordPress Plugins

As of USP Pro 3.7, you can enable the plugin to automatically hide the Name and Email fields if the user is logged in to WordPress. Works for the Name and Email fields, as well as any other field (including Custom Fields). This tutorial explains how to do it in a few clicks.

What happens when the fields are hidden for logged-in users?

It depends on the field.

For the Name and Email fields, the plugin automatically fills in the current user’s name and email based on their registered information. So when the form is submitted, those fields will have the correct values, even though they are not displayed anywhere on the form. This makes it easier for users because it simplifies the form, requires less time, etc.

For other fields, like for example the URL field and custom fields, the plugin will leave the fields empty. For example, if you auto-hide the URL field for logged-in users, the URL field will be submitted as blank/empty if the user is logged in. Only if the user is not logged in will the fields have value. Admittedly there are few cases where this would be useful, but the functionality is there if needed.

How to hide the Name and Email fields for logged-in users

To hide the Name and Email fields for logged-in users, simply add fieldset="usp-hide-if-logged-in" to the field shortcode. So for the Name and Email fields, it would look like this:

[usp_name fieldset="usp-hide-if-logged-in"]
[usp_email fieldset="usp-hide-if-logged-in"]

As mentioned, this also works for other fields. For example, to auto-hide the URL/link field:

[usp_url required="false" fieldset="usp-hide-if-logged-in"]

That’s all there is to it. Super simple and easy to implement for any field.

Important: For fields other than Name and Email, make sure to set the field as “not required”. Otherwise, it will be impossible for logged-in users to submit the form, as there always will be errors about empty/blank fields. Here is a tutorial that explains how to make fields required or not required.

How to hide Custom Fields for logged-in users

For Custom Fields, the idea is the same. Add usp-hide-if-logged-in and make sure the field is not required. Here is an example, showing how to auto-hide a simple custom text field:

data-required#false|field_class#usp-hide-if-logged-in

Two things happening here: the first attribute sets the field to not required:

data-required#false

And then the second attribute sets the field to be hidden if/when the user is logged in to WordPress:

field_class#usp-hide-if-logged-in

Of course, you can add other attributes to further customize the field as needed. One of the strengths of USP Pro is the granular control and flexibility that it provides. Here is a post with complete information on Adding Custom Fields.

Important Note

To hide the fields for logged users, the plugin makes use of its default provided CSS styles. And these default styles were added in USP Pro 3.7. So that means if you are upgrading from a previous version of USP, and are not using the default provided styles, then you need to add the following line of CSS in order for auto-hiding to work.

.usp-hidden, .logged-in .usp-hide-if-logged-in { display: none; }

That line can be added via the plugin’s CSS settings (located under the “CSS/JS” tab) for whichever styles you are using. Or you can add via your theme stylesheet or any other suitable method.