Support » Plugins » Hacks » custom filter action not being called

  • I’m trying to write a plugin that uses a custom filter hook and I cannot seem to get it to work. It’s been a while since I’ve written any plugin code, but as far as I can tell I’m doing all the right things, so I can’t figure out what’s wrong. Hopefully someone here can help me out.

    It’s also quite possible that I’m doing it wrong from a PHP perspective.

    In order not to clutter the post I’ve posted pseudocode as a gist at but essentially I’m calling apply_filter with a hook name and hooking into it in a static method on another class. As far as I can tell (via logging to a text file) the startup/filter hooking code is working properly, but my filter handler’s not ever being called.

    Thanks in advance for any suggestions!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Disclosure: I don’t use classes in my plugins, but isn’t the correct way to call add_filter with a class:

    add_filter( $tag, array( & $this, $my_method_goes_here ) );

    and you call it via apply_filters() plural and not apply_filter() singular. I believe you’re using the latter.

    Thanks bcwp; I’m trying to call the function statically, so I don’t have a $this to reference.

    You’re right about the apply_filters spelling, but unfortunately that was a typo in my pseudocode, not a mistake in my actual code.

    Hmmmm everything looks right to me. You’ve tested to ensure the that has_filter() returns true? Unfortunately I’m not sure what else could be wrong without seeing more of the code.

    According to the WordPress codex for add_filter():

    The function returns true whether the attempted function hook fails or not. There is no test that the function exists nor whether the $function_to_add is even a string. It is up to you to take care and this is done for optimization purposes, so everything is as quick as possible.

    Is it add_filter() returning true? In your pseudocode there’s no check for the return value, which normally isn’t necessary.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘custom filter action not being called’ is closed to new replies.