Skip to:
Content

Opened 2 months ago

Last modified 3 days ago

#7337 new defect (bug)

PHP Fatal error: Uncaught Error: Call to a member function get_do_autolink() on null

Reported by: slaFFik Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version:
Component: Extended Profile Keywords: dev-feedback has-patch 2nd-opinion
Cc:

Description

Got this error:

PHP Fatal error:  Uncaught Error: Call to a member function get_do_autolink() on null in wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-filters.php:344

in one of my plugins, when doing this:

$field_link = xprofile_filter_link_profile_data( $field_value, $field_data['type'] );

There is no $field; defined, using this function in ajax request.
I've fixed that in a plugin by defining the global with xprofile_get_field( $field_id ) in my loop, but shouldn't we consider checking the $field for not being null (or better instanceof BP_XProfile_Field) before using its method get_do_autolink()?

Attachments (1)

7337.patch (597 bytes) - added by slaFFik 6 weeks ago.
Add additional check

Download all attachments as: .zip

Change History (6)

#1 @slaFFik
2 months ago

  • Milestone changed from Awaiting Review to 2.8

@slaFFik
6 weeks ago

Add additional check

#2 @slaFFik
6 weeks ago

  • Keywords has-patch added

#3 @DJPaul
6 weeks ago

I ran into this while writing a unit test last week. While not ideal, the current function is written to be used inside the xprofile template loop. This patch just prevents a fatal error when it's used wrong; it doesn't make the function usable outside the template loop. And that's what the function ought to be changed for, if we're going to change it at all.

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


6 weeks ago

#5 @DJPaul
3 days ago

  • Keywords 2nd-opinion added

I'm not convinced that this is a worthwhile change. Opinions?

Note: See TracTickets for help on using tickets.