Skip to:

Opened 14 months ago

Last modified 14 months ago

#8189 new defect (bug)

buddypress-xprofile-rich-text-field (PHP 7+ warnings) - variable checking needs to be done

Reported by: theZman Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Extended Profile Keywords: needs-patch


File: buddypress-xprofile-rich-text-field.php

Problem: slows down sites with many profile fields and fill up logging with warnings. (For example, a site with 50+ custom profile fields of varying types is a big problem.)

PHP warning:
Trying to get property 'field_id' of non-object in wp-content/plugins/bp-xprofile-rich-text-field/buddypress-xprofile-rich-text-field.php on line 190

To fix line 190 better variable checking needs to be done since this function hooks into EVERY single xprofile_get_field_data() call and does not consider that sometimes an ID is passed instead of an object.

============ PATCH =============

//check if this is an object or a number to prevent PHP 7 warnings
if(is_object( $data_obj)) { $field_id =  $data_obj->field_id;}
if(!is_object( $data_obj) && is_numeric($data_obj)) { $field_id =  $data_obj;}

// THEN get field from data object
$field = new BP_XProfile_Field( $field_id);

// if this isn't our field, skip amending allowed tags
if ( $field->type != 'richtext' ) { return $allowedtags;  }

============ END PATCH =============

Change History (1)

#1 @imath
14 months ago

Thanks a lot for your feedback @theZman I'll look at it asap.

Note: See TracTickets for help on using tickets.