BuddyDev

Search

Replies

  • 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' );
  • 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' );