Handling Empty and Array returns from bp_get_profile_field_data

Home Forums Legacy Support Support queries Other issues Handling Empty and Array returns from bp_get_profile_field_data

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #48599
    eclipsedev
    Spectator
    Hello, Wanted to flag an issue with the implementation of the bp_get_profile_field_data function throughout the theme and your plugins. There's potential for a 'false' return from this function which should be intercepted as an empty string for echo'ing; if (empty($response)) $response = ''; You'll also want to handle arrays as the user can decide to choose a multi-select as their instructor_field or student_field option. This can be done by either selecting the first array item or imploding the array into comma-seperated list. Below are examples or each approach; First Item; echo '<span>'.bp_get_profile_field_data( array('user_id'=>$user_id,'field'=>$field ))[0].'</span>'; Comma List; echo '<span>'.implode(", ", bp_get_profile_field_data( array('user_id'=>$user_id,'field'=>$field ))).'</span>'; Note: The bp_get_profile_field_data doesn't support $multi_format argument as the xprofile_get_field_data which is called does. I've put in a trac ticket concerning this, but for the meantime will need to utilize implode to create a comma separated list. Trac Ticket - https://buddypress.trac.wordpress.org/ticket/7068#ticket Cheers
    #48705
    Anshuman Sahu
    Keymaster
    Thanks for sharing this information we will try to add this feature in the next update of wplms .
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Handling Empty and Array returns from bp_get_profile_field_data’ is closed to new replies.