#7580 closed defect (bug) (no action required)
PHP Warning: Illegal offset type in wp-content/plugins/buddypress/bp-activity/bp-activity-functions.php on line 734
| Reported by: | magland | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | Activity | Version: | |
| Severity: | minor | Keywords: | reporter-feedback |
| Cc: |
Description
PHP Warning: Illegal offset type in wp-content/plugins/buddypress/bp-activity/bp-activity-functions.php on line 734
I believe there is a syntax error in the below function causing the above PHP warning.
<?php function bp_activity_post_type_get_tracking_arg( $activity_type, $arg = '' ) { if ( empty( $activity_type ) || empty( $arg ) ) { return false; } $bp = buddypress(); // Set the activity track global if not set yet if ( empty( $bp->activity->track ) ) { $bp->activity->track = bp_activity_get_post_types_tracking_args(); } if ( isset( $bp->activity->track[ $activity_type ]->{$arg} ) ) { return $bp->activity->track[ $activity_type ]->{$arg}; } else { return false; } }
$activity_type is an array not a string so the square brackets look to be in the wrong place. Suggested fix below:
<?php function bp_activity_post_type_get_tracking_arg( $activity_type, $arg = '' ) { if ( empty( $activity_type ) || empty( $arg ) ) { return false; } $bp = buddypress(); // Set the activity track global if not set yet if ( empty( $bp->activity->track ) ) { $bp->activity->track = bp_activity_get_post_types_tracking_args(); } if ( isset( $bp->activity->track[ $activity_type->{$arg}] ) ) { return $bp->activity->track[ $activity_type->{$arg}]; } else { return false; } }
Change History (4)
#2
@
9 years ago
- Keywords needs-patch removed
- Milestone Under Consideration
- Resolution → invalid
- Status new → closed
- Version 2.9.0
$activity_type is not meant to be an array. The PHPDoc states $activity_type is meant to be a string.
DJPaul is correct that it is probably a plugin causing the notices, as internally, we do not pass $activity_type as an array.
Feel free to keep commenting, but going to close as invalid for now.
#3
@
9 years ago
Hi I believe it may be due to the fact I am filtering activity types out of the sitewide activity with the following code:
<?php function my_custom_bp_activity_types( $retval ) { // only filter stuff from the main timeline... if( ! bp_is_activity_directory()) { return $retval; } // get all registered activity types including custom ones $allArray = bp_activity_get_types(); $allKeys = array(); foreach($allArray as $key => $value) { array_push($allKeys, $key); } // an array of things we want to exclude $excludeArray = array( 'new_member', 'new_avatar', 'updated_profile', 'friendship_accepted', 'friendship_created', 'joined_group', 'compliment_sent', 'compliment_received' ); // remove the array we want to exclude using array_diff $diff = array_diff($allKeys, $excludeArray); // set the action to our new $diff array $retval['action'] = $diff; // make sure to return it! return $retval; } add_filter( 'bp_after_has_activities_parse_args', 'my_custom_bp_activity_types' );
with that filter in place I get an array of allowed activity types returned if I do this:
<?php function bp_activity_post_type_get_tracking_arg( $activity_type, $arg = '' ) { print '<pre>'; print_r($activity_type); print '</pre>'; exit;
Any pointers on how to resolve?
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Were you able to figure out what URL is triggering these errors?
Do you have any plugins (that integrate with BuddyPress) installed, or bespoke changes to the Activity component?