Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

#7516 closed defect (bug) (fixed)

bp_member_profile_data( 'field=Non existing fields' )

Reported by: seventhqueen's profile seventhqueen Owned by: r-a-y's profile r-a-y
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.7
Component: Members Keywords: has-patch
Cc:

Description

Hi, if you want to output a field that doesn't exist or the user hasn't yet completed you will get a PHP notice:
Notice: Undefined index: plugins/buddypress/bp-members/bp-members-template.php on line 1162

Attachments (1)

7516.01.patch (683 bytes) - added by r-a-y 7 years ago.

Download all attachments as: .zip

Change History (10)

#1 @tw2113
7 years ago

I can definitely see this happening, since this is the line in question:

$data = apply_filters( 'bp_get_member_profile_data_' . $profile_data[ $r['field'] ]['field_type'], $data, $r );

No isset checks at that point. Logically, in those cases, it's going to produce a filter name of bp_get_member_profile_data_ without anything after the trailing _

That said, it's hard to say if we want to try and default to a specific value or perhaps return early with a false value?

#2 @hnla
7 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from Awaiting Review to 2.9

Lets bring it in to 2.9 and get a second-opinion of fix then.

This ticket was mentioned in Slack in #buddypress by hnla. View the logs.


7 years ago

@r-a-y
7 years ago

#4 @r-a-y
7 years ago

  • Component changed from Core to Members
  • Keywords has-patch added; 2nd-opinion removed
  • Version set to 2.7

01.patch should fix this up.

#5 @r-a-y
7 years ago

  • Severity changed from major to normal

#6 @tw2113
7 years ago

Do we perhaps want to change it to have a filter of bp_get_member_profile_data by default and then conditionally append the rest?

$filter = 'bp_get_member_profile_data';
if ( ! empty( $profile_data[ $r['field'] ]['field_type'] ) ) { 
    $filter .= "_{$profile_data[ $r['field'] ]['field_type']}";
}
$data = apply_filters( $filter, $data, $r )

This way, it at least gets "bp_get_member_profile_data" available as a filter. Just a thought.

#7 @r-a-y
7 years ago

There's already a 'bp_get_member_profile_data' filter right above the dynamic one :)

#8 @tw2113
7 years ago

Ah, well played. I see nothing wrong with this then.

#9 @r-a-y
7 years ago

  • Owner set to r-a-y
  • Resolution set to fixed
  • Status changed from new to closed

In 11588:

Members: Avoid a notice if an invalid field is passed in bp_member_profile_data().

Props seventhqueen.

Fixes #7516.

Note: See TracTickets for help on using tickets.