Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide profile fields from editing for specific users


  • olandir
    Participant

    @olandir

    I have a corporate Intranet running on WordPress 4.9.8 and BuddyPress 3.1.0

    I have specific xprofile fields that I’d like only editable to people who have the “Edit Users” capability.

    I’ve seen snippets of code here or there that almost do what I’m looking for but everything I’ve found is old and out of date.

    Could someone help me with this.

    Basically I need the PHP equivalent of

    If we’re on the edit BuddyPress profile page AND user does not have the “edit users” capability then hide profile fields with X id(s).

    I’d also be happy with specifying a role instead of capability as long as I can specify multiple role ids.

    Thank you in advance.

Viewing 4 replies - 1 through 4 (of 4 total)

  • Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    Please try this plugin https://wordpress.org/plugins/buddypress-admin-only-profile-fields/

    The UI is changed now so you will find the option in visibility drop-down.

    Thanks


    olandir
    Participant

    @olandir

    I don’t want it to be only Admins. This description talks about only admins being able to see the field.


    Prashant Singh
    Participant

    @prashantvatsh

    function ps_hide_profile_edit( $retval ) {	
    	// remove field from edit tab
    	if(  bp_is_user_profile_edit() && !current_user_can('edit_users')) {	
    		$retval['exclude_fields'] = 'field_id'; // ID's separated by comma
    	}	
    	// allow field on register page
    	if ( bp_is_register_page() ) {
    		$retval['include_fields'] = 'field_id'; // ID's separated by comma
    	}		
    	
    	return $retval;	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'ps_hide_profile_edit' );

    Please try this snippet.

    Thanks


    namyang
    Participant

    @namyang

    What file should this snippet go in?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar