Dynamic addFilter Display in a Hook


I want to create a new plugin.
I search to use the dynamic filter function (addFilter).

When I use this in SetUp function it works but not in a hook.

protected $_hooks = array(

public function maFonction($text, $args)
return ''.$text.'';

public function hookConfigForm()
require 'config-form.php';

public function setUp(){
//add_filter(array('Display', 'Item', 'Dublin Core', 'Description'), array($this,'maFonction'));
add_filter(array('Display', 'Item', 'Dublin Core', 'Title'), array($this,'maFonction'));//it works.

public function hookConfig()
add_filter(array('Display', 'Item', 'Dublin Core', 'Description'), array($this,'maFonction'));//doesn't work.
set_option('text_test', trim($_POST['text_test']));

Can you help me please ?



Are you sure you really want to be adding that filter in hookConfig? I don't know what you're trying to do, but it doesn't really make sense to add a filter for displaying the Description element in that hook.

hookConfig is only going to fire and do anything on the plugin's configuration page (and even then, only when saving the configuration, not when showing the form).

I wanted to add news filters
according to the parameters in configuration page.

To do something like that, you'll need to save the settings from the configuration form, either as an option or options, or in your own database table (the option route is much simpler).

Then you'd use something like the "initialize" hook which will run on every page load, read out your saved options, and create the appropriate filters. The way you're doing it now only creates them during a page load that doesn't ever display anything, so the filter's never used.

Thank you for your advices. I'll look at it.