Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to make certain profile fields editable by admin only?

  • Avatar of Brendino
    Brendino
    Participant

    @brendino

    WP 3.5.1, BP 1.7-beta1.

    I’m working on a BP network for my company and there are some fields that users don’t need to edit themselves (branch they work at, date of hire, etc.), but I still want them to be visible in the profile.

    From what I’ve read, this kind of functionality isn’t available out of the box. BP 1.7 adds fields that can be edited by the user and viewed only by admins, but I want the opposite: edited only by admins but can be viewed by anyone (well, anyone who’s logged in).

    Two questions. Would this be a good feature to request? And if I were to attempt to make a plugin, could someone point me in the right direction? What things do I need to hook into to make that happen? (I’m a designer not a programmer, so basic steps to start would be helpful!)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Avatar of jimmy140
    jimmy140
    Participant

    @jimmy140

    @Brendino,

    Looking to accomplish the same thing! I haven’t been able to find any good solutions either. If you come up with something please post!

    Jimmy

    Avatar of azchipka
    azchipka
    Participant

    @azchipka

    Ok so I managed to find a backwards way of doing it because I needed to be able to do the same thing. Your going to need two plugins.

    1. Your Preferred Role Management Plugin. I like Capacity Manager Enhanced
    2. Buddypress xProfiles ACL

    STEPS
    1. Use your role manager to create some new roles. Name them what ever you want.
    2. Go into the Users -> Profile Fields
    3. Create a Field Group for your Restricted Items (not the primary one).
    4. Go to the Settings -> xProfile ACL
    5. Put your Field Group that you only want the Admin to be able to edit for the admin only.
    6. Now this is important you need to modify the xProfile ACL php file (yes I know this makes it a hack, if xProfile ACL is updated you will lose this setting.)
    6a. Go to line 240 of the buddypress-xprofiles-acl.php file. Comment out lines 240 – 249, the code you are commenting out is:

    `
    function filter_xprofile_groups_with_acl() {
    global $bp, $profile_template, $current_user;
    get_currentuserinfo();
    foreach($profile_template->groups as $key => $profile_group) {
    if( ! in_array($profile_group->id, $this->user_allowed_xprofile_groups) ) {
    unset($profile_template->groups[$key]);
    }
    }
    }
    `

    6b. Below the code you just commented out add:
    ` function filter_xprofile_groups_with_acl() {}`

    7. Save your changes to the buddypress-xprofiles-acl.php file.

    8. Now when ever you need to modify the fields log in with your admin account navigate to the user profile in buddy press and select Edit Member Profile from the tool bar. You will see the fields from the private group. Users will see the fields but when they select edit they will not be displayed.

    Hope this helps.

    Avatar of theflyingkitty
    theflyingkitty
    Participant

    @theflyingkitty

    azchipka, would you happen to have a copy maybe of the file you edited?

    Maybe they changed the scripts in the last three months, but following directions exactly and it keeps giving me a fatal error.

    Avatar of theflyingkitty
    theflyingkitty
    Participant

    @theflyingkitty

       <?php
      }
      /*EDIT*/
      
      function filter_xprofile_groups_with_acl() {
        global $bp, $profile_template, $current_user;
        get_currentuserinfo();
        foreach($profile_template->groups as $key => $profile_group) {
          if( ! in_array($profile_group->id, $this->user_allowed_xprofile_groups) ) {
            unset($profile_template->groups[$key]);
          }
        }
      }
      /*EDIT*/
      function filter_xprofile_groups_with_acl() {}
      function block_screen_edit_profile() {
Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.