0

I was just reading through BuddyPress code because I want to develop a custom plugin on top of it. I encountered was something very peculiar that I haven't seen before and cannot seem to find any material on.

The following code is from a protected function under a class named as BP_Legacy

// Filter BuddyPress template hierarchy and look for page templates.

add_filter( 'bp_get_buddypress_template', array( $this, 
'theme_compat_page_templates' ), 10, 1 );

As far as I know, the syntax for add_filter is something like

add_hilter ('hook_name', 'callback_function', $priority, $number_of_arguments)

How is it that an array has been passed instead of the callback function? How exactly would this line of code run?

1

You can pass as the callback argument anything which is callable by PHP definition, something that might actually change between PHP versions.

In this specific case the array($o,$m) type of notation indicates that the filter will call $o->$m

  • Hey thanks for the reply but if I may ask, how did you logically conclude that array($o, $m) will result in the filter calling $o->$m . Is this how add_filter works when an array is passed ? – Ram Iyer May 19 '17 at 11:03
  • no, that is how you generally do a callable for a method of an object in PHP – Mark Kaplun May 19 '17 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.