Show fields for specific user roles
-
Thanks for this promissing plugin.
Actually i’m looking for a way to show/hide profile fields for some specific user roles.
Could this plugin be customized to do this and how?https://ww.wp.xz.cn/plugins/buddypress-admin-only-profile-fields/
-
Hi @orios,
For sure you can definitely do this, might want to fork the plugin to apply your customizations.
You’ll need to handle this in two steps;
1. Add Custom Visibility Levels for your roles in custom_visibility_levels function on line 143.$levels['adminedit'] = array( 'id' => 'adminedit', 'label' => __( 'Admin Editable', 'bp_admin_only_profile_fields' ) );Give it an appropriate id and label.
2. Tie into the logic of the append_hidden_level function on line 173
Basically will want to add the custom visibility level from step #1 here into the logic so that it’s added to the $hidden_levels array when the user shouldn’t have access to it.Hope that makes sense, step #2 is a bit complicated took me a bit to wrap my head about it as the logic is reverse to what’s intuitive.
If you create a fork share it here and I can help with your customization.
Cheers
Thank you very much for your reply.
Unfortunatelly i’m not much of a programmer and thus will not be able to acomplish this.
Thanks anywayNo worries @orios,
I’d be happy to assist you with your customization on a freelance basis, you can contact me at nightbook [dot] g [dot] hyder [at] gmail [dot] com.
Cheers
Thanks for the offer.
I will keep this in mind for future issues.
For the time being, i did manage to solve the issue with a slight customization of another plugin.I used the ‘Extending BuddyPress profile field visibility’ code from Brajesh Singh. See http://buddydev.com/buddypress/extending-buddypress-profile-field-visibility/.
And altered it a bit to hide on user roles (pmpro_role_1 and pmpro_role2)
For the entire code see extended-xprofile-field-visibility-levels.php atAh, link doesn’t show. Here in full https://github.com/IChess1/WPI/tree/master
First I added the custom visiblity fields
$allowed_visibilities[‘pmpro_role_1’] = array(
‘id’ => ‘pmpro_role_1’,
‘label’ => _x( ‘Gratis leden’, ‘Visibility level setting’, ‘bp-extended-profile-visibility’ )
);
$allowed_visibilities[‘pmpro_role_2’] = array(
‘id’ => ‘pmpro_role_2’,
‘label’ => _x( ‘Premium leden’, ‘Visibility level setting’, ‘bp-extended-profile-visibility’ )
);And then the rules
if( ( $displayed_user_id != $current_user_id ) && ! current_user_can(‘pmpro_role_1’) && ! is_super_admin() ) {
$hidden_levels[] = ‘pmpro_role_1’; //profile field with this privacy level will be hidden for the user
}
if( ( $displayed_user_id != $current_user_id ) && ! current_user_can(‘pmpro_role_2’) && ! is_super_admin() ) {$hidden_levels[] = ‘pmpro_role_2’; //profile field with this privacy level will be hidden for the user
}et voila, it worked just fine
Thanks for sharing @orios, nice work.
What is the appropriate id for Subscriber, Author, and Editor?
Hi @assal0le,
The WordPress default roles and their ids are as follows;
add_role(‘administrator’, ‘Administrator’);
add_role(‘editor’, ‘Editor’);
add_role(‘author’, ‘Author’);
add_role(‘contributor’, ‘Contributor’);
add_role(‘subscriber’, ‘Subscriber’);
Reference – https://github.com/WordPress/WordPress/blob/703d5bdc8deb17781e9c6d8f0dd7e2c6b6353885/wp-admin/includes/schema.php#L651Hope that helps,
Cheers
The topic ‘Show fields for specific user roles’ is closed to new replies.