Contents
Field Visibility Add-on gives you the possibility 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.
Activating the Field Visibility Add-on
Field Visibility is an Advanced add-on, available with a Profile Builder Basic or Pro license only.
After purchasing a premium version of Profile Builder, you can check the following guide on how to install Profile Builder.
For Field Visibility add-on to work as expected, you’ll also need to have the following plugin installed and activated on your site:
- Profile Builder Basic or Pro – version 2.0.8 or higher
Field Visibility Options
After we activate the Field Visibility Add-on we will see new options for our Extra Fields Types:
- Visibility – Admin Only field is visible only for administrators. User Locked field is visible for both administrators and users, but only administrators have the capability to edit it
- User Role Visibility – Select which user roles see this field
- Location Visibility – Select the locations you wish the field to appear
Visibility
We can set the Visibility option to:
- All – The field is seen by the Admin and also by the User
- Admin Only – The field is visible only by the Admin
- User Locked field – The field is visible for both the Admin and the User, but only the Admin has the capability to edit it
Setting Visibility to All
This 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.
Setting Visibility to Admin Only
This options 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.
Setting Visibility to User Locked
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.
User Role Visibility
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 thought 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.
Location Visibility
This option gives you the ability to show the field only in certain forms.
The available options are:
- All – Displays the field in WordPress Edit Profile Form (back-end), Register Forms Front-End and also in Edit Profile Forms Front-End
- WordPress Edit Profile Form (back-end) – This is the user profile that you can find by going to your Dashboard -> Users and then edit any user
- Register Forms Front-End – This represents all the Registration forms that are created with Profile Builder
- Edit Profile Forms Front-End – This represents all the Edit Profile forms created with Profile Builder
How to
Make a field User Locked only in the Edit Profile form
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /** * 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.
Get Field Visibility – Profile Builder Add-on
Profile Builder Pro
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.
Unlock PRO Features