[buddypress-trac] [BuddyPress Trac] #8189: buddypress-xprofile-rich-text-field (PHP 7+ warnings) - variable checking needs to be done

buddypress-trac noreply at wordpress.org
Tue Jan 7 20:19:53 UTC 2020


#8189: buddypress-xprofile-rich-text-field (PHP 7+ warnings) - variable checking
needs to be done
------------------------------+-----------------------------
 Reporter:  theZman           |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Extended Profile  |    Version:
 Severity:  normal            |   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 =============
 {{{#!php
 <?php
 //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 =============

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/8189>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list