Opened 8 years ago
Closed 7 years 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)
Change History (13)
#3
@
8 years 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.
8 years ago
#5
@
8 years ago
- Keywords 2nd-opinion added
I'm not convinced that this is a worthwhile change. Opinions?
This ticket was mentioned in Slack in #buddypress by hnla. View the logs.
7 years ago
#8
@
7 years 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 )
#10
@
7 years ago
Still unconvinced. Adapting a template loop function to be used outside seems against the design intent of those functions.
Add additional check