Skip to:
Content

Opened 13 months ago

Closed 4 months ago

#7337 closed defect (bug) (wontfix)

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

Reported by: slaFFik Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Extended Profile Keywords: dev-feedback 2nd-opinion early needs-patch
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 11 months ago.
Add additional check

Download all attachments as: .zip

Change History (13)

#1 @slaFFik
13 months ago

  • Milestone changed from Awaiting Review to 2.8

@slaFFik
11 months ago

Add additional check

#2 @slaFFik
11 months ago

  • Keywords has-patch added

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


11 months ago

#5 @DJPaul
10 months ago

  • Keywords 2nd-opinion added

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

#6 @DJPaul
10 months ago

  • Keywords early added
  • Milestone changed from 2.8 to 2.9

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


8 months ago

#8 @r-a-y
8 months ago

  • Keywords needs-patch added; has-patch removed

I agree with Paul. The current patch doesn't change how the xprofile_filter_link_profile_data() function works.

@slaFFik - I would rework the patch so we add a third parameter - $field_id - to xprofile_filter_link_profile_data(). This is so the 'bp_get_the_profile_field_value' filter will continue to work as-is.

Then instead of looking at the $field global in the xprofile_filter_link_profile_data() function, we do $field = xprofile_get_field( $field_id );.

Then in your custom AJAX call, you could do this:
xprofile_filter_link_profile_data( $field_value, $field_data['type'], $field_id )

#9 @r-a-y
5 months ago

  • Milestone changed from 2.9 to Awaiting Review

Bumping back to Awaiting Review.

#10 @DJPaul
5 months ago

Still unconvinced. Adapting a template loop function to be used outside seems against the design intent of those functions.

#11 @r-a-y
5 months ago

I'm not convinced either, but do we want to safeguard the function from being used outside the xprofile loop?

If so, the current patch or a variation of it could be done (like empty( $GLOBALS['field'] )).

#12 @DJPaul
4 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Let's not do this.

Note: See TracTickets for help on using tickets.