BuddyDev

Search

Make the BP Non Editable Profile Fields Truly Non Editable

  • Participant
    Level: Initiated
    Posts: 3
    sheryanne on #11312

    Hi. The plugin ‘BP Non Editable Profile Fields’ allows the user to make a selection only one time, then afterwards it is non-editable. How can I set up a field that is non-editable by the user at all. Change can only be made in the admin panel.

    Thanks!

  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #11322

    Hi Sheryanne,
    There seems to be a plugin that does admin only BuddyPress field
    https://wordpress.org/plugins/buddypress-admin-only-profile-fields/

    If that Brajeshdoes not serve your purpose, please do let me know and I will be willing to put something in place.

    Regards

  • Participant
    Level: Initiated
    Posts: 3
    sheryanne on #11333

    Hi there! Thank you for responding. I had hopes for the plugin you suggested, but it hides the field from front-end view. I would like the field to be visible, just not editable by the user.

    (If it helps to know how we are using this… this is for a homeowner’s association. One Profile Field is radio button selection to show the Membership Type, we want to show what kind of member the person is. But this should not be chosen by the user, only the Admin can make the selection. The selections are… Non-Voting Member, Voting Member, Board Member, President, Vice President, etc.. and these positions change all the time. When someone registers, we want “Non-Voting Member” to be the default choice that displays on the front-end until it’s time to promote the person.)

    Right now the default is chosen, but the user is allowed to change it one time. And the field will not appear on the profile until the user “saves” first. Is it possible to have the field appear in the profile immediately when the user logs in for the first time and then cannot be changed by the user, only the Admin? Would it help to give you access?

    Thanks again 🙂

  • Participant
    Level: Initiated
    Posts: 3
    sheryanne on #11395

    I’m ok, nevermind. I found a snippet on the buddypress forums that will hide the profile field from the user’s edit screen but it still appears on their profile page. I added it to bp-custom.php and it’s working. I am only using the first part that says “remove field from edit tab”. Here’s the code – maybe you can include it on a future update?

    function bpfr_hide_profile_edit( $retval ) {
    // remove field from edit tab
    if( bp_is_profile_edit() ) {
    $retval[‘exclude_fields’] = ‘2’; // field ID’s separated by comma
    }
    // allow field on register page
    if ( bp_is_register_page() ) {
    $retval[‘include_fields’] = ‘2’; // field ID’s separated by comma
    }

    // hide the field on profile view tab
    if ( $data = bp_get_profile_field_data( ‘field=2’ ) ) :
    $retval[‘exclude_fields’] = ‘2’; // field ID’s separated by comma
    endif;

    return $retval;
    }
    add_filter( ‘bp_after_has_profile_parse_args’, ‘bpfr_hide_profile_edit’ );

  • Participant
    Level: Initiated
    Posts: 2
    Joel of MMCC on #27934

    The code posted in @sheryanne’s #11395 above was apparently edited in an editor designed for text posting, not code, or else the forum software here did this, but it converted the straight single quotes into “curly” ‘single quotes.’ This of course does not make for valid PHP code!

    Here it is as a code block that will hopefully not try to “prettify” the quotes:

    function bpfr_hide_profile_edit( $retval ) {
    
      // remove field from edit tab
       if ( bp_is_profile_edit() ) {
         $retval['exclude_fields'] = '2'; // field IDs separated by comma
       }
    
      // allow field on register page
      if ( bp_is_register_page() ) {
        $retval['include_fields'] = '2'; // field IDs separated by comma
      }
    
      // hide the field on profile view tab
      if ( $data = bp_get_profile_field_data( ‘field=2’ ) ) :  /// Joel MMCC: Does this also need to be changed, and if so, how for multiple fields?
        $retval['exclude_fields'] = '2'; // field ID’s separated by comma
      endif;
    
    return $retval;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_edit' );
  • Participant
    Level: Initiated
    Posts: 2
    Joel of MMCC on #27938

    Ooops! Turns out the code above uses a deprecated function as of BuddyPress 1.5.

    bp_is_profile_edit should be bp_is_user_profile_edit (apparently to distinguish between user front-end and admin dashboard back-end versions of the XProfile edit page).

    Updated code block:

    function bpfr_hide_profile_edit( $retval ) {
    
      // remove field from edit tab
       if ( bp_is_user_profile_edit() ) {
         $retval['exclude_fields'] = '2'; // field IDs separated by comma
       }
    
      // allow field on register page
      if ( bp_is_register_page() ) {
        $retval['include_fields'] = '2'; // field IDs separated by comma
      }
    
      // hide the field on profile view tab
      if ( $data = bp_get_profile_field_data( ‘field=2’ ) ) :  /// Joel MMCC: Does this also need to be changed, and if so, how for multiple fields?
        $retval['exclude_fields'] = '2'; // field IDs separated by comma
      endif;
    
    return $retval;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_edit' );
  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #27939

    Hi Joel,
    Welcome to BuddyDev.

    Thank you for sharing and updating the code.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved