Skip to:

Opened 5 months ago

Last modified 2 months 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.9 Priority: normal
Severity: normal Version:
Component: Extended Profile Keywords: dev-feedback, has-patch, 2nd-opinion, early


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 4 months ago.
Add additional check

Download all attachments as: .zip

Change History (7)

#1 @slaFFik
5 months ago

  • Milestone changed from Awaiting Review to 2.8

4 months ago

Add additional check

#2 @slaFFik
4 months ago

  • Keywords has-patch added

#3 @DJPaul
4 months 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.

3 months ago

#5 @DJPaul
2 months ago

  • Keywords 2nd-opinion added

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

#6 @DJPaul
2 months ago

  • Keywords early added
  • Milestone changed from 2.8 to 2.9
Note: See TracTickets for help on using tickets.