Skip to:

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#6649 closed defect (bug) (fixed)

Compatibility with `WP_Hook`

Reported by: boonebgorges's profile boonebgorges Owned by: boonebgorges's profile boonebgorges
Milestone: 2.4 Priority: normal
Severity: normal Version:
Component: Core Keywords: has-patch dev-feedback needs-testing


See and especially

bp_get_template_stack() reaches into $wp_filter and operates on some nested arrays in situ. #WP17817 proposes that $wp_filter become an array of WP_Hook objects instead of multidimensional arrays. So things like foreach ( current( $wp_filter[ $tag ] ) ) become impossible, because $wp_filter[ $tag ] is a WP_Hook object. WP_Hook does implement ArrayAccess, so passing it to current() doesn't throw a fatal error. But WP_Hook stores callbacks in the callbacks property, which is a different structure than what bp_get_template_stack() expects.

jbrinley's recommendation is to assign the callback array (by reference) to a variable before operating on it, and to check if ( class_exists( 'WP_Hook' ) ) in order to figure out how to set that variable. I've confirmed that this works. It's also completely backward compatible. The only change is the use of a variable where previously we were operating directly on $wp_filter['bp_template_stack'].

The sooner we get this fix into BP, the sooner people will start upgrading to versions of BP that are WP_Hook-compatible. So I'm recommending that we go with the attached patch for 2.4.

Attachments (1)

6649.diff (1.3 KB) - added by boonebgorges 9 years ago.

Download all attachments as: .zip

Change History (6)

9 years ago

#1 @DJPaul
9 years ago

  • Keywords dev-feedback needs-testing added

#2 @r-a-y
9 years ago

I tested the patch briefly on a few BP plugins that rely on registering a template stack, without applying the WP_Hook patch from #WP17817 and everything still works well.

I say let's commit it for now and return to this once #WP17817 is sorted out.

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

9 years ago

#4 @boonebgorges
9 years ago

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

In 10279:

Support for WP_Hook in bp_get_template_stack().

The proposed WP_Hook #WP17817 breaks backward compatibility for plugins that
attempt to manipulate $wp_filter in certain ways. For BuddyPress, it means
that we cannot directly modify the callbacks that are currently registered as
an array at $wp_filter[ $tag ], in bp_get_template_stack(). Instead, when
WP_Hook is not available, we assign the callbacks to a variable (leveraging
WP_Hook's ArrayAccess) and manipulate the variable.

Props jbrinley.
Fixes #6649.

#5 @DJPaul
8 years ago

  • Component changed from API to Core
Note: See TracTickets for help on using tickets.