admin管理员组

文章数量:1410724

I was just reading through BuddyPress code because I want to develop a custom plugin on top of it. I encountered 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 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_filter ('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?

I was just reading through BuddyPress code because I want to develop a custom plugin on top of it. I encountered 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 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_filter ('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?

Share Improve this question edited Jan 21, 2020 at 22:57 davemackey 3152 silver badges18 bronze badges asked May 19, 2017 at 7:17 Ram IyerRam Iyer 331 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

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

本文标签: plugin developmentaddfilterPassing an array instead of the callback function