Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Contributor Garrett Hyder

    (@garrett-eclipse)

    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

    Thread Starter Orios

    (@orios)

    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 anyway

    Plugin Contributor Garrett Hyder

    (@garrett-eclipse)

    No 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

    Thread Starter Orios

    (@orios)

    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.

    Plugin Contributor Garrett Hyder

    (@garrett-eclipse)

    Awesome @orios,

    Please share so future users who stumble on the thread can follow your lead.

    Thanks

    Thread Starter Orios

    (@orios)

    I used the ‘Extending BuddyPress profile field visibility’ code from Brajesh Singh. See https://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 at

    Thread Starter Orios

    (@orios)

    Thread Starter Orios

    (@orios)

    Ah, link doesn’t show. Here in full https://github.com/IChess1/WPI/tree/master

    Thread Starter Orios

    (@orios)

    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

    Plugin Contributor Garrett Hyder

    (@garrett-eclipse)

    Thanks for sharing @orios, nice work.

    What is the appropriate id for Subscriber, Author, and Editor?

    Plugin Contributor Garrett Hyder

    (@garrett-eclipse)

    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#L651

    Hope that helps,
    Cheers

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Show fields for specific user roles’ is closed to new replies.