oop – How to get parameters with add_filter with a static method?


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.

Marc 2 months 2022-09-24T07:31:22-05:00 0 Answers 0 views 0

Leave an answer