WordPress.org

Ready to get started?Download WordPress

Forums

Several "add_filter" (2 posts)

  1. bloli
    Member
    Posted 5 years ago #

    This is probably a very simple question for those who know the answer.
    I've got problems with my plugin: It needs two filters - comment_text and get_comment_ID - but when I try it in this form

    function my_filter_function($comment_text, $get_comment_ID) {
    ...
    }
    add_filter('comment_text', 'my_filter_function');
    add_filter('get_comment_ID', 'my_filter_function');

    I get this message:
    "Warning: Missing argument 2 for my_filter_function() in /var/...path.../wp-content/plugins/my_plugin.php on line 20"

    "line 20" is "function my_filter_function($comment_text, $get_comment_ID) {"
    I guess, the second variable ("argument 2") isn't delivered.

    So: How can I use several filters for one function?

  2. ensarija
    Member
    Posted 5 years ago #

    maybe you should try sth. like this:

    ...
    add_filter('comment_text', 'my_filter_function',10,2);
    ...

    After defining filter and function, you should specify priority (by default 10, and number of accepted argument (by default 1).

    accepted_args is an optional integer argument defining how many arguments your function can accept (default 1), useful because some hooks can pass more than one argument to your function.

Topic Closed

This topic has been closed to new replies.

About this Topic