Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#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's profile magland Owned by:
Milestone: Priority: low
Severity: minor Version:
Component: Activity 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)

#1 @DJPaul
7 years ago

  • Keywords reporter-feedback added
  • Milestone changed from Awaiting Review to Under Consideration

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?

#2 @r-a-y
7 years ago

  • Keywords needs-patch removed
  • Milestone Under Consideration deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 2.9.0 deleted

$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 @magland
7 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?

#4 @atmojones
7 years ago

@magland Have you tried passing the values as a comma separated string rather than an array?

Note: See TracTickets for help on using tickets.