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.
Related Posts:
- What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__()
- What is Inversion of Control?
- What is an example of the Liskov Substitution Principle?
- What __init__ and self do in Python?
- When should you use a class vs a struct in C++?
- C++ error ‘Undefined reference to Class::Function()’ [duplicate]
- What’s the difference between a method and a function?
- How do I implement interfaces in python?
- What is polymorphism, what is it for, and how is it used?
- java – invalid method declaration; return type required [duplicate]
- java – invalid method declaration; return type required
- Is C++ an Object Oriented language?
- Difference between abstraction and encapsulation?
- What are metaclasses in Python?
- extends class and implements interface in java
- What is a “driver class”?
- What is difference between functional and imperative programming languages?
- How can I create a copy of an object in Python?
- What is polymorphism in Javascript?
- When should I be using classes in Python?
- How to create a subclass in C#?
- How would one write object-oriented code in C?
- How to get a JavaScript object’s class?
- Inheritance vs. Aggregation [closed]
- What is the difference between an Instance and an Object?
- What does ‘low in coupling and high in cohesion’ mean
- What is an example of the Single Responsibility Principle?
- Will WordPress become completely OOP?
- How to name files of namespaced classes?
- What is the best way to instantiate a class of a plugin in your WordPress theme?
- problem with implementing widget via the_content()
- Load classes using spl_autoload_register
- UML diagrams of WordPress
- Trying to get property of non-object
- Static vs Dynamic methods in WordPress
- Autoloader not finding classes from my plugin
- Integration tests test script enqueue/register fails
- Error of “Call a member function on non object” while var_dump get correct result
- How pass args to wp_list_comments callback?
- Does &$this is really disallowed to use anywhere?
- Don’t filters violate the a class’ local variables visibility rules?
- Admin submenu does not call function to load the page
- Using Geo Data Store Plugin Code
- How to wait for WordPress Core to load when writing OOP?
- OOP – from plugin add new object and call static method in another file
- What is the purpose of the word ‘self’?
- Understanding Python super() with __init__() methods [duplicate]
- Difference between Inheritance and Composition
- What is the difference between private and protected members of C++ classes?
- Reading from file in c++ ifstream
- Are static class variables possible in Python?
- Difference between virtual and abstract methods
- Separating class code into a header and cpp file
- What is a mixin, and why are they useful?
- Error at constructor : Expected an identifier?
- Prefer composition over inheritance?
- What is Serialization?
- Error “C++ requires a type specifier for all declarations whilst defining methods”
- C++ BlackJack Stuck trying to program Ace
- What are the differences between struct and class in C++?
- What is the meaning of single and double underscore before an object name?
- How to sort a list of objects based on an attribute of the objects?
- When should I use ‘self’ over ‘$this’?
- How to implement a binary search tree in Python?
- Already defined in .obj – no double inclusions
- Polymorphism vs Overriding vs Overloading
- fatal error LNK1169: one or more multiply defined symbols found in game programming
- How to call a parent class function from derived class function?
- Python function overloading
- Meaning of @classmethod and @staticmethod for beginner?
- Meaning of @classmethod and @staticmethod for beginner?
- What is the difference between object-oriented languages and non object-oriented languages?
- An object reference is required to access a non-static member
- When to use ‘raise NotImplementedError’?
- Why do some classes require main methods and others do not?
- What is the syntax for accessing PHP object properties?
- What is method hiding in Java? Even the JavaDoc explanation is confusing
- Can you pass-by-reference in R?
- Pass arguments to Constructor in VBA
- Why use getters and setters/accessors?
- JavaScript pattern for multiple constructors
- Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?
- How do you implement a class in C?
- What’s wrong with overridable method calls in constructors?
- Does ECMAScript 6 have a convention for abstract classes?
- Fields in interfaces
- When/why to make function private in class?
- jQuery creating objects [duplicate]
- Explaining Python’s ‘__enter__’ and ‘__exit__’
- What is a mixin, and why are they useful?
- “public” or “private” attribute in Python ? What is the best way?
- Error: invalid use of member in static member function
- What does the variable $this mean in PHP?
- How can I design a class named allergy?
- C++ equivalent of java’s instanceof
- How to remove a filter that is an anonymous object?
- Using OOP in themes
- Should all plugins be encapsulated in a Class?
- Plugin Form Submission Best Practice
- Registering Class methods as hook callbacks