开发者

Howto use the has_filter wordpress function with an object based callback

I have several plugins, all of which are based on using objects to hold the plugin.

In one plugin class named "test_plugin" I have:

apply_filter('wp_list_pages', array(&$this, 'wp_list_pages'));

I would like to use the has_filter function in one plugin to try to detect the presence of the other plugin.

I cant find any examples of the has_filter function bei开发者_JAVA百科ng used with an object based callback.

I have tried:

has_filter('wp_list_pages', array('test_plugin', 'wp_list_pages'));

But this only returns false. I have written some debugging output to display the contents of the $wp_filters global variable and the callback is definitely registered in the $wp_filters array.


Take a look at the _wp_filter_build_unique_id function defined at the bottom of wp-includes/plugin.php. That's where the array key for $wp_filters is generated. It looks like it does something like this for your case:

$obj_idx = get_class($this).'wp_list_pages';

and then appends an integer to the end of that to make sure it's unique. That integer is also added to a field called wp_filter_id on your object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜