最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - add_filter : Passing an array instead of the callback function?

programmeradmin2浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论