tags:

views:

120

answers:

1

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 being 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.

A: 

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.

scompt.com
I did trace my way through this but for some reason the wp_filter_id gets left off the end and therefore the has_filter returns false.
Littlejon
What are the contents of the $wp_filters array?
scompt.com
That array holds the master list of filters and actions. Including references to the objects and functions to perform those filters.So under $wp_filters[$tag][$priority][test_pluginwp_list_pages4]It is the test_pluginwp_list_pages4 that _wp_filter_build_unique_id is supposed to return but for some reason it only returns test_pluginwp_list_pages without the number on the end. Which in turn causes has_filter to not be able to find the item in the $wp_filter list.I have found a way around my current problem but it is certainly not an elegant solution and is waiting to be broken :-)
Littlejon