Skip to:
Content

BuddyPress.org

Opened 14 months ago

Closed 13 months ago

Last modified 13 months ago

#9010 closed defect (bug) (fixed)

PHP Fatal error: Uncaught TypeError: Illegal offset type in /buddypress/bp-activity/bp-activity-functions.php:798

Reported by: btwebdesign's profile btwebdesign Owned by: imath's profile imath
Milestone: 12.0.0 Priority: normal
Severity: normal Version: 11.3.2
Component: Activity Keywords: has-patch has-unit-tests
Cc: info@…

Description

PHP Fatal error: Uncaught TypeError: Illegal offset type in /html/wordpress/wp-content/plugins/buddypress/bp-activity/bp-activity-functions.php:798

Error:
if ( isset( $bp->activity->track[ $activity_type ]->{$arg} ) ) {

return $bp->activity->track[ $activity_type ]->{$arg};

Solution (wrong set ]-brackets):
if ( isset( $bp->activity->track[ $activity_type ->{$arg}] ) ) {

return $bp->activity->track[ $activity_type ->{$arg}];

Buddpress Version 11.3.2 and several older versions

Change History (11)

#1 @imath
14 months ago

Hi @btwebdesign

Thanks for your report, I’ll look at it asap.

#2 @imath
14 months ago

  • Keywords reporter-feedback added; changes-requested removed

I can't reproduce using PHP 8.2, could you give me more information, like:

  • what's the value of $activity_type and $arg when you get this error ?
  • what's your PHP version ?

Thanks in advance.

#3 @btwebdesign
14 months ago

Hi,

these are the desired data:

[24-Oct-2023 19:53:43 UTC] function bp_activity_post_type_get_tracking_arg
[24-Oct-2023 19:53:43 UTC] activity_type:
[24-Oct-2023 19:53:43 UTC] Array
(

[0] => activity_comment
[1] => activity_update
[2] => friendship_created
[3] => created_group
[4] => joined_group
[5] => last_activity
[6] => new_avatar
[7] => new_member
[8] => updated_profile

)

[24-Oct-2023 19:53:43 UTC] arg:
[24-Oct-2023 19:53:43 UTC] post_type

PHP Version: 8.0.29

The error looks something like this:
https://buddypress.trac.wordpress.org/ticket/7580

Many thanks and kind regards

#4 @imath
13 months ago

  • Resolution set to fixed
  • Status changed from new to closed

Hi @btwebdesign

Thanks for providing these details and the link to the ticket. In BuddyPress Core we're always using bp_activity_post_type_get_tracking_arg() with the right $activity_type argument type. I imagine this error is due to a misusage of a BuddyPress filter or of this function. In #7580 we chose to leave this as is for this reason. You can probably debug backtrace the plugin or the custom code which is responsible for this error.

#5 @imath
13 months ago

  • Milestone 11.4.0 deleted

#6 @imath
13 months ago

  • Keywords needs-testing added; reporter-feedback removed
  • Milestone set to 11.5.0
  • Resolution fixed deleted
  • Status changed from closed to reopened

#7 @imath
13 months ago

  • Keywords needs-patch added; needs-testing removed

After looking more into it. This can only happen when a plugin or some custom code is filtering the bp_has_activities() action argument and returns an array of activity actions (or types).

Here's an example of such a filter.

function my_custom_bp_activity_types( $args ) {
	$args['action'] = array( 'new_blog_post', 'new_blog_comment' );
	return $args;
}
add_filter( 'bp_after_has_activities_parse_args', 'my_custom_bp_activity_types', 1 );

Although it cannot be caused by BuddyPress itself and doesn't seem to be on us to fix this at first sight, when we look at the inline comment for the bp_has_activities() function we wrote:

 *     @type string|array|bool $action           Filters by the `type` column in the database, which is a string
 *                                               categorizing the activity item (eg, 'new_blog_post', 'created_group').
 *                                               Accepts a comma-delimited string or an array of types. Default: false.
 

Meaning we support passing an array of activity types. So we need to fix it, and we'll do!

#8 @imath
13 months ago

  • Milestone changed from 11.5.0 to 12.0.0

As this was preexisting to branch 11.0, moving this to 12.0 milestone.

This ticket was mentioned in PR #190 on buddypress/buddypress by @imath.


13 months ago
#9

  • Keywords has-patch has-unit-tests added; needs-patch removed

Make sure the bp_blogs_new_blog_comment_query_backpat() doesn't generate an error when an array of activity actions is requested by the activity loop.

Trac ticket: https://buddypress.trac.wordpress.org/ticket/9010

#10 @imath
13 months ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from reopened to closed

In 13642:

Make Activity loop reliable when post & activity comments are synced

As the $action key of the bp_has_activities() function arguments array accepts a string, a boolean as well as an array, we need to make sure the bp_blogs_new_blog_comment_query_backpat() function doesn't trigger an error when an array of activity type is passed.

Props btwebdesign, magland, teeboy4real

Fixes #9010
Closes https://github.com/buddypress/buddypress/pull/190

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


13 months ago

Note: See TracTickets for help on using tickets.