0

I use this add_filters to append some links to each comment:

add_filter('comment_text', array($this, 'printModerateLinks'));

How do I pass the other attributes in this static method to my method "printModerateLinks"? I need the comments object in "printModerateLinks".

Thank you =)

0

1 Answer 1

1

First, consult the documentation or source code to see how many arguments are passed to the filter. We can see it has 3 in total, and the comments object is the second one, so you'll need to have at least two.

Next, you'll want to declare the number of arguments to pass to the function you're hooking on, which is the 4th parameter of add_action/add_filter

add_filter( 'comment_text', array( $this, 'printModerateLinks' ), 10, 3 );

Lastly, make sure you add the parameters to your method that's being hooked on.

public function printModerateLinks( $comment_text, $comment, $args ) {

Now you can access the comment object with the $comment variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.