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
- Meaning of @classmethod and @staticmethod for beginner?
- What is the difference between object-oriented languages and non object-oriented languages?
- What is the syntax for accessing PHP object properties?
- Pass arguments to Constructor in VBA
- JavaScript pattern for multiple constructors
- When/why to make function private in class?
- jQuery creating objects [duplicate]
- Error: invalid use of member in static member function
- How to remove a filter that is an anonymous object?
- Should all plugins be encapsulated in a Class?
- Registering Class methods as hook callbacks
- Using classes instead of global functions in functions.php
- add_action in namespace not working
- Using Ajax with a Class file
- Namespaces in WordPress – How do I initiate the main class?
- How to include one class/instance without using global variables
- syntax for remove_filter in parent theme with class
- PHP5, Inheritance, Singleton – action & filter hook limitations
- Ajax Request not coming back to class
- How to do conditional publishing?
- Adding Meta Boxes while Registering a Post Type in a Class
- Current user in plugin returns NULL
- How to structure a plugin into multiple files using classes?
- Conditional tags inside a class
- How to avoid repeatedly use the new statement to instantiate a class? [closed]
- Creating a shortcode, but getting tied up with OOP and Classes?
- Trying to get property of non-object “ wordpress ”
- TInyMCE object Tag stripped
- Use Repository Pattern in WP theme
- Register jQuery – OOP WP
- How to Set Taxonomy Object Description?
- remove_action: how to access to a method in an child class?
- Need oop for wordpress theme? [duplicate]
- Cant register rest routs from class instance
- get_option / wp_localize_script Not Working in OOP Plug In
- Remove an action added within a class in a WordPress plugin
- PHP Helper Class to create shortcodes
- Class property seems to lose scope, attached to save_post action?
- wp_nav_menu inside an object — how do I deal with fallback_cb?
- Wp ajax not working from “current_screen” admin hook
- changes after I save a post
- OOP PHP class extends TwentyTwenty_Customize in Child Theme
- Call to “admin_notices” hook from a static method
- How to add typehints to function in functions.php when argument is an object?
- How to set a public variable in someone else’s plugin class
- Reorganization of namespaces
- AJAX save options inside class
- Meta Box not being added in plugin
- Why is this require statement not working?
- Best way to access variables in template markup
- Creating a register settings class that supports extended classes
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- OOP Plugin: Where should I place the action hooks in the class?
- How to remove a filter that is an object method?
- How can I modify or filter this variable in an existing class? (Mai Theme)