Table of Contents
Field Visibility Add-on gives you the possibility to create User Locked fields or fields which are only visible to the Administrator, it also allows you to show/hide fields on certain forms and you can show/hide fields only for specific User Roles.
This allows you to have a single Edit Profile Form for multiple user roles, for example.
Field Visibility is an Advanced add-on, available with a Profile Builder Basic, Pro, or Agency license only.
After purchasing a premium version of Profile Builder, you can check the following guide on how to install Profile Builder.
For the Field Visibility add-on to work as expected, you’ll also need to have the following plugin installed and activated on your site:
After we activate the Field Visibility Add-on we will see new options for our Extra Fields Types:
We can set the Visibility option to:
This is the default option and it means that the User and the Admin can both see and edit the field. Inside the User Role Visibility option check “All” to display the field to logged out users.
This option means that the field is visible and editable only by Administrators. The values selected inside the User Role Visibility option will not overwrite the “Admin Only” option.
Admin Side
This is how the Admin sees the Registration form.
This is how the Admin sees the Edit Profile form.
This is how the Admin sees the WordPress Edit Profile form.
User Side
This is how the user sees the Registration form.
This is how the user sees the Edit Profile form.
This is how the user sees the WordPress Edit Profile form.
It means that the field is visible for both the Administrator and the User, but only the Administrator will be able to edit it. Check the “All” value inside the User Role Visibility option to display the user locked field to all the user roles.
Admin Side
This is how the Admin sees the Registration form.
This is how the Admin sees the Edit Profile form.
This is how the Admin sees the WordPress Edit Profile form.
User Side
This is how the user sees the Registration form.
This is how the user sees the Edit Profile form.
This is how the user sees the WordPress Edit Profile form.
This option gives you the ability to show/hide a field only for certain User Roles.
For example, you might have an Editor and a Subscriber user role, and you want them to be able to update their profile using the same Edit Profile page, but you are requesting different details about them upon registration.
This options allows you to show only the relevant fields to the Editor or Subscriber user roles, even though your form contains all the fields.
Inside the User Role Visibility option check “All” to display the field to logged out users. The values selected inside the User Role Visibility option will not overwrite the “Admin Only” option.
This option gives you the ability to show the field only in certain forms.
The available options are:
Lets say that we have a User Locked Select Field but we want to display this field in the Registration Form.
We want to let our users select a value inside the Select field but after the Registration we want this Select field to become a read only field inside the Edit Profile page.
Also, we want only the Admin to be able to modify the value displayed inside the Select Field.
Go to Profile Builder -> Manage Fields -> Add a Select Field and in the Visibility option choose User Locked and for the the User Role Visibility and Location Visibility check the “All” value.
Now you will need to use some custom code in order to make the Select Field User Locked only in the Edit Profile page:
1. Create an empty plugin like this: https://gist.github.com/sareiodata/76f701e01db6685829db
2. Add the following code to the end of it:
/**
* Checks to see if a user_locked field has values set when saving the form. It should not, and
* if it does an error is printed for that form, preventing the form values to be saved
*
*/
function wppbc_fv_check_if_user_locked( $message, $field, $request_data, $form_location, $form_role = '', $user_id = 0 ) {
// Handle visibility for register form
if( $form_location == 'register' ) {
// Visibility for User Locked option
if( !current_user_can( apply_filters( 'wppb_fv_capability_user_locked', 'manage_options' ) ) ) {
if (isset($field['visibility']) && ($field['visibility'] == 'user_locked')) {
remove_filter('wppb_check_form_field_' . WordPress_Creation_Kit_PB::wck_generate_slug( $field['field'] ), 'wppb_in_fv_check_field_value', 11);
remove_filter('wppb_check_form_field_' . WordPress_Creation_Kit_PB::wck_generate_slug( $field['field'] ), 'wppb_in_fv_check_if_user_locked', 11);
}
}
}
return $message;
}
function wppbc_init_field_visibility() {
if ( !defined('WPPBFV_IN_PLUGIN_DIR') ){
return;
}
$filter_fields = wppb_in_field_visibility_get_extra_fields();
// add filters for the fields
foreach( $filter_fields as $filter_field_slug => $filter_field ) {
if( class_exists('Wordpress_Creation_Kit_PB') ) {
add_filter('wppb_check_form_field_' . WordPress_Creation_Kit_PB::wck_generate_slug( $filter_field ), 'wppbc_fv_check_if_user_locked', 10, 6);
}
}
}
add_action( 'init', 'wppbc_init_field_visibility', 999 );
/*
* Make field visibility user locked on the Edit Profile page only
*/
add_filter( 'wppb_output_display_form_field', 'wppbc_handle_output_display_state', 999, 5 );
function wppbc_handle_output_display_state( $display_field, $field, $form_location, $form_role, $user_id ){
// Handle visibility for register form
if( $form_location == 'register' ) {
// Visibility for User Locked option
if( !current_user_can( apply_filters( 'wppb_fv_capability_user_locked', 'manage_options' ) ) ) {
if (isset($field['visibility']) && ($field['visibility'] == 'user_locked')) {
$display_field = true;
}
}
}
return $display_field;
}
3. Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality
This will work only in Front End and if users have access to the Back End they will be able to modify it. The Admin will be able to modify it in Front End.
Create beautiful front-end registration and profile forms with custom fields. Setup member directories, custom redirects, cutomize user emails & more using the all in one user management plugin.
Get Profile BuilderCombine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.
Get 25% off with the bundle